-
Switch help please!!!!
I am having problem with my code, any advise?
public class Travel{
public static void main (String[]args){
int distance;
final int MOTORWAY=85;
final int AROAD=70;
final int BROAD=55;
final int URBAN=40;
int minutes;
int seconds;
int time;
System.out.println("Please enter the distance you will travel");
distance=UserInput.reaInt;
System.out.println("Please enter the distance you will travel");
MOTORWAY, AROAD,BROAD,URBAN=UserInput.reaInt;
switch(time){
case 'm':
case 'M':
time=distance/MOTORWAY;
System.out.println("To travel "+distance+" road type m takes "+time+" seconds");
System.out.println("To travel "+distance+" road m takes "+time+" hours "+minutes+" minutes "+seconds+" Seconds");
break;
case 'a':
case 'A':
time= distance/AROAD;
System.out.println("To travel "+distance+ "road type a takes "+time+" seconds");
System.out.println("To travel "+distance+" road a takes "+time+" hours "+minutes+" minutes "+seconds+" Seconds");
break;
case 'b':
case 'B':
time= distance/BROAD;
System.out.println("To travel "+distance+ "road type b takes "+time+" seconds");
System.out.println("To travel "+distance+" road b takes "+time+" hours "+minutes+" minutes "+seconds+" Seconds");
break;
case 'u':
case 'U': time= distance/URBAN;
System.out.println("To travel "+distance+ "road type u takes "+time+" seconds");
System.out.println("To travel "+distance+" road u takes "+time+" hours "+minutes+" minutes "+seconds+" Seconds");
break;
default: System.out.println("Invalid road type x");
System.exit(0);
}
seconds =time*3600;
seconds = seconds%60;
minutes =time-(int)time;
minutes=minutes*60;
}
}
-
Whats the error output message? Also, use code tags please.
-
System.out.println("Please enter the distance you will travel");
distance=UserInput.readInt;
can not resolve statment.
MOTORWAY, AROAD,BROAD,URBAN=UserInput.reaInt;
Not a statement,.
-
The compiler's not lying to you.
What is UserInput.readInt? It's not a method? Where do you get this UserInput class to begin with?
What are you trying to do with the improper statement below that, the
Code:
MOTORWAY, AROAD,BROAD,URBAN=UserInput.reaInt;
as this code makes no sense at all.
-
If you want them to be all the same with
Code:
MOTORWAY, AROAD,BROAD,URBAN=UserInput.reaInt;
you should use
Code:
MOTORWAY = AROAD = BROAD = URBAN = UserInput.readInt;
-
Again ???
I have already told you once (in another posting) some of the things you need to change in your program. Based on that:
From the code you're posting (again), it's apparent that you don't have absolutely no idea what you are doing. In many ways this code is worse than the first posting (like assigning values to variables AFTER trying to use the variables).
I would suggest buying a good Java book and at a minimum go through this:
The Java™ Tutorials
Since the principal subject you're worried about is switches, here's another link:
The switch Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)
Luck,
CJSL
-
soc86, really, did you even Google or think for yourself before posting this, after the last time? I find this really egocentric and selfish. You won't make much friends here by doing this. This time, actually read Chris's advice.