以下为《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》的无排版文字预览,完整格式请下载
下载前请仔细阅读上面文字预览以及下方图片预览。图片预览是什么样的,下载的文档就是什么样的。