calculate the grades for a student using if..else statements.
Expand Post »
hi everyone,
i am very new in java. can anyone help me to solve the following problem:
A school conducts a 100 mark exam for its student and grades them as follows:
Grade:
Grade A: Marks>75
Grade B: 75>Marks>60
Grade C: 60>Marks>50
Grade D: 50>Marks>40
Write ajava program to calculate the grades for a student, using if..else statement. use some given value to test the code.
Re: calculate the grades for a student using if..else statements.
I'm in a very giving mood today Usually I don't just give the answer to homework problems outright like I am now. I'd rather see some effort put in on your end. So consider yourself very lucky. The following is the pseudocode for the program. Think about what each line means, and then translate it into Java syntax line by line.
Re: calculate the grades for a student using if..else statements.
Hi shantuli,why not try this code as well.Have a lovely day.
Bobinson.
class Testy
{
byte score;
Testy()
{
score=78;
}
public static void main(String arg[])
{
Testy tst=new Testy();
tst.processGrades();
}
public void processGrades()
{
if
(score >=75)
{
System.out.println("Your grade is A");
}
else
if
((score >= 60)&&( score <75 ))
{
System.out.println("Your grade is B");
}
if
((score >=50 )&&(score<60))
{
System.out.println("Your grade is C");
}
else
if
((score >=40 )&&(score <50))
{
System.out.println(" Your grade is D");
}
else
if
(score <40 )
{
System.out.println(" Sorry you have no part here,FAILED");
}
Re: calculate the grades for a student using if..else statements.
Dude, 2 things.
1. Put your code into the [*code] and [/code] tags (remove the * though)
2. Don't just give him the answer to his homework, what good will that do him. You can help him and give him clues, but don't just do it for him. Also, your code seems overly complicated and there is no room for adjustment (i.e. the grade is always 78)
System.out.println(exellent +"\n"+ veryGgood +"\n"+ good +"\n"+ pass +"\n"+fail);
System.out.println("maximum = "+ max +"\t");
System.out.println("minimum = "+ min +"\t");
System.out.println("\tAverage = " +avg);
System.exit(0);
}
switch(grade/10)
{
case100:
case9 :
exellent += "\n"+ name + "\t" +grade+"\n";
break;
case8 :
veryGgood += "\n" + name + "\t" +grade +"\n";
break ;
case7 :
good += "\n" + name + "\t" +grade +"\n";
break;
case6:
case5:
pass += "\n" + name + "\t" +grade +"\n";
break;
default:
fail +="\n" + name + "\t" +grade +"\n";
break;
}
sum = sum + grade;
counter = counter + 1;
if(grade > max)
{
max = grade;
}
if(grade < min)
{
min = grade;
}
}
}
}
Last edited by peter_budo; Nov 12th, 2009 at 8:48 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.