Quiz 9 - Object Oriented Programming I - Spring 2009 | CMSC 131, Quizzes of Computer Science

Material Type: Quiz; Class: OBJECT-ORIENTED PROG I; Subject: Computer Science; University: University of Maryland; Term: Spring 2009;

Typology: Quizzes

Pre 2010

Uploaded on 07/30/2009

koofers-user-lod
koofers-user-lod 🇺🇸

9 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name (printed):
Student ID #:
Section # (or TA’s:
name and time)
CMSC 131 Quiz #9 Spring 2009
For both of the questions on the other side of this paper, assume the classes shown here:
public class Door {
private int ht;
private int rating;
public Door(int ht, int rating){
// valid constructor for the Door class
}
public Door(Door oldDoor){
// valid copy constructor for the Door class
}
public boolean equals(Door rtDoor){
// valid equals method for the Door class
}
//other methods appear here
}
----------------------------------------------
public class House {
private Door[] all;
private String address;
public House(Door[] doorList, String address){
//valid constructor for the House class
}
public House (House oldHouse){
//valid copy consructor for the House class
}
public boolean equals(House otherHouse){
//valid equals for the House class
}
//Other methods appear here
}
Turn to the other paper to answer the questions. You may separate the two pages (it may be easier for
you that way), but make sure you put your name on both and make sure you turn both back in at the
end of the quiz.
pf3
pf4

Partial preview of the text

Download Quiz 9 - Object Oriented Programming I - Spring 2009 | CMSC 131 and more Quizzes Computer Science in PDF only on Docsity!

Name (printed):

Student ID #:

Section # (or TA’s: name and time)

CMSC 131 Quiz #9 Spring 2009

For both of the questions on the other side of this paper, assume the classes shown here:

public class Door { private int ht; private int rating;

public Door(int ht, int rating){ // valid constructor for the Door class } public Door(Door oldDoor){ // valid copy constructor for the Door class } public boolean equals(Door rtDoor){ // valid equals method for the Door class } //other methods appear here }


public class House { private Door[] all; private String address;

public House(Door[] doorList, String address){ //valid constructor for the House class } public House (House oldHouse){ //valid copy consructor for the House class } public boolean equals(House otherHouse){ //valid equals for the House class } //Other methods appear here }

Turn to the other paper to answer the questions. You may separate the two pages (it may be easier for you that way), but make sure you put your name on both and make sure you turn both back in at the end of the quiz.

This page intentionally blank.

  1. Write the JUnit test that would determine if your House copy constructor (written for the other question) worked correctly. Unlike most JUnit tests, you only need to write enough code to test one case of the copy constructor for the House. Also, this test does not need to be complete. It only needs to make sure you have the new house with the same values. It does not need to make sure aliasing did not occur. (note: this restriction is only for the quiz not for real life.)

import junit.framework.TestCase;

public class HouseTest extends TestCase {

public void testHouseHouse() { // Write the code that would need to be here to test // the copy constructor above. // Only one test is needed - not several as shown in class // or as you shouls have done on the project