Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Switch Statments

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Switch Statments

    Total Score Recommendation Points Earned
    >500 Excellent 4
    350 – 499 Very Good 3
    200 – 249 Good 2
    <249 Not good enough 1

    I need to write a java code and compile it using Switch statements? Anyone can help thanks


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Switch Statments

    Do you have any specific questions about your assignment?
    Please post your code and any questions about problems you are having.

    What have you tried? - Matt Gemmell


    switch statements aren't much good for ranges of data.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Switch Statments

    /*Question :
    * Complete the requirement of the program to determine the meaning
    * and population using Switch Statment.
    * Note this time I am looking for the appropriate exception handling with a
    * correct loop to continue until user ask to exit the program.
    */
    package midterm;
    import java.util.Scanner;
    public class Midterm {
    public static void main(String[] args) {
    Scanner input = new Scanner (System.in);

    String recommendation;
    String pointsEarned;

    System.out.println("Enter your score now!");
    int score = input.nextInt();

    switch (score ){
    case 1:
    if (score >=500){
    recommendation = "Excellent";
    pointsEarned = "43%";
    }
    break;
    case 2:
    if (score>=350 && score<=499){
    recommendation = "Excellent";
    pointsEarned = "43%";
    }
    break;
    case 3:
    if (score>=249 && score<=200){
    recommendation = "Excellent";
    pointsEarned = "43%";
    }
    break;
    case 4:
    if (score < 200){
    recommendation = "Excellent";
    pointsEarned = "43%";
    }
    break;
    }
    }
    }

    --- Update ---

    it does not complie and i still need to use try and catch

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Switch Statments

    it does not complie
    Please copy the full text of the error messages and post it here.

    What values can the user enter? What will the switch statement do with those values?

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.


    Check your clipboard. The copy and paste feature on your PC is not working correctly.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Switch Statments

    Hello all,
    the whole community of java can't compile a switch statement, really? need help guys..

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Switch Statments

    Please copy the full text of the error messages you are getting and post it here.

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Switch
    By KillerToFu in forum What's Wrong With My Code?
    Replies: 8
    Last Post: March 21st, 2013, 05:53 PM
  2. what switch?
    By kingzeze in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 26th, 2013, 11:09 AM
  3. Switch
    By hiepa in forum What's Wrong With My Code?
    Replies: 10
    Last Post: November 19th, 2012, 06:21 PM
  4. Why does java not honor my if/else statments
    By mflb94 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: September 11th, 2012, 10:41 PM
  5. using if/else statments
    By new2java in forum Loops & Control Statements
    Replies: 1
    Last Post: September 25th, 2009, 12:21 AM