12,451,455 members (49,711 online)
Rate this:
See more:
my Assignment:
Write a program that will do the following tasks. Declare and initialize two variables that represent a student's scores on two tests. The grade average should be computed by summing the test scores and dividing by 2. Then, a letter grade should be determined based on the average grade. The following scoring shall be used: A = 90-100, B = 80-89, C = 70-79, D = 65-69, F = 64 or less. The program should display the average test score and the student's letter grade.

My answer (can you check and fix):
```public class TestGrades
{
public static void main (String [] args)
{

System.out.println("\n" + "your test score is" + testscore);

if(testscore >= 90 )

elseif(testscore >= 80 );

elseif(testscore >= 70 );

elseif(testscore >= 65 );

else
}
}```
Posted 31-Aug-12 4:11am
Updated 31-Aug-12 7:04am
v5

And no it's not right. You are not displaying the grade anywhere. But if you ran it, you would already know that.

Rate this:

## Solution 1

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
lewax00 31-Aug-12 11:51am

I think this is a fair question, he's made an attempt and wants it verified by people with experience, he's not asking us to write it for him.
Rate this:

## Solution 2

You have a couple problems, but if you try to run it these should be pointed out by the compiler.

But, here's a quick rundown of the problems I see:
- `else if` should be two words, you have no space between them
- There should not be a semicolon at the end of your `else if` lines
- As mentioned by Wes, you forgot to display the grade

And some tips:
- You shouldn't need to concatenate string literals, you can change `"\n" + "your test score is"` to just `"\nyour test score is"`
- You probably want to add a space to the end of that string as well, or you'll get output like "your test score is76" instead of "your test score is 76"
- Even though { and } aren't required for `if` statements with only one line in the body, use them anyways. If you ever want to add another line later it's a pain to add them then, and most Java IDEs will add the closing brace when you type the opening one.
Rate this:

## Solution 3

I see there are some conditional errors(consider a case,if your testscore is 95 then what will be the grade?because all conditions true for it) in your if else conditions..it will work better just like as it..
```    if(testscore >= 90 )

else if((testscore >= 80 ) && (testscore < 90))

else if((testscore >= 70 ) && (testscore < 80))

else if((testscore >= 65 ) && (testscore < 70))

else
```
there are also some syntax errors which is informed you earlier by lewax00..
v2
lewax00 31-Aug-12 13:17pm

That's not necessary, if the grade is 85 it would fails the first condition (>= 90), then the second condition will be checked (>= 80), then it will assign the grade and exit the if-block. Nothing else will be evaluated. Those less than statements are already handled implicitly (e.g. a grade cannot make it to the check for B unless it is less than 90, so that will always evaluate to true in any case the evaluation occurs, because in any case where it is false the evaluation is never made).

Top Experts
Last 24hrsThis month
 ppolymorphe 189 OriginalGriff 115 Afzaal Ahmad Zeeshan 60 Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ) 50 Karthik Bangalore 45
 OriginalGriff 6,103 ppolymorphe 3,600 Karthik Bangalore 3,530 Maciej Los 3,005 Richard Deeming 2,830