|
-
February 28th, 2010, 08:56 PM
#1
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.
-
March 1st, 2010, 09:11 AM
#2
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.
-
March 1st, 2010, 05:30 PM
#3
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.
-
March 2nd, 2010, 01:27 AM
#4
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
-
March 2nd, 2010, 05:57 AM
#5
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
 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
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
March 2nd, 2010, 09:01 AM
#6
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
 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).
-
March 2nd, 2010, 09:22 AM
#7
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
 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). 
telephone!!!!!!!!
------
If you are satisfied with the responses, add to the user's rep!
-
March 2nd, 2010, 09:54 AM
#8
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
 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...
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 [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
March 2nd, 2010, 01:17 PM
#9
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
 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
-
March 2nd, 2010, 02:17 PM
#10
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
 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... 
Who dares to teach must never cease to learn...
J.C. Dana
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
March 2nd, 2010, 02:37 PM
#11
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
-
March 2nd, 2010, 02:46 PM
#12
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
-
March 2nd, 2010, 05:14 PM
#13
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
 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
-
March 2nd, 2010, 05:36 PM
#14
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
No, just lazy
-
March 2nd, 2010, 06:19 PM
#15
Re: Newbie Help with Study Guide Question---NOT HOMEWORK
 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 
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 [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|