Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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());

} }

Implement the classes that are given in the class diagram. Also implement a Test class where you will create three objects and execute their toString() methods > G Vehicle assignment year: int weight double Vehicle Vehicle(int, double) o getYearO:int o setyear(int)void o getWeight0):double o setWeight(double):void toString0:String > C Automobile > C Tank licensePlate. String a make: String a armorWidth: double Automobile(0 Tank0) Automobile(int,double,String,String) o getLicensePlate():String o setLicensePlate(String)void o getMake():String o setMake(String):void o toString):String Tank(nt,double,double) o getArmorwidthO double o setArmorWidth(double):void o toString0:String OTruck assignment2 C Car assignment2 towCapa city: double Truck) Truck int,double, String,String,double) a maxPassengers: int Car() Car(int,double,String,String,int) o getTowCapacity):double o setTowCapacity(double):void o toString():String o getlMaxPassengersOint o setMaxPassengers(int) void toString):String Sample output Honda: Year 2006 weight: 2100.56 License Plate: 1RT245 Make: Honda MaxPassengers: 5 Dodge: Year 2009 weight: 2500.45 License Plate: 2tu123 Make: Dodge Tow Capacity: 1200.0 Tank: Year: 2011 weight: 7000.56 Armor Width: 4.56 There are two things to pay special attention to Each class has two constructors. Default constructor sets the field values to default values such as unknown for license plate or 2000 for weight Each toString method overrides its superclass implementation by adding more data about the object

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions