CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Feb 2010
    Posts
    2

    Newbie Help with Study Guide Question---NOT HOMEWORK

    Hello,

    The questions says a professor determines his grades based on the following table.

    score
    90-100

    80-89

    70-79

    60-69

    <60

    grade
    A

    B

    C

    D

    F

    Assign the appropriate value to the variable grade(character) based on the variable score(integer). Use the switch structure.

    We were told you are not supposed to use relational operators in JAVA in a switch (char or int).

    My thoughts would have been

    {
    case 1: Grade = "A";
    break;
    case 2: Grade = "B";
    break;
    case 3: Grade = "C";
    break;
    case 4: Grade = "D";
    break;
    default:
    Grade = "F";
    }

    I just don't know how to work in the grade scale. Any help appreciated. I am unsure if I posted this correctly.

  2. #2
    Join Date
    Feb 2008
    Posts
    966

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    First off I think we need to clarify things:

    We were told you are not supposed to use relational operators in JAVA in a switch (char or int).
    So can you use a switch statement or not? I ask because it looks like you are trying to use one.

  3. #3
    Join Date
    Feb 2010
    Posts
    2

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    Yes, a switch is what I am trying to use. I just wasn't sure how to figure in the scores.

  4. #4
    Join Date
    Nov 2009
    Posts
    17

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    If you must use a switch: You should switch on the score, and once you determine the appropriate case, assign the letter grade

  5. #5
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    Quote Originally Posted by DavidFongs View Post
    If you must use a switch: You should switch on the score, and once you determine the appropriate case, assign the letter grade
    How would you do that without using relational operators in the switch (unless you had a switch with 100 cases, which doesn't sound reasonable) ?

    Maybe the professor wants relational operators used on the score before the switch, to initialise the variable used in the switch...

    Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable techniques to solve it...
    A. Aho and J. Ullman
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  6. #6
    Join Date
    Feb 2008
    Posts
    966

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    Quote Originally Posted by dlorde View Post
    Maybe the professor wants relational operators used on the score before the switch, to initialise the variable used in the switch...
    Which would be about the most useless, redundant thing we've seen this week. Maybe it would help if we could see the entire question. I have a feeling something is being lost in between (kind of like that game you play in 1st grade, where the teacher tells one kid a secret, and he/she passes it along, and when it gets to the end it's not the same message).

  7. #7
    Join Date
    Apr 2007
    Posts
    425

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    Quote Originally Posted by programthis View Post
    which would be about the most useless, redundant thing we've seen this week. Maybe it would help if we could see the entire question. I have a feeling something is being lost in between (kind of like that game you play in 1st grade, where the teacher tells one kid a secret, and he/she passes it along, and when it gets to the end it's not the same message).
    telephone!!!!!!!!
    ------
    If you are satisfied with the responses, add to the user's rep!

  8. #8
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    Quote Originally Posted by ProgramThis View Post
    Which would be about the most useless, redundant thing we've seen this week.
    That's what I thought, but the alternative seemed even worse...

    Maybe it would help if we could see the entire question. I have a feeling something is being lost in between (kind of like that game you play in 1st grade, where the teacher tells one kid a secret, and he/she passes it along, and when it gets to the end it's not the same message).
    We used to call it 'Chinese Whispers', but that may not be PC these days.

    It is easier to measure something than to understand what you have measured...
    Anon.
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  9. #9
    Join Date
    Nov 2009
    Posts
    17

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    Quote Originally Posted by dlorde View Post
    How would you do that without using relational operators in the switch (unless you had a switch with 100 cases, which doesn't sound reasonable) ?

    Maybe the professor wants relational operators used on the score before the switch, to initialise the variable used in the switch...

    Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable techniques to solve it...
    A. Aho and J. Ullman
    It would need 41 cases.... which is why I said "if you must"

    Seems a lot easier to just use a few if/else if statements

  10. #10
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    Quote Originally Posted by DavidFongs View Post
    It would need 41 cases.... which is why I said "if you must"

    Seems a lot easier to just use a few if/else if statements
    Yes, my mistake - you're right, 41 cases would do it - but I can't believe that's what was intended...

    Who dares to teach must never cease to learn...
    J.C. Dana
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  11. #11
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    Yes, my mistake - you're right, 41 cases would do it - but I can't believe that's what was intended...
    If score is an int and you divide it by 10 you can solve this in 6 cases
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  12. #12
    Join Date
    Feb 2008
    Posts
    966

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    Quote Originally Posted by keang View Post
    If score is an int and you divide it by 10 you can solve this in 6 cases
    Math FTW! Good thinking.

    I knew there was a reason they were teaching me all that math in school.

  13. #13
    Join Date
    Nov 2009
    Posts
    17

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    Quote Originally Posted by keang View Post
    If score is an int and you divide it by 10 you can solve this in 6 cases
    you are smart

  14. #14
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    you are smart
    No, just lazy
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  15. #15
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Newbie Help with Study Guide Question---NOT HOMEWORK

    Quote Originally Posted by keang View Post
    If score is an int and you divide it by 10 you can solve this in 6 cases
    That's cheating

    An excellent solution - wish I'd thought of it. Although it needs a good understanding of integer math in practice, so is it too clever to be the expected answer?

    To arrive at the simple is difficult...
    R. Elisha
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured