Question
Answered step-by-step
MinisterWillpowerLion30
To better prepare yourself for the quiz, use the below questions to…

To better prepare yourself for the quiz, use the below questions to study, modify, compile and run code. Be sure to look closely at the comments. Compile and execute the code and post the output you get to the discussion board. Keep all answers as short as possible and right to the point.
 

Teacher.java

public class Teacher { // This is a class named Teacher

private String firstName; // This is an instance variable of type String
private String lastName; // This is an instance variable of type String

public Teacher(String firstName, String lastName) { // This is the constructor, it has 2 parameters
this.firstName = firstName; // assign instance variables from local variables
this.lastName = lastName; // assign instance variables from local variables
}

// a method to get the first name of this object
public String getFirstName() { // an accessor method (sometimes called a getter)
return firstName;
}

// a method to get the last name of this object
public void setFirstName(String firstName) { // a setter method (sometimes called a setter)
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}
}

Student.java

public class Student { // a class named Student
private String firstName; // See Teacher class for reference
private String lastName; // See Teacher class for reference
private double gpa; // an instance variable of type double to keep track of student GPA
private int numCreditsGained; // an instance variable of type int to keep
// track of the number of credits gained by this student

// Student constructor
public Student(String firstName, String lastName, double gpa, int numCreditsGained) {
this.setFirstName(firstName); // Example of using a setter method to set the instance variables
this.setLastName(lastName); // See Teacher constructor for an alternate way of
// assignment instance variables
this.setGpa(gpa);
this.setNumCreditsGained(numCreditsGained);
}

public String getFirstName() { // Getter method
return firstName;
}

public void setFirstName(String firstName) { // Setter method
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public double getGpa() {
return gpa;
}

public void setGpa(double gpa) {
this.gpa = gpa;
}

public int getNumCreditsGained() {
return numCreditsGained;
}

public void setNumCreditsGained(int numCreditsGained) {
this.numCreditsGained = numCreditsGained;
}
}

Assignment.java

public class Assignment { // a class named Assignment – an assignment within a course
private String assignmentName;
private String assignmentType;
private int numPointsPossible;
private double difficultyRating;

public Assignment(String assignmentName, String assignmentType, int numPointsPossible, double difficultyRating) {
this.setAssignmentName(assignmentName);
this.setAssignmentType(assignmentType);
this.setNumPointsPossible(numPointsPossible);
this.setDifficultyRating(difficultyRating);
}

public String getAssignmentName() {
return assignmentName;
}

public void setAssignmentName(String assignmentName) {
this.assignmentName = assignmentName;
}

public String getAssignmentType() {
return assignmentType;
}

public void setAssignmentType(String assignmentType) {
this.assignmentType = assignmentType;
}

public int getNumPointsPossible() {
return numPointsPossible;
}

public void setNumPointsPossible(int numPointsPossible) {
this.numPointsPossible = numPointsPossible;
}

public double getDifficultyRating() {
return difficultyRating;
}

public void setDifficultyRating(double difficultyRating) {
this.difficultyRating = difficultyRating;
}
}

CollegeCourse.java

public class CollegeCourse { // a class named CollegeCourse – for example a Java 1 Course
private Student[] theStudents; // a Student array, used to keep track of the students for this course
private Teacher theTeacher; // a Teacher object, used to keep track of the teacher for this course
private Assignment[] theAssignments; // an Assignment array, used to keep track of the
//assignments for this course
private int courseNumber;
private int numCredits;
private double difficultyRating;
public static final boolean IS_REQUIRED_FOR_DEGREE = true; // a static final variable

public CollegeCourse(Student[] theStudents, Teacher theTeacher, Assignment[] theAssignments, int courseNumber, int numCredits, double difficultyRating) {
this.theStudents = theStudents;
this.theTeacher = theTeacher;
this.theAssignments = theAssignments;
this.courseNumber = courseNumber;
this.numCredits = numCredits;
this.difficultyRating = difficultyRating;
}

public Student[] getTheStudents() {
return theStudents;
}

public void setTheStudents(Student[] theStudents) {
this.theStudents = theStudents;
}

public Teacher getTheTeacher() {
return theTeacher;
}

public void setTheTeacher(Teacher theTeacher) {
this.theTeacher = theTeacher;
}

public Assignment[] getTheAssignments() {
return theAssignments;
}

public void setTheAssignments(Assignment[] theAssignments) {
this.theAssignments = theAssignments;
}

public int getCourseNumber() {
return courseNumber;
}

public void setCourseNumber(int courseNumber) {
this.courseNumber = courseNumber;
}

public int getNumCredits() {
return numCredits;
}

public void setNumCredits(int numCredits) {
this.numCredits = numCredits;
}

public double getDifficultyRating() {
return difficultyRating;
}

public void setDifficultyRating(double difficultyRating) {
this.difficultyRating = difficultyRating;
}
}

Main.java

public class Main {

/**
* This is the program entry point
*/
public static void main(String[] args) {
Student studentJohn = new Student(“John”, “Doe”, 3.25, 12); // new-up a Student object, named John
Student studentJane = new Student(“Jane”, “Doe”, 3.58, 9); // new-up a Student object, named Jane
Teacher coscTeacher = new Teacher(“Tom”, “Arenivas”); // new-up a Teacher object, named Tom

// new-up an Assignment object for the Java course
// Assignment name: Programming Assignment 1
// Assignment Category: Assignment
// # of points possible: 100
// Difficulty rating: 5.0
Assignment programmingAssignment1 =
new Assignment(“Programming Assignment 1”, “Assignment”, 100, 5.0);

// new-up an Assignment object for the Java course
// Assignment name: Programming Assignment 2
// Assignment Category: Assignment
// # of points possible: 100
// Difficulty rating: 7.5
Assignment programmingAssignment2 =
new Assignment(“Programming Assignment 2”, “Assignment”, 100, 7.5);

// new-up an Assignment object for the Java course
// Assignment name: Quiz 1
// Assignment Category: Quiz
// # of points possible: 200
// Difficulty rating: 7.5
Assignment quiz1 = new Assignment(“Quiz 1”, “Quiz”, 200, 7.5);

// new-up an Assignment object for the Java course
// Assignment name: Exam 1
// Assignment Category: Exam
// # of points possible: 400
// Difficulty rating: 9.5
Assignment exam1 = new Assignment(“Exam 1”, “Exam”, 400, 9.5);

// new-up an Assignment object for the Java course
// Assignment name: Exam 2
// Assignment Category: Exam
// # of points possible: 400
// Difficulty rating: 10.0
Assignment exam2 = new Assignment(“Exam 2”, “Exam”, 400, 10.0);

// new-up an Assignment object for the Java course
// Assignment name: Final Exam
// Assignment Category: Final Exam
// # of points possible: 1,000
// Difficulty rating: 10.0
Assignment finalExam = new Assignment(“Final Exam”, “Final Exam”, 1000, 10.0);

// Create a Student array. We insert John and Jane into this list. They will
// be students of the Java 1 course.
Student[] studentList = new Student[] {
studentJane,
studentJohn
};

// Create an Assignment Array. We insert the programming assignments, quizzes, exams and final exam
// into this list. These assignments will be a part of the Java 1 course.
Assignment[] assignmentList = new Assignment[]{
programmingAssignment1,
programmingAssignment2,
quiz1,
exam1,
exam2,
finalExam
};

// Create a new CollegeCourse object. This object represents the java 1 course.
// We pass in, as arguments into the constructor, the:
// 1. List of students
// 2. Teacher
// 3. List of assignments
// 4. Course Number
// 5. Number of credits for this course
// 6. Difficulty rating (this is an arbitrary metric)

CollegeCourse java1Course = new CollegeCourse(studentList, coscTeacher, assignmentList, 701, 3, 7.5);

// Print the details of the Java 1 course object that we created
System.out.println(“Java 1 Course – ” + java1Course.getCourseNumber());
System.out.println(“——————————————“);
System.out.println(“Required for degree: ” + CollegeCourse.IS_REQUIRED_FOR_DEGREE);
System.out.println(“Instructor: ” + java1Course.getTheTeacher().getFirstName() + ” ” + java1Course.getTheTeacher().getLastName());

// Loop through all the students of this course and print their names
System.out.println(“Student List:”);
for(int i = 0; i < java1Course.getTheStudents().length; ++i) { Student currentStudent = java1Course.getTheStudents()[i]; System.out.println("tStudent #" + (i+1) + ": " + currentStudent.getFirstName() + " " + currentStudent.getLastName()); } // Loop through all of the assignments for this course and print the assignment name, type, and the number of points possible System.out.println("Assignment List:"); for(int i = 0; i < java1Course.getTheAssignments().length; ++i) { Assignment currentAssignment = java1Course.getTheAssignments()[i]; System.out.println("tAssignment #" + (i+1) + ": " + currentAssignment.getAssignmentName() + " " + currentAssignment.getAssignmentType() + " Points possible: " + currentAssignment.getNumPointsPossible()); } } } Output of Main.java Java 1 Course - 701 ------------------------------------------ Required for COSC degree: true Instructor: Tom Arenivas Student List: Student #1: Jane Doe Student #2: John Doe Assignment List: Assignment #1: Programming Assignment 1 Assignment Points possible: 100 Assignment #2: Programming Assignment 2 Assignment Points possible: 100 Assignment #3: Quiz 1 Quiz Points possible: 200 Assignment #4: Exam 1 Exam Points possible: 400 Assignment #5: Exam 2 Exam Points possible: 400 Assignment #6: Final Exam Final Exam Points possible: 1000 Process finished with exit code 0