Results 1 to 7 of 7
  1. #1
    iv3java is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Smile Java Loops - accumulating totals

    Hi guys, I new here.

    I just need a little bit of help. I'm just wondering if I'm in the right direction.
    I've written a code and it won't compile.

    Here's an overview of the problem:

    Write a program that calculates the cost of buying a burger from the CIS 103 Super Burger store. The menus has four choices to choose from:
    Menu Cost ($)
    Burger 2.15
    Combo 1 (Fries + Drink) 3.50
    Combo 2 ( Cheese + Fries + Drink) 4.85
    Combo 3 (Double Cheese Burger + Fries + Drink) 5.25

    The program presents a menu that allows the user to choose the desired burger combo. When the user selects an item, the program displays the cost. When the user selects option 5, the program displays the accumulated total cost.

    Sample output

    //this is the menu that is suppose to appear

    CIS 103 SUPER BURGER
    1. Burger
    2. Burger Combo1 (Fries + Drink)
    3. Burger Comb2 (Cheese + Fries + Drink)
    4. Burger Comb3 (Double cheese Burger + Fries + Drink)
    5. Done

    (The menu appears with showing "Please choose 1,2,3,4, or 5")
    //user chose 2

    You select combo1: $3.50

    CIS 103 SUPER BURGER
    1. Burger
    2. Burger Combo1 (Fries + Drink)
    3. Burger Comb2 (Cheese + Fries + Drink)
    4. Burger Comb3 (Double cheese Burger + Fries + Drink)
    5. Done

    (The menu appears with showing "Please choose 1,2,3,4, or 5")
    //user chose 4

    You select combo3: $5.25

    CIS 103 SUPER BURGER
    1. Burger
    2. Burger Combo1 (Fries + Drink)
    3. Burger Comb2 (Cheese + Fries + Drink)
    4. Burger Comb3 (Double cheese Burger + Fries + Drink)
    5. Done

    (The menu appears with showing "Please choose 1,2,3,4, or 5")
    //user chose 3

    You select combo2: $4.85

    CIS 103 SUPER BURGER
    1. Burger
    2. Burger Combo1 (Fries + Drink)
    3. Burger Comb2 (Cheese + Fries + Drink)
    4. Burger Comb3 (Double cheese Burger + Fries + Drink)
    5. Done

    (The menu appears with showing "Please choose 1,2,3,4, or 5")
    //user chose 5

    The total is $13.6

    -------------
    Here's part of what I have already written.

    Java Code:
    import javax.swing.*;
    public class burger
    {
    	public static void main(String args[])
    	{
    		int total = 0;
    		String s;
    		int choice;
    		double choice1 = 2.15;
    		double choice2 = 3.50;
    		double choice3 = 4.85;
    		double choice4 = 5.25;
    		
    		
    		s = JOptionPane.showInputDialog("CIS 103 Super Burger/n1. Burger/n2. Combo1 (Fries + Drink)/n3. Combo2 (Cheeseburger + Fries + Drink)/n4. Combo 3 (Doublecheeseburger + Fries + Drink)/n5. Done");
    		choice = Integer.parseint(s);
    		
    		while (choice<5)
    		{
    		s = JOptionPane.showInputDialog("CIS 103 Super Burger/n1. Burger/n2. Combo1 (Fries + Drink)/n3. Combo2 (Cheeseburger + Fries + Drink)/n4. Combo 3 (Doublecheeseburger + Fries + Drink)/n5. Done");
    		choice = Integer.parseint(s);
    		total++;
          }   
    			if (choice == 1)
    			{	
    				total += 2.15;
    				System.out.println("You've selected a Burger");
    				System.out.println("Your current total is: $" +total);
    			}
    			else if (choice == 2)
    			{			
    						total += 3.50;
    						System.out.prinln("You've selected Combo1");
    						System.out.println("Your current total is: $" +total);
    			}		
    					else if (choice == 3)
    			{					
    								total += 4.85;
    								System.out.println("You've selected Combo2");
    								System.out.println("Your current total is: $" +total);	
    			}				
    							else
    			{						
    									total += 5.25;
    									System.out.println("You've selected Combo3");
    									System.out.println("Your current total is: $" +total);
    			}						
    									total++;
    									
    		}	//endwhile								
    	}
    I'm curious as to why my program won't compile.
    Any input/comments/suggestions would be much appreciated.

    Thanks in advance! :)

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The compiler error will tell you 1) what the problem is or why it won't compile, and 2) the line that this problem occurs on. Learning to read this is a big part of learning to code Java.

    If you can't figure this out after reading this, then how about posting both the error message and indicate which line it's referring to.

    Much luck!

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Also, please remember that programming is an exercise in precision. The compiler will tolerate no spelling or capitalization errors (hint, hint).

  4. #4
    iv3java is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default

    Okay, I've fixed the spelling errors, but it still won't compile.

    Here's the error message.


    ----jGRASP exec: java burger
    Exception in thread "main" java.lang.NoClassDefFoundError: burger
    Caused by: java.lang.ClassNotFoundException: burger
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
    Could not find the main class: burger. Program will exit.

    ----jGRASP wedge: exit code for process is 1.
    ----jGRASP: operation complete.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  6. #6
    iv3java is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default

    I use JGrasp to compile it.

    I really appreciate your help

    Thanks

  7. #7
    syntrax is offline Member
    Join Date
    Sep 2009
    Location
    http://www.kouje.com
    Posts
    16
    Rep Power
    0

    Default

    what i can tell from your compile error, it seems that u have a lot of mispelling, i suggest u copy/paste the same variable.

Similar Threads

  1. when should we use loops
    By shahemaan in forum New To Java
    Replies: 1
    Last Post: 10-31-2009, 01:38 AM
  2. While Loops, need a bit of help.
    By Keno777 in forum New To Java
    Replies: 7
    Last Post: 10-30-2009, 08:24 PM
  3. [HELP]Java loops
    By jude113 in forum JCreator
    Replies: 0
    Last Post: 03-06-2009, 03:11 AM
  4. Replies: 16
    Last Post: 12-09-2008, 02:05 AM
  5. Help me: loops in java
    By silvia in forum New To Java
    Replies: 3
    Last Post: 07-19-2007, 06:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •