CS 1401, Exam #2, version a

Date: Friday, October 7, 2005
Name (please type legibly, ideally in block letters): ______________________________________________________________________

On October 7, 1913, Henry Ford introduced the assembly line at his automobile factory. This made cars cheaper and affordable to most people.

1. With the assembly line, it took 48 man-hours -- i.e., 6 man-days -- to produce a car. Write down a method named cars that, given the number of workers, returns the number of cars that these workers produced per day. Trace your method, on the example of 60,000 workers, and show that your method correctly computes the value 10,000.











































2. If the variable numberOfWorkers has the initial value 60,000, and we run the following sequence of statements, what will be the resulting values of the variables numberOfWorkers and salary:
numberOfWorkers = numberOfWorkers * 2.0;
numberOfWorkers = numberOfWorkers/10;
double salary = 5.0 * numberOfWorkers;
++numberOfWorkers;
What is the advantage of using ++numberOfWorkers instead of numberOfWorkers = numberOfWorkers + 1?
















































3. At first, the Ford Motors Co. produced the model Ford A. Later, a new model Ford AA was introduced. Write a method that, given a string manual in which the name "Ford A" appears exactly once, returns a corrected manual, in which the name "Ford A" is replaced with "Ford AA".
























































4. The Ford automobile museum in Detroit, Michigan, has a large collection of the old Ford cars. Suppose that two cars were made in year1 and year2. We want to sort these values so that the oldest car will be first. Write a piece of code that will sort these values, i.e., if year1 is later than year2 (e.g., 1966 > 1913), it will swap the values of the two variables.
























































5. At a 1914 car race, three cars showed times time1, time2, and time3. Write down a method record2 that, given these three times, returns the value "true" or "false" depending on whether car 2 won the race.


























































6. What are the reasonable test cases for the method you developed for Problem 5? Explain your answer.


























































7. Let us assume that the number of cars produced in different days are stored, line by line, in a file daily.dat. Write down a piece of code that, given this file, computes the overall number of cars produced by the company.
























































8. Define a class Car with three fields make, horsepower, and wheelRadius, constructor method, and methods which return the wheel's circumference and area. Use constant(s) and methods from the Math package.

Reminder: