Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Part 1 subpackage p1 under the hw1 package. In the p1 subpackage, create a public class named Course, and add the following private

image text in transcribedimage text in transcribedimage text in transcribed

Create a Part 1 subpackage p1 under the hw1 package. In the p1 subpackage, create a public class named Course, and add the following private data fields to the Course class: - name, which is of type String and represents the name of a course. We assume here for simplicity that every course has a unique name that identifies it. - capacity, which is an integer representing the maximum number of students that can enroll in the course. - roster, which is an Array List of strings each representing the name of a student enrolled in the course. Assume here that every student has a distinct name so that a student's name identifies the student. Add the following public methods to the Course class: - A constructor public Course (String name, int capacity) that initializes the name and capacity fields with the values of the arguments, and initializes the roster field to an empty list. Assume here that capacity >0 is satisfied. - A getter for the name field. - A method public boolean add (String student) that adds the student in the argument to the roster and returns true if the capacity has not been reached. Otherwise, the method should print an error message "__ is full" without adding the student to the roster, where the underscore should be replaced with the name of the course, and return false. - A method public void remove (String student) that removes from the roster the student in the argument. You can assume that the student in the argument is a student on the roster. - A toString( ) method that returns a string, in the default format of IntelliJ, consisting of the values of all data fields. In the p1 subpackage, create a public class named CourseTest. In the main method of the AccountTest class: - Create a Course object named itec2150, using "ITEC 2150" as the course name and 3 as the capacity. Print the itec2150 object to the console. Your code should print Course { name=' ITEC 2150, capacity =3, roster =[]} - Add "Alice", "Bob", "Carol" and "Daniel" to the itec2150 roster and print the returned results of the add method. Your code should print true true true ITEC 2150 is full false - Print the itec2150 object to the console. Your code should print Course { name= 'ITEC 2150, capacity =3, roster =[ Alice, Bob, Carol ]} - Remove "Bob" from the itec2150 roster and again add "Daniel" to the roster. Print the itec2150 object to the console. Your code should print Course { name= 'ITEC 2150, capacity =3, roster =[ Alice, Carol, Daniel ]} Part 2 Now you will (1) create a Grizzly class and a Student subclass, (2) modify the Course class, and (3) write a class named Hw1Test to test the Grizzly, Student and Course classes. Create a Part 2 subpackage p2 under the hw1 package and copy here the Course class from subpackage p1. In the p2 subpackage, create a public class named Grizzly, and add the following private data fields to the Grizzly class: - A private static data field named numGrizzlies of type int, representing the number of Grizzly objects that have been created. - A protected data field named id of type int, representing the ID that uniquely identifies a GGC member. - A protected data field named name, which is of type String and represents the name of a GGC member. Create the following methods in the Grizzly class: - A constructor public Grizzly (String name) that - Increments the static numGrizzlies field by 1 and assigns the result to the id instance variable. - Initializes the name field with the value of the argument. - Getters for the id and name fields. - Override the equals method so that it compares only the id field and returns true if both Grizzly objects have the same id. Create a public class named Student as a subclass of the Grizzly class, and add the following private data field to the Student class: - courses, which is an Array List of Course objects each representing a course the student is enrolled in

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions