Can someone please help me solve this problem. This is my first programming clas
ID: 674266 • Letter: C
Question
Can someone please help me solve this problem. This is my first programming class and I am having such a hard time trying to get this problem to work. Please and I will greatly appreciate the help! thank you!!
A. create a CollegeCourse class. the class contains fields for the course ID (for example "CIS 210"), credit hours (for example, 3), and the 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 CollegeCourse; 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 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
Explanation / Answer
Program:
//InputGrades.java
import java.util.Scanner;
public class InputGrades {
public static void main(String[] args) {
// to hold data of 10 students
Student student[]=new Student[10];
String c;//courseid
int hr;//hour
String g="";//grade
int f;//flag
int num;
Scanner scan=new Scanner(System.in);
//input student data
for(int i=0;i<10;i++)
{
student[i]=new Student();
System.out.println("Enter ID for Student#"+(i+1)+":");
student[i].setID(scan.next());// set ID
// reading course data
for(int j=0;i<5;i++)
{
System.out.println("Enter Course ID #"+(j+1)+":");
c=scan.next();
System.out.println("Enter Credit Hours:");
hr=scan.nextInt();
f=0;
//check for grade letter
while(f==0)
{
System.out.println("Enter letter grade:");
g=scan.next();
if(g.equals("A") ||g.equals("B")||g.equals("C")||g.equals("D")||g.equals("E")||g.equals("F"))
{
f=1;
}
else
System.out.println("Letter grade is not valid.");
}
//set the course data
student[i].course[j]=new CollegeCourse(c,hr,g);
}
// output student data
for(i=0;i<10;i++)
{
System.out.println("Student#"+(i+1)+" Details");
System.out.println("ID:"+student[i].getID());
System.out.println("CourseID CreditHours Grade");
for(int j=0;i<5;i++)
{
System.out.println(student[i].course[j].getID()+" "+student[i].course[j].getcreditHours()+" "+student[i].course[j].getGrade());
}
}
// updating a course data
System.out.println("Enter the student number"); // 0 to 10
num=scan.nextInt();
System.out.println("Enter the course number");// 0 to 4
int cnum=scan.nextInt();
System.out.println("Enter Course ID:");
c=scan.next();
System.out.println("Enter Credit Hours:");
hr=scan.nextInt();
f=0;
while(f==0)
{
System.out.println("Enter letter grade:");
g=scan.next();
if(g.equals("A") ||g.equals("B")||g.equals("C")||g.equals("D")||g.equals("E")||g.equals("F"))
{
f=1;
break;
}
else
System.out.println("Letter grade is not valid.");
}
student[num].setCourse(new CollegeCourse(c,hr,g), cnum);
// Read a course data
System.out.println("Enter the student number"); // 0 to 10
num=scan.nextInt();
System.out.println("Enter the course number to read data");// 0 to 4
cnum=scan.nextInt();
c=student[num].getCourse(cnum).getID();
hr=student[num].getCourse(cnum).getcreditHours();
g=student[num].getCourse(cnum).getGrade();
System.out.println("Course ID: "+c);
System.out.println("Credit Hours: "+hr);
System.out.println("Grade: "+g);
}
}
}
//============================================================
//Student.java
package InputGrades;
/*create a student class containing an ID number and an array of five CollegeCourse objects. */
public class Student {
String ID;
CollegeCourse course[];
public Student()
{
course=new CollegeCourse[5];
}
//create a get() and set() method for the student ID number.
public String getID()
{
return ID;
}
public void setID(String I)
{
ID=I;
}
/*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). */
public CollegeCourse getCourse(int i)
{
return course[i];
}
/*create a set() method that sets the value of one of the student's
CollegeCourse; the method takes two arguments - a CollegeCourse and an
integer representing the CollegeCourse's position (0 through 4).*/
public void setCourse(CollegeCourse cc,int i)
{
course[i]=cc;
}
}
//=================================================================
//CollegeCourse.java
package InputGrades;
public class CollegeCourse {
String courseID;
int creditHours;
String grade;
public CollegeCourse(String ID, int hr, String g)
{
courseID=ID;
creditHours=hr;
grade=g;
}
public void setID(String ID)
{
courseID=ID;
}
public void setcreditHours(int hr)
{
creditHours=hr;
}
public void setGrade(String g)
{
grade=g;
}
public String getID()
{
return courseID;
}
public int getcreditHours()
{
return creditHours;
}
public String getGrade()
{
return grade;
}
}