homework8

# homework8 - 15-100 HOMEWORK 8 - FALL 2007Answer the...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 15-100 HOMEWORK 8 - FALL 2007Answer the following questions on paper and hand in at the start of class on the due date indicated. Let a ParkingLotclass be defined as follows: public class ParkingLot{ private Car carArray; private int numCars; public ParkingLot() { carArray = new Car[1]; numCars = 0; } public void insertAtEnd(Car newCar) { if (numCars == carArray.length) doubleLength(); carArray[numCars] = newCar; numCars++; } private void doubleLength() { Car newArray = new Car[carArray.length*2]; for (int index = 0; index < carArray.length; index++) newArray[index] = carArray[index]; carArray = newArray; } public String toString() { String result = "numCars = " + numCars + "\n"; result += "carArray.length = " + carArray.length + "\n"; for (int i = 0; i < numCars; i++) result += "carArray[" + i + "] = " + carArray[i].toString(); return result; } // other methods } This class uses the Carclass defined in lecture. (Refer to your course notes for this class.) 1. (a) Write a Java class called...
View Full Document

## This note was uploaded on 01/25/2010 for the course CS 15100 taught by Professor Tom during the Fall '07 term at Carnegie Mellon.

### Page1 / 3

homework8 - 15-100 HOMEWORK 8 - FALL 2007Answer the...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online