Click to See Complete Forum and Search --> : Newbie Help with Study Guide Question---NOT HOMEWORK
TKulak
February 28th, 2010, 07:56 PM
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.
ProgramThis
March 1st, 2010, 08:11 AM
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.
TKulak
March 1st, 2010, 04:30 PM
Yes, a switch is what I am trying to use. I just wasn't sure how to figure in the scores.
DavidFongs
March 2nd, 2010, 12:27 AM
If you must use a switch: You should switch on the score, and once you determine the appropriate case, assign the letter grade
dlorde
March 2nd, 2010, 04:57 AM
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
ProgramThis
March 2nd, 2010, 08:01 AM
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
Deliverance
March 2nd, 2010, 08:22 AM
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!!!!!!!!
dlorde
March 2nd, 2010, 08:54 AM
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). :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.
DavidFongs
March 2nd, 2010, 12:17 PM
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
dlorde
March 2nd, 2010, 01:17 PM
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
keang
March 2nd, 2010, 01:37 PM
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 ;)
ProgramThis
March 2nd, 2010, 01:46 PM
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:
DavidFongs
March 2nd, 2010, 04:14 PM
If score is an int and you divide it by 10 you can solve this in 6 cases ;)
you are smart
keang
March 2nd, 2010, 04:36 PM
you are smartNo, just lazy :)
dlorde
March 2nd, 2010, 05:19 PM
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
keang
March 2nd, 2010, 05:46 PM
so is it too clever to be the expected answer?It may be clever but, no doubt like yourself, unless it was an absolute requirement of the homework I still wouldn't do it with a switch statement. It's more work than using if-else statements and it doesn't read as well.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.