Results 1 to 7 of 7
  1. #1
    soc86 is offline Member
    Join Date
    Oct 2008
    Posts
    39
    Rep Power
    0

    Default 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;





    }
    }

  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Whats the error output message? Also, use code tags please.
    I die a little on the inside...
    Every time I get shot.

  3. #3
    soc86 is offline Member
    Join Date
    Oct 2008
    Posts
    39
    Rep Power
    0

    Default

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

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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;
    as this code makes no sense at all.

  5. #5
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    If you want them to be all the same with
    Java Code:
    MOTORWAY, AROAD,BROAD,URBAN=UserInput.reaInt;
    you should use
    Java Code:
    MOTORWAY = AROAD = BROAD = URBAN = UserInput.readInt;
    I die a little on the inside...
    Every time I get shot.

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default 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:
      What is wrong with my switch??
    • 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,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    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.
    I die a little on the inside...
    Every time I get shot.

Similar Threads

  1. [SOLVED] Should I use switch or if else
    By hungdukie in forum New To Java
    Replies: 14
    Last Post: 12-25-2011, 01:49 AM
  2. What is wrong with my switch??
    By soc86 in forum New To Java
    Replies: 3
    Last Post: 11-20-2008, 12:34 AM
  3. Help with switch color
    By Daniel in forum AWT / Swing
    Replies: 2
    Last Post: 09-18-2008, 07:54 AM
  4. How to use Switch keyword
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-23-2008, 08:07 PM
  5. Switch Statement Help
    By bluegreen7hi in forum New To Java
    Replies: 6
    Last Post: 02-06-2008, 05:16 AM

Posting Permissions

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