Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me with this assignment, thank you! **Course.java** **Roster.java**

ID: 3857958 • Letter: P

Question

Please help me with this assignment, thank you!

**Course.java**

**Roster.java**

**Student.java**

**TestRoster.java**

Thanks again!

This assignment. involves a program made up of several Java classes: An object of class Course represents a course, e.g. 198:11 1 . 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 o There will never be an object that is an instance of the class TestRoster. 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 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 Rosterjava 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.

Explanation / Answer

Here is your Roster.java class

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) {

students = new Student[stopPoint];

this.stopPoint = stopPoint;

this.course = course;

numStudents = 0;

}

/**

* 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() {

if (this.numStudents == this.stopPoint) {

return true;

}

return false;

}

/**

* 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) {

if ((this.numStudents > 0 && findStudent(student)) || this.numStudents == this.stopPoint) {

return false;

} else {

students[numStudents++] = student;

return true;

}

}

/**

* returns true if and only if the student is on this roster.

*/

public boolean findStudent(Student student) {

int j;

for (j = 0; j < students.length; j++) {

if (students[j].equals(student)) {

break;

}

}

if (j == students.length) {

return true;

} else {

return false;

}

}

/**

* 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) {

if (!findStudent(student)) {

return false;

} else {

int j;

for (j = 0; j < students.length; j++) {

if (students[j].equals(student)) {

break;

}

}

for (int i = j; i < students.length; i++) {

students[j] = students[j + 1];

this.numStudents--;

}

return true;

}

}

}

Sample Run: -

198:111 0/4
Doe true
198:111 1/4
Student: Doe, John

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote