The Car Class Construction

/**
* The Car class will model a car. It will be able to have
* gas added to it, drive a certain distance and report the
* amount of gas left in the tank
*
* @author (your name)
* @version (a version number or a date)
*/

Instance Fields Methods
  • mileage
  • tankSize
  • gasInTank
  • mpg
  • drive(double numMiles) // if numMiles > remaining miles in tank, go until empty
  • fillTank()
  • fillTank(double numGallons) // if numGallons > amount empty, throw an exception!
  • toString()
  • // accessors and modifiers for all instance variables
  • // JAVA DOC each method
  • Constructors

    // generic values:
    // tankSize =11.3
    // mpg = 21
    // gasInTank/mileage = 0

    public Car() // initialize all instance fields to generic values

    public Car(double mpg) // initialize all instance fields to generic values except for mpg

    public Car(double mpg, double tankSize) // make all else generic