All pastes #623773 Raw Edit

Miscellany

public java v1 · immutable
·published 2007-07-17 20:43 UTC
rendered paste body
/* * Creates a Gas Tracking System */public class Car {  private double fuelLevel;  private int mpg;    /*   * Creates a car with fuel level of 0   * @param initialMPG Miles Per Gallon   */  public Car(int initialMPG) {      this.fuelLevel = 0;      this.mpg = initialMPG;  }    /*   * Simulates driving the car   * @param distance Distance in Miles   */  public void drive(double distance) {      this.fuelLevel = this.fuelLevel - (distance/this.mpg);  }  /*   * Shows the amount of fuel left   * @return The amount of fuel left (gallons)   */  public double getFuel() {      return this.fuelLevel;  }    /*   * Adds fuel to the car   * @param amount Amount of fuel to add (gallons)   */  public void addFuel(double amount) {      this.fuelLevel = this.fuelLevel + amount;  }}