# Thread: Java Loops - accumulating totals

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:
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

//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

//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

//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

//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.

2. 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. Also, please remember that programming is an exercise in precision. The compiler will tolerate no spelling or capitalization errors (hint, hint).

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.security.AccessController.doPrivileged(Native Method)
Could not find the main class: burger. Program will exit.

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

5. Member
Join Date
Dec 2009
Posts
3
Rep Power
0
I use JGrasp to compile it.

Thanks

6. Member
Join Date
Sep 2009
Location
http://www.kouje.com
Posts
16
Rep Power
0
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.

#### Posting Permissions

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