Goal: In this lab, we will practice how to apply the composition concept to reus
ID: 3705861 • Letter: G
Question
Goal: In this lab, we will practice how to apply the composition concept to reuse a Java class as a whole (i.e., not by copying and pasting) that has already been defined by the programmer. 1. Implement the Course Class. Implement the following class: public class Course *The basic feature of a course public String courseName; private String courseNumber; public String instructorName; private Student[] listStudents; *Construct a course object (TWO constructors) / Accessors and mutators (one pair per each feature) *toString method Fill in the blanks above according to the guidelines in the comments. Also write a main method that will use one of the two Course constructors to create two Course objects. Your main method should print out the details of these two Courses (each course with at least 3 students).Explanation / Answer
import java.util.Arrays; public class Course { private String courseName; private String courseNumber; private String instructorName; private Student[] listStudents; public Course() { } public Course(String courseName, String courseNumber, String instructorName) { this.courseName = courseName; this.courseNumber = courseNumber; this.instructorName = instructorName; listStudents = new Student[100]; } public String getCourseName() { return courseName; } public void setCourseName(String courseName) { this.courseName = courseName; } public String getCourseNumber() { return courseNumber; } public void setCourseNumber(String courseNumber) { this.courseNumber = courseNumber; } public String getInstructorName() { return instructorName; } public void setInstructorName(String instructorName) { this.instructorName = instructorName; } public Student[] getListStudents() { return listStudents; } public void setListStudents(Student[] listStudents) { this.listStudents = listStudents; } @Override public String toString() { return "Course{" + "courseName='" + courseName + ''' + ", courseNumber='" + courseNumber + ''' + ", instructorName='" + instructorName + ''' + ", listStudents=" + Arrays.toString(listStudents) + '}'; } } public class TestCourse { public static void main(String[] args) { Course course = new Course(); Course course2 = new Course("CSE", "123", "ronaldo"); System.out.println(course2); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.