Create a CollegeCourse class. The class contains fields for the course ID (for e
ID: 3932150 • Letter: C
Question
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 get 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 CollegeCourses; 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. Write an application that prompts a professor to enter grades for five different courses 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.javaExplanation / Answer
1)
CollegeCourse.java
public class CollegeCourse {
String courseID;
int creditHours;
char letterGrade;
public String getCourseID() {
return courseID;
}
public void setCourseID(String courseID) {
this.courseID = courseID;
}
public int getCreditHours() {
return creditHours;
}
public void setCreditHours(int creditHours) {
this.creditHours = creditHours;
}
public char getLetterGrade() {
return letterGrade;
}
public void setLetterGrade(char letterGrade) {
this.letterGrade = letterGrade;
}
}
Student.java
public class Student {
int studentID;
CollegeCourse[] course=new CollegeCourse[5];
public int getStudentID() {
return studentID;
}
public void setStudentID(int studentID) {
this.studentID = studentID;
}
public CollegeCourse getCourse(int courseNumber) {
return course[courseNumber];
}
public void setCourse(CollegeCourse[] course, int courseNumber) {
this.course[courseNumber] = course[courseNumber];
}
}
b)
InputGrades.java
import java.util.Scanner;
public class InputGrades {
public static void main(String args[])
{
Student[] student=new Student[10];
Scanner reader = new Scanner(System.in);
for(int s=1;s<=10;s++){
System.out.println("Enter details for student ID #"+s);
for(int n=1;n<=5;n++){
System.out.println("Enter grades for course ID #"+n);
char ch=reader.next().charAt(0);
if(ch=='A' || ch=='B' || ch=='C' || ch=='D' || ch=='F')
{
student[s].course[n].setLetterGrade(ch);
}
else
{
System.out.println("Wrong Grade entered. Please enter again");
continue;
}
}
}
}
}