Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
June 14th, 2003, 01:28 AM
 apw420
Registered User

Join Date: Jun 2003
Location: NYC
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
Rookie needs some help

Just starting out with Java. Working on an assignment and trying to create a menu. Hitting 1 will take you to 1 calculation, 2 another, and 3 exits you.

Unless you hit 3 to exit 1 and 2 should loop when the calculation is concluded.

I figure the option 1 and 2 calcs will be nested statements, so I'm trying to figure out how to put together the menu first and I hit a roadblock.

Any help is appreciated.
Here's what I have:

import java.io.*;
public class Earn {
public static void main (String [] args) throws IOException{
String input;

int hours;
int earnings=0;

do{

System.out.println("*******************************************************");
System.out.println("*******************************************************");
System.out.println("1) Calculate earnings at \$10 per hour");
System.out.println("2) Calculate earnings at \$0.10 doubled each hour");
System.out.println("3) Exit");
System.out.println("*******************************************************");

//option 1
System.out.println("How many hours?");
hours=Integer.parseInt(input);

earnings=(hours * 10);

System.out.println("You will earn \$" + earnings);
}

//option 2

System.out.println("How many hours?");
hours=Integer.parseInt(input);

}

//option 3

break;

}
}

Thanks for any input!

#2
June 14th, 2003, 03:16 PM
 Nemi
Clueless llama

Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353
Time spent in forums: 2 Days 12 h 39 m 5 sec
Reputation Power: 116
I'm sorry, I guess I don't understand what the problem is. Is this not working?

#3
June 16th, 2003, 05:15 PM
 apw420
Registered User

Join Date: Jun 2003
Location: NYC
Posts: 11
Time spent in forums: < 1 sec
Reputation Power: 0
Basically just trying to make a menu to start my program.
3 options, 3rd being exiting the program.
If 1 or 2 are selected, they'll perform a calculation -- then it will start over again at the Menu.

#4
June 17th, 2003, 01:53 PM
 nva
Junior Member

Join Date: Jun 2003
Location: Sweden
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
Just quickly scanning through your code I saw some errors:
-You have semicolons after the end-parenthesis in your if-statements, remove those.
-You are not calculating and printing the earnings in menu option 2. (Maybe you just forgot it?)
-Not really and error but you don't need to have an if-statement for option 3 since that is already checked in the while-statement.

 Viewing: Dev Shed Forums > Programming Languages > Java Help > Rookie needs some help