First I need to create 2 classes. The first will contain an ID number and an array of 5 course titles. I also have to create a get and a set method for populating the ID. I also must create a method to get a course. It does this by taking an integer and returning the course to that position (0 through 4). Then I must create a set method that sets the value of one of the courses by taking two arguements a name and an integer and returning the name to the position indicated by the integer.
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:
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:
Code:
// 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)
{
}
}
Code:
// 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***********
}
}
Code:
// 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);
}
}
}
Comment