Question
I have problem with the test class, the output should looks like this my codes for each class : :Vehicle public class Vehicle { protected
I have problem with the test class, the output should looks like this
my codes for each class : :Vehicle public class Vehicle { protected int year; protected double weight; public Vehicle() { super(); } public Vehicle(int year, double weight) { this.year = year; this.weight = weight; } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public double getweight() { return weight; } public void setYear(double weight) { this.weight = weight; } public String toString() { return "Year:" + year + " Weight:" + weight + ""; } } TANK public class Tank extends Vehicle { protected double armorwidth; public Tank() { super(); } public Tank(int year, double weight , double armorwidth ) {super(year, weight); this.armorwidth = armorwidth; } public double getArmorWidth() { return armorwidth; } public void setarmorwidth(double armorwidth) { this.armorwidth = year; } public String toString() { return super.toString() + armorwidth; } } public class Automobile extends Vehicle { protected String licensePlate, make; Automobile public Automobile() { super(); } public Automobile(int year, double weight,String licensePlate , String make) { super(year, weight); this.licensePlate = licensePlate; this.make= make; } public String getLicensePlate() { return licensePlate; } public void setLicensePlate(String licensePlate) { this.licensePlate = licensePlate; } public String getMake() { return make; } public void setYear(String make) { this.make = make; } public String toString() { return super.toString() + licensePlate + make; } }
CAR
public class Car extends Automobile { protected int maxPassengers; public Car() { super(); } public Car(int year, double weight, String licensePlate, String make, int maxPassengers) { super(year, weight, licensePlate, make); this.maxPassengers = maxPassengers; } public int getMaxPassengers() { return maxPassengers; } public void setMaxPassengers(int maxPassengers) { this.maxPassengers = maxPassengers; } public String toString() { return "Honda: " +super.toString()+ " MaxPassengers:" +maxPassengers+ ""; } }
TRUCK
public class Truck extends Automobile { protected double towCapacity; public Truck() { super(); } public Truck(int year, double weight, String licensePlate, String make, double towCapacity) { super(year, weight, licensePlate, make); this.towCapacity = towCapacity; } public double getTowCapacity() { return towCapacity; } public void setTowCapacity(double towCapacity) { this.towCapacity = towCapacity; } public String toString() { return "Dodge: " +super.toString() + " Tow Capacity:" +towCapacity+ ""; } }
TESTCLASS public class TestVehicle { public static void main(String[] args){ Car C = new Car (); Truck T = new Truck (); Tank T1 = new Tank (); System.out.println(C.toString()); System.out.println(T.toString()); System.out.println(T1.toString()); } }
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started