CS1150 (Fall 2012, Section 4): Programming Assignment 7

Modular Code


  • In this assignment, we will improve upon the result of Assignment 6 and develop a very simple fleet management system. This fleet is very small; there is a primary car, a secondary car, and either or both of these slots may be open.
  • Add a named constant to the car class called DEFAULT_MPG to represent a default MPG of 23.0.
  • Create a Java class called fleet. Implement a main mathod in this class. As before, this is for your own testing; I will use my own main method to grade your program. This fleet class should have two instance variables of type car, primaryCar and secondaryCar. Implement accessors and mutators for these properties.
  • Implement an instance method in the fleet class called size that returns the number of cars (0, 1, or 2) in the fleet.
  • Also implement an instance method in the fleet class called toString. The toString method should take no arguments and return a String containing the size of the fleet and the mileage and fuel level of any cars that are in the fleet.
  • In your main method, create a fleet, print it out, add a primary and secondary car, and again get (and print) the description. Drive each car 30 miles, then 60 miles. Fuel up the primary car and then attempt to drive each 300 miles. Print out the fleet's description after each step. Then add a new primary car and print the fleet. When you create each car, immediately fill its gas tank and set the average miles per gallon to the value in the DEFAULT_MPG named constant.
  • Deliverables

    Submit as per the syllabus.