以下为《Homework2 class composition》的无排版文字预览,完整内容请下载
Homework 2: class composition
The question description.
(The Course class ) Revise the Course class as follows:
1. The array size is fixed in Listing 10.6. Improve it to automatically increase the array size by creating a new larger array and copying the contents of the current array to it.
2. Implement the dropStudent method.
3. Add a new method named clear() that removes all students from the course.
4. Write a test program that creates a course, adds three students, removes one, and displays the students in the course.
The source code
import java.util.*;
public class TestCourse {
public static void main(String[] args) {
Course course1=new Course("Data Structures");
course1.addStudent("Peter Jones");
course1.addStudent("Kim Smith");
course1.addStudent("Anme Kennedy");
System.out.println("Number of students in course1: " + course1.getNumberOfStudents());
String [] students = course1.getStudents();
for (int i=0;i
以上为《Homework2 class composition》的无排版文字预览,完整内容请下载
Homework2 class composition由用户“巨蟹御前女官”分享发布,转载请注明出处