I am currently working on a project for a beginners java class. Below is an except of the question:
a)Create a CollegeCourse class. The class contains fields for the course ID ( for example, "CIS 210"),credit hours (for example, 3) and a letter grade (for example, 'A'). Include ge() and set() methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get () and set() method for the Student ID number. Also create a get () method that returns one of the Student's CollegeCourses; the method takes an integer argument and returns the CollegeCourse in that position(0 through 4). Next, create a set() method that sets the value of one of the Student's CollegeCoursesl the method takes two arguments - a CollegeCourse and an integer representing the CollegeCourse's position (0 through 4). Save the files as CollegeCourse.java and Student.java
b)Write an application that prompts a professor to enter grades for five different courses each for 10 students. Prompt the professor to enter grades for five different couses each for 10 students. Prompt the professor to enter data for one student at a time, including student ID and course data for five courses. Use prompts containing the number of the student whose data is being entered and the course number - for example, "Enter ID for student #s", where s is an integer from 1 through 10, indicating the student, and "Enter course ID #n", where n is an integer from 1 through 5, indicating the course number. Verify that the professor enters only A, B, C, D, or F for the grade value for each course. Save the file as InputGrades.java.
I have successfully completed the (a) part but i am stuck on part (b). Below is the code I have so far:
public class CollegeCourse
{
String courseID;
int creditHours;
char grade;
public void setCourseId(String id) {
this.courseID = id;
}
public String getCourse() {
return courseID;
}
public void setHours(int hours) {
this.creditHours = hours;
}
public int getHours() {
return creditHours;
}
public void setGrade(char grade) {
this.grade = grade;
}
}
public class Student
{
int id;
CollegeCourse[] cc = new CollegeCourse[5];
public void setId(int id)
{
this.id = id;
}
public int getId()
{
return id;
}
CollegeCourse[] courses;
public CollegeCourse getCourse(int index) {
return courses[index];
}
public void setCourse(int index, CollegeCourse course) {
courses[index] = course;
}
}
public class InputGrades
{
public static void main(String[] args)
{
Student[] students = new Student[10];
char[] grades = {'A', 'B', 'C', 'D', 'F'};
for(int x = 0; x < students.length; ++x)
{
System.out.println("Enter student Id: ");
Student stu = new Student();
stu.setId(Id);
}
}
}