/*** * Excercise 21: Car2.java * Author: Peter Sestoft, updated by Anne * Translated by: Cecilie, d. 10.09.02 * * Field-declaration : make, licensePlate, colour, SerialNo, serialNoCounter * Constructor-declaration : Car(String, String, String), Car(String, String) * Method-declaration : sameMake(Car), nextSerialNo(), toString() ***/ public class Car2 { private String make, licensePlate, colour; private int serialNo; private static int serialNoCounter = 0; public Car2(String make, String licensePlate, String colour) { this.make = make; this.licensePlate = licensePlate; this.colour = colour; serialNoCounter = serialNoCounter + 1; this.serialNo = serialNoCounter; } public boolean sameMake(Car2 c) { return this.make.equals(c.make); } public static int nextSerialNo() { return serialNoCounter + 1; } public String toString() { return "Car:\n\t Make: " + make + "\n\t License plate: " + licensePlate + "\n\t Colour: " + colour + "\n\t Serial no.: " + serialNo; } }