Results 1 to 7 of 7
Thread: Java Loops - accumulating totals
- 12-15-2009, 03:56 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 3
- Rep Power
- 0
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.
I'm curious as to why my program won't compile.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 }
Any input/comments/suggestions would be much appreciated.
Thanks in advance! :)
-
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!
-
Also, please remember that programming is an exercise in precision. The compiler will tolerate no spelling or capitalization errors (hint, hint).
- 12-15-2009, 04:21 AM #4
Member
- Join Date
- Dec 2009
- Posts
- 3
- Rep Power
- 0
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.
-
You may have a classpath issue here. How are you compiling this code? Are you using a package here?
- 12-15-2009, 04:59 AM #6
Member
- Join Date
- Dec 2009
- Posts
- 3
- Rep Power
- 0
I use JGrasp to compile it.
I really appreciate your help
Thanks
- 12-15-2009, 05:39 AM #7
Member
- Join Date
- Sep 2009
- Location
- http://www.kouje.com
- Posts
- 16
- Rep Power
- 0
Similar Threads
-
when should we use loops
By shahemaan in forum New To JavaReplies: 1Last Post: 10-31-2009, 01:38 AM -
While Loops, need a bit of help.
By Keno777 in forum New To JavaReplies: 7Last Post: 10-30-2009, 08:24 PM -
[HELP]Java loops
By jude113 in forum JCreatorReplies: 0Last Post: 03-06-2009, 03:11 AM -
hey im new to java, and i need some help with "while loops"
By neilmx7 in forum New To JavaReplies: 16Last Post: 12-09-2008, 02:05 AM -
Help me: loops in java
By silvia in forum New To JavaReplies: 3Last Post: 07-19-2007, 06:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks