I've provided a Student.java class. You will use this class inyour project. Review the code and make sure it makes sense. Notethat the Student class includes an equals method- we haven'tcovered this yet, so you can ignore this method for now.
The Student id is meant to be unique. When comparing students,compare their id Strings to see if they are a match. (Remember whatcode you should use to compare Strings!)
Do not modify the Student.javaclass.
(Note: for now, if a user enters two students with the sameid but different names, your program will treat these Students asthe same.)
Write a Course class. A Course keeps track of Studentsenrolled in the Course. Some are enrolled on the roster and someare enrolled on the waitlist. Implement methods to add a student tothe course and drop a student from the course.
Your program must compile. Your class should contain thecore class components listed below and also the class-specificmethods described here.
Instance Data Variables
Declare instance data variables torepresent:
the course name
the roster and waitlist as two Student[]variables
the maximum number of students allowed on the waitlistand on the roster
any other variables you think are helpful
Constructor
A constructor will initialize Courseobjects.
A Course object is initially created by specifying themaximum number of students allowed on the roster and on thewaitlist. Take these values in as parameters to theconstructor.
In the constructor, initialize the instance datavariables.
The roster and waitlist arrays are initiallyempty.
Getters and Setters
Carefully consider which variables should have setters.If you choose not to include a setter, add a comment as towhy.
Include validity checks in setters when appropriate toprevent invalid values from being assigned.
Note: the tester program relies on some getter methodsexisting that use these names: getMaxEnrolled, getMaxWaitlist,getNumEnrolled, and getNumWaitlist. If you want to use differentnames, you can search-and-replace those names in the testerprogram.
toString
Write the toString method. The text representation of acourse should include:
the name of the course
the number of students enrolled in the course and themaximum number that can be enrolled
the roster of enrolled students (all student data forall enrolled students should be included)
the number of students on the waitlist and the maximumnumber that can be on the waitlist
the students on the waitlist (all student data for allwaitlisted students should be included)
note: for full credit, make sure that there are no"nulls" printed with the arrays
addStudent Method
An addStudent method adds a Student to theCourse.
method header: public boolean addStudent(Studentstudent)
this method adds a student to the course if they areeligible and if there is room
a student is eligible to add the course if:
they have paid tuition and
they are not already enrolled on the roster orwaitlist
if a student is eligible to add:
if there is room on the roster, add the student to theroster
if the roster is full but there is room on the waitlist,add the student to the waitlist
if there is no room on the roster or waitlist, do notadd the student
return true or false based on whether the student isadded or not
if a student is added to either the roster or thewaitlist, the method should return true
dropStudent Method
A dropStudent method removes a Student from theCourse.
method header: public boolean dropStudent(Studentstudent)
this method drops a student from the course
if the student is not on the roster or waitlist, thestudent cannot be dropped
if the student is on the waitlist, remove the studentfrom the waitlist
if the student is on the roster, remove the student fromthe roster
since there is now one more space in the class, if thewaitlist is not empty, take the first student off the waitlist andadd them to the roster; then remove that student from the waitlist(and then shift everyone else up in their waitlistposition)
return true or false based on whether the student isdropped or not
if a student is dropped from either the roster or thewaitlist, the method should return true
Code Design
Follow object-oriented and general coding principles,including principles of encapsulation.
Follow Java coding conventions and bestpractices.
Follow naming conventions for variables, methods, andconstants.
Properly indent your code.
Design your code to reduce repeated or duplicatedcode.
Use helper methods.
Find yourself writing the same or very similar code inmore than one place? Put it in a private helper methodinstead!
Remember that you are allowed to pass instance datavariables as parameters to private methods if ithelps.
Choose appropriate visibility for methods.
Methods that are part of the functionality of the objectshould be public.
Helper methods should be private.
Choose appropriately whether methods and variablesshould be instance (non-static) or static.
Methods and variables associated with each individualobject should not be static.
Methods and variables associated with the class itselfthat are common across all objects should be static.
Summary of Rules for Adding/DroppingStudents
Students on the roster can be stored in anyorder.
Students on the waitlist should be stored in the orderthey were added.
A student can only be added to the course if they havepaid their tuition.
A student cannot be on the roster or waitlist more thanonce.
A student cannot be on both the roster and thewaitlist.
If a student on the roster drops the course, the firststudent from the waitlist should be added to the roster (andremoved from the waitlist).
When searching for whether a student is on the roster orwaitlist, compare the Student ids to see if a student is amatch.
Interactive Driver
Write an interactive driver program that getsinformation from the user (through the keyboard) to create Studentsand add/drop them to a Course.
Create a Course object (you can decide the name androster/waitlist sizes).
Note: this part does not need to be interactive. You canhard-code the Course information into your program.
Inside of a loop, show the user a menu and let themchoose one of these actions:
Add a student by entering the student's name, id, andpaid tuition status.
Drop a student by entering the student's information(you can decide what information is needed)
View a text representation of the course
Quit the program.
If the user chooses to add or drop, display the result(success/failure) of that action.
Use the loop so that the user can repeat these actionsas many times as they want before quitting.
Student.Java class
public class Student { /* DO NOT MODIFY THIS CLASS!!! */
private String name, id; private boolean tuitionPaid;
public Student(String name, String id,boolean tuitionPaid) { this.name = name; this.id = id; this.tuitionPaid =tuitionPaid; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getID() { return id; }
public void setID(String id) { this.id = id; }
public boolean isTuitionPaid() { return tuitionPaid; }
public void setTuitionPaid(booleantuitionPaid) { this.tuitionPaid =tuitionPaid; }
@Override public String toString() { return name + " (" + id +")"; } // Don't worry about this method for now- we'lllearn about it later on! @Override public boolean equals(Object obj) { if(obj instanceof Student){ Studentother = (Student) obj; returnthis.id.equalsIgnoreCase(other.id); } else { returnfalse; } }
}
I've provided a Student.java class. You will use this class in your project. Review the code and make sure it makes sens
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
I've provided a Student.java class. You will use this class in your project. Review the code and make sure it makes sens
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!