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.
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
First off I think we need to clarify things:
Quote:
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.
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.
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
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
Quote:
Originally Posted by
DavidFongs
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
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
Quote:
Originally Posted by
dlorde
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). :D
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
Quote:
Originally Posted by
programthis
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). :d
telephone!!!!!!!!
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
Quote:
Originally Posted by
ProgramThis
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...
Quote:
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). :D
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.
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
Quote:
Originally Posted by
dlorde
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
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
Quote:
Originally Posted by
DavidFongs
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... :eek:
Who dares to teach must never cease to learn...
J.C. Dana
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
Quote:
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 ;)
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
Quote:
Originally Posted by
keang
If score is an int and you divide it by 10 you can solve this in 6 cases ;)
Math FTW! :D Good thinking.
I knew there was a reason they were teaching me all that math in school. :blush:
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
Quote:
Originally Posted by
keang
If score is an int and you divide it by 10 you can solve this in 6 cases ;)
you are smart
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
Quote:
Originally Posted by
keang
If score is an int and you divide it by 10 you can solve this in 6 cases ;)
That's cheating :thumb:
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