Question: Instructions Using your Vehicle.java, Car.java and Truck.java classes from Chapter 2 assignment create a new main method. In the main method, create an ArrayList of




Instructions Using your Vehicle.java, Car.java and Truck.java classes from Chapter 2 assignment create a new main method. In the main method, create an ArrayList of Vehicle objects. Prompt the user for the attributes of 2 Car objects and 2 Truck objects that you will create and add to the ArrayList. After the ArrayList is complete, use a for loop or enhanced for-loop to print the toString() method of each object in the ArrayList individually. Do not simply print the ArrayList. public class Truck extends vehicle { // unique attributes of Truck private int numDoors; private double cargoCapacity; // create constructor public Truck(double horsepower, int numberofwheels, int numDoors, double cargocapacity) { super(horsepower, number of wheels); this.numDoors = numDoors; this.cargocapacity = cargocapacity; } /** * getter method for numDoors * @return int */ public int getNumDoors() return numDoors; } /** * setter method for numDoors @param number of doors */ public void setNumDoors(int numDoors) { if (numDoors
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
