Question: C201/I210 Computer Programming II Java L-17: Course Class Complete the following lab steps : Create a new Java project using NetBeans, giving it the name

C201/I210 Computer Programming II Java

L-17: Course Class

Complete the following lab steps:

Create a new Java project using NetBeans, giving it the name L-17.

Create a Courseclass modeled after Listing 10.6 (page 385) in your text, Course.java (you may use the actual code obtained from below).

Create a CourseClientclass to test the basic Course class definition (Listing 10.7). Make sure you can create a course and add students.

Modify the Course class to include the following:

a static numberOfCoursesinstance variable that is incremented each time a new course is created

a static getNumberOfCourses method

a displayNumberOfCoursesmethod

a displayNumberOfStudentsmethod that prints the number of students in a specific class with an appropriate label, such as Total students enrolled: 32

a printRostermethod that shows the name of the course followed by a numerical listing of all students in the course followed by a line showing the total students enrolled in the course (use the displayNumberOfStudents method)

a setCourseNamemethod that allows the course name to be changed to the value passed in as a parameter

an overloaded addStudentmethod with no parameters that asks for the students name to be added to the course.

Implement the dropStudent method.

Add a new method clear() that removes all students from the course.

Update the CourseClient class to thoroughly test your added methods.

Create at least 3 courses with a minimum of 5 students each. For at least one of the courses, use a loop with a call to the new addStudentmethod to fill up the course.

Change the name of one of your courses.

Display the number of courses created.

Display the rosters for each course. Make sure you clearly label all of your outputs.

Make sure your code is readable, documented, indented and spaced properly. Comment block, also.

public class Course {

private String courseName;

private String[] students = new String[4];

private int numberOfStudents;

public Course(String courseName) {

this.courseName = courseName;

}

public void addStudent(String student) {

students[numberOfStudents] = student;

numberOfStudents++;

}

public String[] getStudents() {

return students;

}

public int getNumberOfStudents() {

return numberOfStudents;

}

public String getCourseName() {

return courseName;

}

public void dropStudent(String student) {

}

}

You will need a method to return the index of a searched-for item (change from int to String and use .equals instead of ==).

int indexOf(int value) { for (int i = 0; i < size; i++) { if (values[i] == value) { return i; } } return -1; } 

To delete an item from an array, this might work (convert int to String again).

void remove(int value) { for (int i = 0; i < size; i++) { if (values[i] == value) { --size; for (; i < size; ++i) { values[i] = values[i + 1]; } return true; } } }

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!