Results 1 to 7 of 7
Thread: Switch help please!!!!
- 11-23-2008, 02:57 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 39
- Rep Power
- 0
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;
}
}
- 11-23-2008, 03:04 PM #2
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 12
Whats the error output message? Also, use code tags please.
I die a little on the inside...
Every time I get shot.
- 11-23-2008, 03:12 PM #3
Member
- Join Date
- Oct 2008
- Posts
- 39
- Rep Power
- 0
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
Java Code:MOTORWAY, AROAD,BROAD,URBAN=UserInput.reaInt;
- 11-23-2008, 03:43 PM #5
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 12
If you want them to be all the same with
Java Code:MOTORWAY, AROAD,BROAD,URBAN=UserInput.reaInt;
Java Code:MOTORWAY = AROAD = BROAD = URBAN = UserInput.readInt;
I die a little on the inside...
Every time I get shot.
- 11-23-2008, 03:45 PM #6
Again ???
I have already told you once (in another posting) some of the things you need to change in your program. Based on that:
- You did not implement my suggestions:
http://www.java-forums.org/new-java/...my-switch.html - Opening a new thread/post about the same code hoping somebody will give you the answer isn't going to happen
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,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- You did not implement my suggestions:
- 11-23-2008, 08:25 PM #7
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 12
Similar Threads
-
[SOLVED] Should I use switch or if else
By hungdukie in forum New To JavaReplies: 14Last Post: 12-25-2011, 02:49 AM -
What is wrong with my switch??
By soc86 in forum New To JavaReplies: 3Last Post: 11-20-2008, 01:34 AM -
Help with switch color
By Daniel in forum AWT / SwingReplies: 2Last Post: 09-18-2008, 08:54 AM -
How to use Switch keyword
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 09:07 PM -
Switch Statement Help
By bluegreen7hi in forum New To JavaReplies: 6Last Post: 02-06-2008, 06:16 AM
Bookmarks