Question: Write the complete code for the class Truck as given in the class diagram below. Be sure to not use duplicate code in the constructors.

Write the complete code for the class Truck as given in the class diagram below. Be sure to not use duplicate code in the constructors. For example, the constructors with 2 arguments should call the one with 1 argument to set the value for cylinder. Use the provided file TruckTester.java to test your class.

Truck - cylinders:int - manufacturer:String - load:double - tow:double + Truck() + Truck(int cylinders) + Truck(int cylinders, String manufacturer) + Truck(int cylinders, String manufacturer, double load) + Truck(int cylinders, String manufacturer, double load, double tow) + printTruckInfo():void + getCylinders():int + setCylinders(int cylinders):void + getManufacturer():String + setManufacturer(String manufacturer):void + getLoad():double + setLoad(double load):void + getTow():double + setTow(double tow):void printTruckInfo method Write a method to print the contents of the variables in the Truck class to produce output in the following format: cylinders = 6 manufacturer = Ford load = 1000.0 tow = 13000.0

Truck Tester is given and it looks like this:

public class TruckTester

{

public static void main(String[] args)

{

//Call the default constructor

Truck truck1 = new Truck();

truck1.printTruckInfo();

//Call constructor with 1 argument

Truck truck2 = new Truck(6);

truck2.printTruckInfo();

//Call constructor with 2 arguments

Truck truck3 = new Truck(6, "Ford");

truck3.printTruckInfo();

//Call constructor with 3 arguments

Truck truck4 = new Truck(6, "Ford", 1000);

truck4.printTruckInfo();

//Call constructor with 4 arguments

Truck truck5 = new Truck(6, "Ford", 1000, 13000);

truck5.printTruckInfo();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!