Plz check.
import java.io.*; public class StudentGrades { String grade; double gradePoints; public void setGrade(String gradeS) { grade = gradeS; } public String getGrade() { return grade; } public void setGradePoints(double gradeP) { gradePoints = gradeP; } public double getGradePoints() { return gradePoints; } public static void main(String[]args)throws IOException { BufferedReader keyboard = new BufferedReader (new InputStreamReader(System.in)); int marks; StudentGrades sg = new StudentGrades(); System.out.println("Enter the marks"); marks = Integer.parseInt(keyboard.readLine()); if(marks>=80) { sg.setGrade("A+"); sg.setGradePoints(4.00); } else if(marks>=75 && marks<=79) { sg.setGrade("A"); sg.setGradePoints(3.70); } else if(marks>=70 && marks<=74) { sg.setGrade("A-"); sg.setGradePoints(3.30); } else if(marks>=65 && marks<=69) { sg.setGrade("B+"); sg.setGradePoints(3.00); } else if(marks>=64 && marks<=60) { sg.setGrade("B"); sg.setGradePoints(2.70); } else if(marks>=55&& marks<=59) { sg.setGrade("B-"); sg.setGradePoints(2.30); } else if(marks>=50 && marks<=54) { sg.setGrade("C+"); sg.setGradePoints(2.00); } else if(marks>=45 && marks<=49) { sg.setGrade("C"); sg.setGradePoints(1.70); } else if(marks>=40 && marks<=44) { sg.setGrade("C-"); sg.setGradePoints(1.50); } else if(marks>=35 && marks<=39) { sg.setGrade("D"); sg.setGradePoints(1.00); } else if(marks<=34) { sg.setGrade("F"); sg.setGradePoints(0.00); } System.out.println("Grade is "+sg.getGrade()); System.out.println("Grade Points is "+sg.getGradePoints()); } }
Is it producing the same null error?
No. It's producing the correct output. Bt wanna knw if I need to make any alterations.
I mean whether i need to make further modifications.
to make it more perfect
If it is doing what you want then I would say it's easier to not fix what isn't broken. :)
:)
If you know that the input is going to be an integer, and you are using the scanner class, you might look at using nextInt. There are quite a few of the input things you are doing that are easier with the scanner class, imho. http://docs.oracle.com/javase/6/docs/api/java/util/Scanner.html
If you are looking to streamline you might also consider your if/else conditions. You do not need to check the upper limit because it would not have reached that code if it did not fall in that range. For example, if your score was 68, all you would need to check is if it was greater than 70 (for A-) and 65 (for B+).
ya right.
Join our real-time social learning platform and learn together with your friends!