Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Need urgent help with Java Project

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need urgent help with Java Project

    ahmed.adan.mohaHello, I have a project due soon for creating a self checkout machine in Java. The user inputs numbers that are added to a grand total and then taxed. My problem is at the end, when the user decides they bought enough things, they type -1 then the program goes straight to the calculation and if they type 0, the previous price is erased. I have the bare code of just adding the prices together but don't know how to erase the last number and stop the program to start the grand total calculation.

    I'm supposed to use loops somewhere but only started learning about them. Any help would be appreciated. Thanks

    ---------------------(heres the barebones code but that shouldn't really matter, I just dont know what to type next)-----------------------
    import java.util.Scanner;
     
    public class aaa
    {
    public static void main(String[] args)
    {
     
    System.out.println("Big Box Depot Self-Serve Checkout");
    System.out.println("");
    System.out.println("Hi. Welcome to the checkout. What's your name? ");
    System.out.println("");
     
    Scanner input = new Scanner (System.in);
    String name = input.nextLine();
    System.out.println("");
    System.out.println("Okay, " + name + ", enter the price of each purchase in dollars and cents, and then push the ENTER key. For example, if item costs $5.99 enter 5.99");
    System.out.println("");
    System.out.println("If you make a mistake when you enter a price enter a zero for the next entry and the last price you entered will be subtracted from your running total.");
    System.out.println("");
    System.out.println("When you've entered all of your prices, enter -1 to indicate that you've finished your entries. I’ll then calculate what your total owing is.");
     
    System.out.println("");
    System.out.println("Enter a price for item #1: ");
    System.out.println("");
    Scanner input2 = new Scanner (System.in);
    Double price1 = input2.nextDouble();
    System.out.println("Enter a price for item #1: " + price1);
    System.out.println("");
    System.out.println("That was $" + price1 + ". Your total is $" + price1 + ".");
    System.out.println("");
     
    System.out.println("");
    System.out.println("Enter a price for item #2: ");
    System.out.println("");
    Scanner input3 = new Scanner (System.in);
    Double price2 = input3.nextDouble();
    System.out.println("Enter a price for item #2: " + price2);
    if (price2 = 0)
    System.out.println("");
    System.out.println("That was $" + price2 + ". Your total is $" + (price1 + price2) + ".");
    System.out.println("fin.");
     
    }
    }
    Last edited by helloworld922; November 26th, 2012 at 05:05 PM. Reason: please use [code] tags


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Need urgent help with Java Project

    This thread has been cross posted here:

    http://www.java-forums.org/new-java/65542-need-urgent-help-java-project.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


Similar Threads

  1. urgent inserting database in a java project
    By kavneetrekhi in forum JDBC & Databases
    Replies: 1
    Last Post: October 19th, 2012, 08:11 PM
  2. Need URGENT help for my project
    By life21in in forum Java Networking
    Replies: 1
    Last Post: July 30th, 2012, 08:15 AM
  3. Urgent Class Project Help !!!!!!!!!!!!!
    By thesoulpatchofBruce in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 10th, 2012, 05:14 AM
  4. Help please - urgent (Project due and not done) - Easy answer
    By Bagzli in forum Java Theory & Questions
    Replies: 1
    Last Post: March 2nd, 2011, 06:36 PM
  5. Need urgent help with my project..
    By secretsau in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 27th, 2010, 09:43 AM