Question: EXTEND FOLLOWING CLASS Create a new class CollegeCourse that extends your Courses class. This new class should include fields for the college name and course

EXTEND FOLLOWING CLASS

Create a new class "CollegeCourse" that extends your Courses class. This new class should include fields for the college name and course number (i.e. COMP600 or ENG101, etc)

Include two constructors, two accessor methods and two mutator methods. Create a toString method that overrides the "Course" class toString method. Create an equals method that compares the teacher and course number to determine if 2 classes are the same.

import java.util.*;

class Course { String title; //title of course String teacher; //teacher of course int room; //room number int periodTime; // 0 to 24 as int form ArrayList studentList; //list containing all students in class public Course (String t, String ch, int r, int p) { //constructor with all values given title = t; teacher = ch; room = r; periodTime = p; studentList = new ArrayList<>(); } public Course () { //defualt constructor this ("", "", 0, 0); } public int getPeriodTime () { //returns time of period return periodTime; } public boolean isStudentEnrolled (int studentId) { //checks if student is enrolledby using contains method on ArrayList and returns as a boolean return studentList.contains(studentId); } public boolean hasSameTimeAs (Course c) { //checks if this course is at the same time as another return periodTime == c.getPeriodTime (); } public void addStudent (int sid) { //adds a student to the ArrayList studentList.add(sid); } public String toString () { //String method of class return "Course: " + title + " Teacher: " + teacher + " Room: " + String.valueOf (room) + " Period time: " + String.valueOf (periodTime) + " # Students: " + studentList.size(); }

/* This is the client code*/ public class Main { public static void main(String[] args) { /*main method*/ Course c1 = new Course ("Math", "P White", 143, 9); Course c2 = new Course ("Science", "A Einstein", 203, 11); /*Information of each course*/ Course c3 = new Course ("Literature", "Shake Spear", 100, 11); /*This is the course's data*/ c1.addStudent (230); c2.addStudent (230); c1.addStudent (104); /*Prints information*/ System.out.println (c1); System.out.println (c2); System.out.println (c3); System.out.println (c1.hasSameTimeAs (c3)); System.out.println (c2.hasSameTimeAs (c3)); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!