Java Programming (The Course class) Revise the Course class as follows: • Revise the getStudents() method to return an array whose length is the same as the number of students in the course. (Hint: create a new array and copy students to it.) • The array size is fixed in Listing 10.6. Revise the addStudent method to automatically increase the array size if there is no room to add more students. This is done by creating a new larger array and copying the contents of the current array to it. • Implement the dropStudent method. • Add a new method named clear() that removes all students from the course. Write a test program that creates a course, adds three students, removes one, and displays the students in the course
Java
(The Course class) Revise the Course class as follows:
• Revise the getStudents() method to return an array whose length is the same as the number of students in the course. (Hint: create a new array and copy students to it.)
• The array size is fixed in Listing 10.6. Revise the addStudent method to automatically increase the array size if there is no room to add more students. This is done by creating a new larger array and copying the contents of the current array to it.
• Implement the dropStudent method.
• Add a new method named clear() that removes all students from the course.
Write a test program that creates a course, adds three students, removes one, and displays the students in the course
![LISTING 10.6 Course.java
1 public class Course {
2
private String courseName;
private String[] students = new String[100];
private int number0fStudents;
3
create students
4
public Course (String courseName) {
this.courseName = courseName;
6
add a course
7
9
public void addStudent (String student) {
students(number0fStudents] = student;
numberOfStudents++;
}
10
11
12
13
14
public String[ getStudents() {
15
return students
16
return students;
17
18
public int getNumber0fStudents(0 {
return number0fStudents;
19
number of students
20
21
22
public String getCourseName() {
return courseName;
23
24
25
26
public void dropStudent(String student) {
|/ Left as an exercise in Programming Exercise 10.9
27
28
29
}
30 }](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff1782974-7f6f-4ae8-8de0-5b81c9f6f2aa%2F960ca8cd-b80b-45dd-b63d-b89e4210b035%2Fjp8ykhp_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 5 steps









