Question: Problem: Rosters This assignment. involves a program made up of several Java classes: Your task is to finish Roster.java by replacing each line marked //
Problem: Rosters This assignment. involves a program made up of several Java classes:
Your task is to finish Roster.java by replacing each line marked // replace this line with your code with code that makes the method do what its comment says it does. There are 4 such lines.
An object of class Course represents a course, e.g. 198:112. A course has a department number and a course number.
An object of class Student represents a student. A student has a personal (first) name and a family (last) name.
An object of class Roster represents a particular section of a course. A roster has an array of students, an int numStudents, that says how many students there are in the section, an int stopPoint that gives the maximum number of students that may be in the section, and a course that says which course this roster is a section of. Note that the students are not in any particular order in the array, but they will be in the first numStudents elements of the array.
The class TestRoster that has a main method that can be used for testing Roster. Of course you will need to add tests to TestRoster - this is just a framework to get you started. There will never be an object that is an instance of the class TestRoster.
Some rules to follow
You may not change Course.java or Student.java. (You will not be handing these in, anyway.)
You may put any code you want in TestRoster.java to test your code. (You will not hand this is, either.)
You must replace each of the lines in Roster.java marked replace this line. (Replace them with as many lines of code as you want.)
You may add methods to Roster.java as long as they are private.
You may not make any other changes to Roster.java.
public class Roster { Student [ ] students; int numStudents; int stopPoint; Course course; /** * The constructor for this class. * Initialize this roster to empty, i.e., holds no students, * with given stop point and course */ public Roster(int stopPoint, Course course){ // replace this line with your code } /** * toString is a method every class has. It returns a string * that represents the object for printing */ public String toString( ){ String res = ""; for(int j = 0; j < numStudents; j++){ res = res + " " + students[j].toString(); } return course + " " + numStudents + "/" + stopPoint+res; } /** * isFull returns true if and only if the number of students in it is * at the stopPoint */ public boolean isFull( ){ return false; // replace this line with your code } /** * add given student to this roster * if student already on roster or numStudents already == stopPoint, * do not change roster and return false * @return true if successful, else false */ public boolean addStudent(Student student){ return false; // replace this line with your code } /** * returns true if and only if the student is on this roster. */ public boolean findStudent(Student student){ return false; // replace this line with your code } /** * Remove given student from this roster. * If student is not on this roster do not change roster and return false * @return true if successful, else false */ public boolean dropStudent(Student student){ return false; // replace this line with your code } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
