Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions