Docsity

Introduction to Object -Oriented Programming I - Quiz 7 | CMSC 131, Quizzes of Computer Science

Toggle sidebar
bg1
CMSC131 Fall 2004 Quiz #7, Duration 25 Minutes
First Name:
Last Name:
Student Id:
Section time (10am/11am): TAs:
Problem Description
A class called WaitList represents a set of students waiting to get into a course. The class relies on a
Student class defined as follows:
/* YOU MAY NOT MODIFY THIS CLASS */
public class Student {
private String name;
private int id;
public Student(String sname, int sid) {
name = sname;
id = sid;
}
public Student(Student student) {
name = new String(student.name);
id = student.id;
}
public int getId() {
return id;
}
public String toString() {
return name + " " + id;
}
}
For this quiz you will implement the WaitList class. The class specifications are:
Instance Variable
Student[] array; // Array that represents the list of students
Methods
• Constructor – Creates a waitlist with no students.
• add – This method takes as parameter a reference to the student to be added. The method
makes a copy of the student object and adds the copy to the end of the array representing
the waitlist. The size of the array will be increased by one.
• toString – Returns a string with the name and id of every student in the waitlist.
Information about each student will appear on a line by itself.
WRITE YOUR IMPLEMENTATION ON THE NEXT PAGE
pf3

Partial preview of the text

Download Introduction to Object -Oriented Programming I - Quiz 7 | CMSC 131 and more Quizzes Computer Science in PDF only on Docsity!

CMSC131 Fall 2004 Quiz #7, Duration 25 Minutes

First Name: Last Name: Student Id: Section time (10am/11am): TAs:

Problem Description

A class called WaitList represents a set of students waiting to get into a course. The class relies on a Student class defined as follows:

/* YOU MAY NOT MODIFY THIS CLASS */ public class Student { private String name; private int id;

public Student(String sname, int sid) { name = sname; id = sid; }

public Student(Student student) { name = new String(student.name); id = student.id; }

public int getId() { return id; }

public String toString() { return name + " " + id; } }

For this quiz you will implement the WaitList class. The class specifications are:

Instance Variable

Student[] array; // Array that represents the list of students

Methods

• Constructor – Creates a waitlist with no students.

• add – This method takes as parameter a reference to the student to be added. The method

makes a copy of the student object and adds the copy to the end of the array representing

the waitlist. The size of the array will be increased by one.

• toString – Returns a string with the name and id of every student in the waitlist.

Information about each student will appear on a line by itself.

WRITE YOUR IMPLEMENTATION ON THE NEXT PAGE