import type.lib.Student; import type.lib.ITstudent; import java.io.PrintStream; public class Grades { public static void main(String[] args) { PrintStream out = System.out; int seed = 0; if (args.length == 1) { seed = Integer.parseInt(args[0]); } Student.setSeed(seed); Student stu = Student.getRandom(); if (stu instanceof ITstudent) { out.println("Try a different seed"); return; } for (String course : stu) { String grade = stu.getCourseGrade(course); out.printf("course : CSE%s, grade : %s%n", course, grade); } double gpa = stu.getGpa(); out.println("GPA is " + gpa); final double MAX_GPA = 5.0; if (gpa >= MAX_GPA - 1) { out.println("GPA cannot be increased by 1"); } else { double currGpa = gpa; while (currGpa - gpa < 1) { // find the course with the lowest grade String minCourse = ""; String minGrade = "A"; for (String course : stu) { String grade = stu.getCourseGrade(course); if (grade.compareTo(minGrade) > 0) { minCourse = course; minGrade = grade; } } out.printf("Upgrading CSE%s from %s to A, ", minCourse, minGrade); // upgrade the mark of minCourse stu.setCourseGrade(minCourse, "A"); // compute new gpa currGpa = stu.getGpa(); out.println("GPA is " + currGpa); } } } }