IN JAVA Inheritance Using super in the constructor Using super in the method Method overriding |
Write an application with five classes Vehicle, Car, Bus, Truck, and Tester class with main method in it.
The following characteristics should be used: make, weight, height, length, maxSpeed, numberDoors, maxPassenges, isConvertable, numberSeats, maxWeightLoad, and numberAxels.
Characteristics that are applicable to all vehicles should be instance variables in the Vehicle class. The others should be in the class(s) where they belong.
Class vehicle should have constructor that initializes all its data. Classes Car, Bus, and Truck will have constructors which will reuse their parents constructor and provide additional code for initializing their specific data.
Class Vehicle should have toString method that returns string representtion of all vehicle data. Classes Car, Bus, and Truck will override inherited toString method from class vehicle in order to provide appropriate string representation of all data for their classes which includes inherited data from Vehicle class and their own data.
Class Tester will instantiate 1-2 objects from those four classes (at least five total) and it will display the information about those objects by invoking their toString methods.
Submit one word document with code for all five classes, picture of program run from blueJ, and picture of UML diagram.
Vehicle.java * A class that represents a vehicle. It is a superclass of all of the * other classes that represent vehicles (Automobile, Motorcycle, Truck, * and their subclasses). * * Fields and methods that all vehicles have in common are defined * here so that they can be inherited by the subclasses of this class. */ public class Vehicle { private String make; private String model; private int year; private int numWheels; private int mileage; private String plateNumber; /** * a constructor that takes the make, model, year, and number of wheels */ public Vehicle(String make, String model, int year, int numWheels) { this.make = make; this.model = model; if (year < 1900) { throw new IllegalArgumentException(); } this.year = year; this.numWheels = numWheels; this.mileage = 0; this.plateNumber = "unknown"; } /*** basic accessors ***/ public String getMake() { return this.make; } public String getModel() { return this.model; } public int getYear() { return this.year; } public int getNumWheels() { return this.numWheels; } public int getMileage() { return this.mileage; } public String getPlateNumber() { return this.plateNumber; } /*** mutators ***/ public void setMileage(int newMileage) { if (newMileage < this.mileage) { throw new IllegalArgumentException(); } this.mileage = newMileage; } public void setPlateNumber(String plate) { this.plateNumber = plate; } public String toString() { String str = this.make + " " + this.model; return str; } }
Get Answers For Free
Most questions answered within 1 hours.