Assigning Grades coderinme

Assigning Grades coderinme

The certain instructor assigns letter grade for his course based on the following table:
Score Grade
>= 90 A+
>= 85 A
>= 80 B+
>= 75 B
>= 65 C+
>= 60 C
>= 55 D+
>= 50 D
< 50 F
Write a class, Grader, which has: an instance variable, score, an appropriate constructor and appropriate methods
Now write a demo class to test the Grader class by reading a score from the user, using it to create a Grader object after validating that the value is not negative and is not greater then 100. Finally, call the letterGrade() method to get and print the grade. See figure (b) for sample run.
Program:

import java.io.*;
class Grader 
{
private int score;
public Grader(int s) 
{
score=s;
}
public String letterGrade() 
{
String grade;
if(score>=90)
grade="A+";
else if(score>=85)
grade="A";
else if(score>=80)
grade="B+";
else if(score>=75)
grade="B";
else if(score>=65)
grade="C+";
else if(score>=60)
grade="C";
else if(score>=55)
grade="D+";
else if(score>=50)
grade="D";
else
grade="F";
return grade;
}
}
public class Q22 
{
public static void main(String[] args) throws IOException 
{
System.out.println("please enter the marks of the student :");
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
int grad=Integer.parseInt(in.readLine());
Grader g1=new Grader(grad);
System.out.println("The grade of the student is :"+g1.letterGrade());
}
}

For more programs on Java, visit our Java Archives

Assigning Grades coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.