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 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 objects; the method takes two arguments—a CollegeCourse and an integer representing the CollegeCourse’s position (0 through 4).
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 #1, and Enter course ID #5. Verify that the professor enters only A, B, C, D, or F for the grade value for each course. After all the data has been entered, display all the information in order by student then course as shown:
Student #1 ID #101 CS1 1 -- credits. Grade is A CS2 2 -- credits. Grade is B CS3 3 -- credits. Grade is C CS4 4 -- credits. Grade is D CS5 5 -- credits. Grade is F
CollegeCourse.java
public class CollegeCourse {
private String courseID;
private int credits;
private char grade;
public String getID() {
}
public int getCredits() {
}
public char getGrade() {
}
public void setID(String idNum) {
}
public void setCredits(int cr) {
}
public void setGrade(char gr) {
}
}
InputGrades.java
import java.util.*;
public class InputGrades {
public static void main(String[] args) {
// Write your code here
}
}
Student.java
public class Student {
private int stuID;
private CollegeCourse[] course = new CollegeCourse[5];
public int getID() {
}
public CollegeCourse getCourse(int x) {
}
public void setID(int idNum) {
}
public void setCourse(CollegeCourse c, int x) {
}
}
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
// InputGrades.java
import java.util.*;
public class InputGrades {
public static void main(String[] args) {
// scanner for input
Scanner scanner = new Scanner(System.in);
// number of courses and students
int courseCount = 5, studentsCount = 10;
// creating an array of Student objects
Student students[] = new Student[studentsCount];
// looping for studentCount times
for (int i = 0; i < studentsCount; i++) {
// creating a student
Student s = new Student();
// asking for student id, reading and updating in s
System.out.print("Enter student id: ");
int studentId = scanner.nextInt();
s.setID(studentId);
int index = 0;
// looping until all course data is entered for current student
while (index < courseCount) {
// asking for course data. to make things simple and easy to
// input, we are reading course id, credits and grade together
// (in one line), or it will be difficult to enter 3*5*10 inputs
// separately
System.out.print("Enter id, credits and grade for course#"
+ (index + 1) + ": ");
// the input must be in the format <courseId> <credits> <grade>
String courseId = scanner.next();
int credits = scanner.nextInt();
char grade = scanner.next().toUpperCase().charAt(0);
// validating the grade
if (grade == 'A' || grade == 'B' || grade == 'C'
|| grade == 'D' || grade == 'F') {
// valid, creating a Course and setting attributes
CollegeCourse course = new CollegeCourse();
course.setCredits(credits);
course.setGrade(grade);
course.setID(courseId);
// setting course at index position in Student s
s.setCourse(course, index);
// updating index
index++;
} else {
// invalid grade
System.out.println("Invalid grade!");
}
}
// adding s to array at index i
students[i] = s;
}
// looping and displaying details of all students
for (int i = 0; i < studentsCount; i++) {
System.out.println("\nStudent #" + (i + 1) + " ID #"
+ students[i].getID());
for (int j = 0; j < courseCount; j++) {
// since we implemented toString method in CollegeCourse class,
// we can simply print it
System.out.println(students[i].getCourse(j));
}
}
}
}
// Student.java
public class Student {
private int stuID;
private CollegeCourse[] course = new CollegeCourse[5];
public int getID() {
return stuID;
}
public CollegeCourse getCourse(int x) {
return course[x];
}
public void setID(int idNum) {
stuID = idNum;
}
public void setCourse(CollegeCourse c, int x) {
course[x] = c;
}
}
// CollegeCourse.java
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) {
courseID = idNum;
}
public void setCredits(int cr) {
credits = cr;
}
public void setGrade(char gr) {
grade = gr;
}
// returns a String containing course id, credits and grade
public String toString() {
return courseID + " " + credits + " -- credits. Grade is " + grade;
}
}
/*sample OUTPUT for 2 courses & 3 students*/
Enter student id: 101
Enter id, credits and grade for course#1: CS1 1 A
Enter id, credits and grade for course#2: CS2 2 X
Invalid grade!
Enter id, credits and grade for course#2: CS2 2 B
Enter student id: 103
Enter id, credits and grade for course#1: CS1 1 C
Enter id, credits and grade for course#2: ENG 2 D
Enter student id: 107
Enter id, credits and grade for course#1: CS2 1 B
Enter id, credits and grade for course#2: CS2 2 C
Student #1 ID #101
CS1 1 -- credits. Grade is A
CS2 2 -- credits. Grade is B
Student #2 ID #103
CS1 1 -- credits. Grade is C
ENG 2 -- credits. Grade is D
Student #3 ID #107
CS2 1 -- credits. Grade is B
CS2 2 -- credits. Grade is C
A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...
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 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...
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 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...
Create an abstract Student class for Parker University. The
class contains fields for student ID number, last name, and annual
tuition. Include a constructor that requires parameters for the ID
number and name. Include get and set methods for each field; the
setTuition() method is abstract.
Create three Student subclasses named UndergraduateStudent,
GraduateStudent, and StudentAtLarge, each with a unique
setTuition() method. Tuition for an UndergraduateStudent is
$4,000 per semester, tuition for a GraduateStudent
is $6,000 per semester, and tuition for...
In this exercise, we will be refactoring a working program. Code refactoring is a process to improve an existing code in term of its internal structure without changing its external behavior. In this particular example, we have three classes Course, Student, Instructor in addition to Main. All classes are well documented. Read through them to understand their structure. In brief, Course models a course that has a title, max capacity an instructor and students. Instructor models a course instructor who...
Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...
Java
Do 72a, 72b, 72c, 72d. Code & output required.
public class Employee { private int id; private String name; private int sal; public Employee(int id, String name, int sal) { super(); this.id = id; this.name = name; this.sal = sal; } public int getid) { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; public void setName(String name) { this.name = name; } public int get Sall) { return sal;...
(To be written in Java code) Create a class named CollegeCourse that includes the following data fields: dept (String) - holds the department (for example, ENG) id (int) - the course number (for example, 101) credits (double) - the credits (for example, 3) price (double) - the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display()...
Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course { /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...
FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...
Create a DataEntryException class whose getMessage() method returns information about invalid integer data. Write a program named GetIDAndAge that continually prompts the user for an ID number and an age until a terminal 0 is entered for both. If the ID and age are both valid, display the message ID and Age OK. Throw a DataEntryException if the ID is not in the range of valid ID numbers (0 through 999), or if the age is not in the range...