After that I must write an application that prompts the user for grades for 5 different courses: it will prompt for the the id number, then course data for each of 5 courses for that ID number. The user will enter the ID number of the student, then when prompted a number from 1 to 5 indicating which course, and a letter grade for the course.
So far this is what I have:
Expand|Select|Wrap|Line Numbers
- // CollegeCourse.java
- // Chapter 8, Exercise 5a
- // A CollegeCourse has an ID, credits, and a letter grade
- public class CollegeCourse
- {
- private String courseID;
- private int credits;
- private char grade;
- public String getID()
- {
- return courseID;
- }
- public int getCredits()
- {
- return credits;
- }
- public char getGrade()
- {
- return grade;
- }
- public void setID(String idNum)
- {
- }
- }
Expand|Select|Wrap|Line Numbers
- // Student.java
- // Chapter 8, Exercise 5c
- // A Student has an ID, and five CoollegeCourses,
- public class Student
- {
- private int stuID;
- private CollegeCourse[] course = new CollegeCourse[5];
- public int getID()
- {
- return stuID;
- }
- *******stuck here***********
- }
- }
Expand|Select|Wrap|Line Numbers
- // InputGrades.java
- // Chapter 8, Exercise 5b
- // Allows input of 5 grades each for 10 students
- import javax.swing.*;
- public class InputGrades
- {
- public static void main(String[] args)
- {
- // http://www.brpreiss.com/books/opus5/html/page89.html
- Student[] students = new Student[10];
- int x, y, z;
- String courseEntry, entry = "", message;
- int idEntry, credits;
- char gradeEntry = ' ';
- boolean isGoodGrade = false;
- char[] grades = {'A', 'B', 'C', 'D', 'F'};
- for(x = 0; x < students.length; ++x)
- {
- Student stu = new Student();
- entry = JOptionPane.showInputDialog(null, "For student #" + (x + 1) + ", enter the student ID");
- idEntry = Integer.parseInt(entry);
- stu.setID(idEntry);
- *********stuck here****************
- CollegeCourse temp = new CollegeCourse();
- temp.setID(courseEntry);
- temp.setCredits(credits);
- temp.setGrade(gradeEntry);
- stu.setCourse(temp, y);
- }
- students[x] = stu;
- }
- for(x = 0; x < students.length; ++x)
- {
- message = "Student #" + (x + 1) + " ID #" + students[x].getID();
- for(y = 0; y < 5; ++y)
- {
- CollegeCourse temp = new CollegeCourse();
- temp = students[x].getCourse(y);
- message = message + "\n" + temp.getID() + " " + temp.getCredits() + " credits. Grade is " + temp.getGrade();
- JOptionPane.showMessageDialog(null,message);
- }
- System.exit(0);
- }
- }
- }