Check08C - out.println(DASH); double gpa = 0.0,...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import type.lib.Student; import java.io.PrintStream; import java.util.Scanner; i public class Check08C { public static void main(String[] args) { PrintStream out = System.out; out.print("Enter the year . .. "); int year = new Scanner(System.in).nextInt(); Student randomStudent = Student.getRandom(); final String DASH = "-----------------------", STUDENT = "Student ", GRADE = "FEDCBA", CONDITION = "[" + year + "][0-9]+"; out.printf("%sName: %s%n%sID: %s%n%sGPA: %1.1f%n", STUDENT, randomStudent.getName(), STUDENT, randomStudent.getID() , STUDENT, randomStudent.getGpa() );
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: out.println(DASH); double gpa = 0.0, subjectTotal = 0.0; for (String courseGrade : randomStudent) { if (courseGrade.matches(CONDITION)) { String studentGrade = randomStudent.getCourseGrade(courseGrade); out.println(courseGrade + "\t" + studentGrade); gpa += GRADE.indexOf(studentGrade); subjectTotal += 1; } } if (gpa > 0) { out.printf("GPA in year %d is: %1.1f%n", year, gpa / subjectTotal); } else { out.printf("No courses taken in year %d!%n", year); } out.println(DASH); } }...
View Full Document

Ask a homework question - tutors are online