Sit-in Lab #1

CS1101 AY2009/10 Semester 1

Date: 18 September 2009, Friday

School of Computing, National University of Singapore


0 Instructions

Please follow the instructions on the first page.

Time limit is 1 hour 20 minutes.

Do NOT use array(s) for this lab.

Please do NOT reveal the question to anybody until tomorrow.

1 Task

You are to write two programs: ToyCar.java and SitInLab1.java.

You may assume that the input data are correct, so you do not need to do input data validation.

Remember not to create multiple instances of Scanner. One instance of Scanner is sufficient.

ToyCar.java

The ToyCar class should contain the following data members:

There is no need to add any other data members.

Your ToyCar class should contain at least a default constructor and appropriate accessors and mutators. Even if a particular accessor or mutator might not be needed by SitInLab1.java, you should still include it for completeness.

The default constructor should create a new ToyCar object with the following default values:

You may write another constructor if you wish. Do NOT add any other methods besides the constructor(s), accessors and mutators.

SitInLab1.java

This application is to read in data about a toy car to create a ToyCar object. The input data includes the model, colour, initial odometer value, the number of trips, and for each trip, the distance travelled (a positive real number).

You may assume that the odometer value and distance travelled has at most one decimal place, and the number of trips is non-negative.

(You will find that there is actually no absolute need to create the ToyCar object, as the task is very simple. However, please create the ToyCar object as instructed anyway, and use the accessors to retrieve information from the object, even though the information are in the variables that hold the input data. We want to test you on how you use the ToyCar class.)

After all the toy car's information are read, the program is to compute the final odometer value, the average distance travelled per trip, and the maximum difference in distance between two consecutive trips. The program then displays the outputs as shown in the sample runs below.

For example, in sample run #1 below, the difference in distance between trip 1 and trip 2 is 4.8, while the difference in distance between trip 2 and trip 3 is 10.8. Hence the maximum difference is 10.8.

You are to display the real numbers in one decimal place.

You may write additional method(s) in SitInLab1.java if you wish.

Refer to the sample runs below and make sure that your program produces the output in exactly the same format, or your output will be deemed wrong.

2 Sample Runs

Sample run #1:

$javac ToyCar.java
$javac SitInLab1.java
$java SitInLab1
Enter model: Viaxer III
Enter colour: white
Enter odometer value: 980.5
Enter number of trips: 3
Distance for trip 1: 23.8
Distance for trip 2: 19
Distance for trip 3: 8.2
Model: Viaxer III
Colour: white
Odometer: 31.5
Trips: 3
Distance per trip: 17.0
Maximum difference between two consecutive trips: 10.8

Sample run #2:

Enter model: Ultimate 2100
Enter colour: black
Enter odometer value: 100
Enter number of trips: 5
Distance for trip 1: 1084.9
Distance for trip 2: 900
Distance for trip 3: 1230.5
Distance for trip 4: 1508
Distance for trip 5: 1450.2
Model: Ultimate 2100
Colour: black
Odometer: 273.6
Trips: 5
Distance per trip: 1234.7
Maximum difference between two consecutive trips: 330.5

Sample run #3:

Enter model: Zeus
Enter colour: blue
Enter odometer value: 820.3
Enter number of trips: 1
Distance for trip 1: 1563.2
Model: Zeus
Colour: blue
Odometer: 383.5
Trips: 1
Distance per trip: 1563.2
Maximum difference between two consecutive trips: 0.0

Sample run #4:

Enter model: Morton Plus
Enter colour: grey
Enter odometer value: 70
Enter number of trips: 0
Model: Morton Plus
Colour: grey
Odometer: 70.0
Trips: 0
Distance per trip: 0.0
Maximum difference between two consecutive trips: 0.0

3 Skeleton Programs

The following two skeleton programs are available in your working directory.

4 Marking Scheme

As usual, your programs will be tested with a number of test data, and 60 marks will be awarded to correctness.

20 marks will be awarded to design. In this case it includes (but not limited to) the following:

20 marks will be awarded to style, which includes (but not limited to) appropriate comments, program description, filling in of discussion group, proper indentation, proper naming of identifiers, etc. For example, if you forget to include your name at the top of your program, 2 marks will be deducted.


Tuesday, July 21, 2009 5:56:05 PM SGT