September:16(Wed)

CS 162[M] Homework Assignment #2

Due September 23 (Wednesday)


Preparation for this assignment and upcoming lectures


Objectives

After completing this assignment, you should be able to:


Specification

Implement a class that simulates an automobile's odometer and fuel gauge operations, keeping track of the overall and trip odometers and the amount in the fuel tank.  A person can drive the car and add fuel to the tank.  Feedback is provided to the user via short text messages.

Sample Demonstration

Here is a sample demonstration of the program specified here; your program needs to function like this.  Note that this example does not cover all possible situations; but your program needs to handle everything as specified.  Pay close attention to the use of blank lines between each result for readability.

The user's actions which should cause these results are as follows: (0) initialize the automobile, (1) add 12 gallons to the tank, (2) drive 250 miles using 10 gallons, (3) attempt to put in -3 gallons, (4) attempt to drive 100 miles using 4 gallons, and (5) print the current status.

Initializing Auto 1G12345 for Hugh McGuire


You have added 12 gallons to the tank

You have driven 250 miles (10 gallons were used).

Sorry, you cannot enter a negative amount.

You cannot drive that far - there is not enough fuel.

Current status
======================
VIN             : 1G12345
owner           : Hugh McGuire
miles per gallon: 25.0
odometer        : 250
trip odometer   : 250
fuel gauge      : 2.0
======================

Fields a.k.a. Instance Variables

You need to come up with fields, providing appropriate names and data types for each of them, corresponding to the data which this class is supposed to have: Vehicle Identification Number (VIN), owner, overall odometer, trip odometer, the amount in the fuel tank, and the amount of fuel used since the last time the trip odometer was reset.  Note that VIN isn't really a number since it can contain letters.

Method Signatures

Further Characteristics

Turn In

Weight of This Assignment

This assignment is worth 40 points.