import java.util.*; public class StudentMarks{ double totalMarks; String grade; public void setTotalMarks(double totalMarks){ this.totalMarks=totalMarks; } public double getTotalMarks(){ return totalMarks; } public void setGrade(String grade){ this.grade=grade; } public String getGrade(){ return grade; } public static void main(String[]args){ Scanner input=new Scanner(System.in); System.out.print("Enter number of students: "); int num=input.nextInt(); StudentMarks data[]=new StudentMarks[num]; for (int i=0; i<data.length; i++) { System.out.println("Enter marks"); double marks=input.nextDouble(); data[i] = new StudentMarks(); data[i].setTotalMarks(marks); if(marks<40){ data[i].setGrade("E"); } if(marks>=40&&marks<=44){ data[i].setGrade("D"); } if(marks>=45&&marks<=49){ data[i].setGrade("D+"); } if(marks>=50&&marks<=54){ data[i].setGrade("C-"); } if(marks>=55&&marks<=59){ data[i].setGrade("C"); } if(marks>=60&&marks<=64){ data[i].setGrade("C+"); } if(marks>=65&&marks<=69){ data[i].setGrade("B-"); } if(marks>=70&&marks<=74){ data[i].setGrade("B"); } if(marks>=75&&marks<=79){ data[i].setGrade("B+"); } if(marks>=80&&marks<=84){ data[i].setGrade("A"); } if(marks>=85&&marks<=100) data[i].setGrade("A+"); } } int count1=0,count2=0,count3=0,count4=0; for(int i=0;i<num;i++){ StudentMarks show = data[i]; String g = show.getGrade(); if(g.equals("A+")){ count1++; } if(g.equals("A")){ count2++; } if(g.equals("D")){ count3++; } if(g.equals("E")){ count4++; } } System.out.println("Number of student getting A and A+ grade: "+(count1+count2)); System.out.println("Number of student getting D and E grade: "+(count3+count4)); } }
HTML
html content help to improve the coding
Thursday, 13 September 2012
Write a program to display grade message according to the marks
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment