next up previous
Next: Car sales: solution Up: Unit 09 Previous: Car sales: representation of

Car sales: public interface

We can now choose the interface of the classes, through which the clients can make use of the objects of the classes Car and CarList. Specifically, for each functionality we have to define a public method that realizes it and determine its header.

The class Car has the following skeleton

public class Car {
  // representation of the objects of the class
  private String model;
  private int year;
  private int km;
  private double price;

  // public methods that realize the requested functionalities
  public Car(String m, int y, int k, double p) { ... }
  public String toString() { ... }
  public String getModel() { ... }
  public int getYear() { ... }
  public int getKm() { ... }
  public double getPrice() { ... }
  public boolean equalTo(Car c) { ... }
  public static Car read(BufferedReader br) throws IOException { ... }
}

The class CarList has the following skeleton

public class CarList {
  // representation of the objects of the class
  private String filename;

  // public methods that realize the requested functionalities
  public CarList (String fn) { ... }
  public int countNewCars()  throws IOException { ... }
  public Car mostExpensiveCar() throws IOException { ... }
  public void addCar(Car c) throws IOException { ... }
  public void removeCar(Car c) throws IOException { ... }
}


next up previous
Next: Car sales: solution Up: Unit 09 Previous: Car sales: representation of