homework7 - 15-100 HOMEWORK 7 - FALL 2007 Answer the...

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: 15-100 HOMEWORK 7 - FALL 2007 Answer the following questions on paper and hand in at the start of class on the due date indicated. ----------------------------------------------------|_|_|_|_|_|_|_| |_| | /_\ | /_\ | /_\ | /_\ | /_\ | /_\ | /_\ | ... | /_\ | |OO|OO|OO|OO|OO|OO|OO| |OO| ----------------------------------------------------0 1 2 3 4 5 6 ... 99 We will use the Car class defined in lecture to create a parking lot to hold 100 cars. 1. A file named cardata.txt contains the make and mileage of each of the 100 cars for the parking lot, one car per line. For example, the first three lines of the file might look like this: Saturn 15100 Olds 2353 Honda 43200 (a) Using Java, show how to declare an array of size 100 to hold references to cars. Name this array parkingLot. (b) Using Java, show how to initialize the array with the 100 cars as defined in the data file. 2. Write a Java code fragment that computes and outputs the average mileage of the 100 cars in the parking lot. 3. Write a Java code fragment that rotates the cars in the spaces so the cars all move "right" one position (as shown in the diagram), with the last car in parking space #99 moving to parking space #0. 4. Write a Java code fragment that outputs the parking space number of the first car from the beginning of the parking lot that has a make of "Toyota". If there are no cars that have a make of "Toyota", output "NOT FOUND" instead. Write your answer so that it will work with a full parking lot of any size. 5. Write a Java code fragment that finds the car with the highest mileage in the 100-car parking lot and drives it an additional 10 miles more. Write your answer so that it will work even if some of the spaces are "empty", but you may assume that the lot has at least one car. (BE CAREFUL: Parking space #0 may be empty!) ...
View Full Document

Ask a homework question - tutors are online