Problem analysis and algorithm design (i.e.: flowchart, algorithm)for this question.Write a Java program that prompt user to input a number of students in a class. Then, prompt user to input the students programming mark. Determine how many student get A+ and A for their grade and how many students get D and E based on the following table:
Marks Grades 85-100 A+ 80-84 A 75-79 B+ 70-74 B 65-69 B- 60-64 C+ 55-59 C 50-54 C- 45-49 D+ 40-44 D 0 E.
import java.util.Scanner; 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; int count2 = 0; int count3 = 0; int 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)); } }
Ads