import java.util.*; import java.text.*; import javax.swing.*; public class Assignment2 { //Create and display complete student information for each student // whose name in given in a list of student's names public static void main(String[] args) { String[] STUDENT_NAMES = {"Jack Felldown", "Jill Tumbling", "Simple Simon", "Missey Muffet", "Georgie Porgy", "Bobby Shafto"}; for (String name : STUDENT_NAMES) { //Create a new CollegeStudent with the current name CollegeStudent student = null; //****(1) //Compose and display the CollegeStudent's transcript JOptionPane.showMessageDialog(null, transcript(student) ); } } //Compose a transcript for a given CollegeStudent // @param student: the student whose transcript is to be composed private static String transcript(CollegeStudent student) { //For each of the available courses for (CollegeCourse course : CollegeCourse.values() ) if ((new Random()).nextBoolean()) //Randomly decide if to select { //Assign a randomly chosen letter grade LetterGrade grade = randomGrade(); //Update student with selected course and letter grade //student.update(course, grade); //****(2) } return student + "\n" + "GPA: " + (new DecimalFormat("0.00")).format( gpa( student ) ); } //Calculate a CollegeStudent's Grade Point Average (GPA) // @parameter janeDoe: the CollegeStudent whose GPA is to be calculated private static double gpa(CollegeStudent student) { int credits = 0; //total earned credits for the given student //****(3) int points = 0; //total grade points for the given student //****(4) return ( credits == 0 ? 0.0 : (double)points / credits ); } //Randomly select a LetterGrade private static final String DISTRIBUTION = "011122222222333333444"; private static LetterGrade randomGrade() { int index = (new Random()).nextInt(DISTRIBUTION.length()); index = Integer.parseInt(DISTRIBUTION.substring(index, index+1)); return LetterGrade.values()[index]; } }