CarInheritanceMain.java CarInheritanceMain.java /*CarInheritanceMain.java * Driver program to test the Car class hierarchy. */ public class CarInheritanceMain {...

Need help with programming


CarInheritanceMain.java CarInheritanceMain.java /*CarInheritanceMain.java  * Driver program to test the Car class hierarchy.  */ public class CarInheritanceMain {     public static void main(String[] args) {         //declare an instance of a Car using the default constructor called car1 (2)                  //declare an instance of a Car using the parameter constructor called car2 (2)                  //declare an instance of a Minivan using the default constructor called car3 (2)                  //declare an instance of a Minivan using the parameter constructor called car4 (2)                  //declare an array of type Car, size 4, called carArray (2)                  //assign the four above cars to the array (4)                  //use a for loop and polymorphism to display each Car (6)                  //use a single method to display the make, model and number of passengers for car3 (4)                  //Use a method to add 10000 miles to car4 (4)                   //Display whether or not car3 needs to be washed (4)                  //Change the information of car3 to the following: (4)         /*          * Make: Dodge          * Model: Caravan          * Year: 2014          * Price: 34000          * Number of Passengers: 7          * Clean: No          */                           //Display the make and model of car3 as follows: (4)          //Dodge Caravan                                                  } } COP2251C Quiz 2 - Inheritance.pdf COP 2251C Quiz 2 100 points Inheritance a) (50 pts) Using inheritance, derive a class named Minivan, from the Car class. For this quiz, a MiniVan object has all the attributes of a Car plus the following: • (2 points) a private numPassengers attribute (an int indicating the maximum number of passengers the car can hold) • (2 points) a private isClean attribute (a boolean value indicating whether or not the minivan is clean) • (7 points) A public default constructor that initializes the numPassengers attribute to 8, the isClean attribute to true and all other data members as defined in the Car class. • (7 points) A public overloaded parameter constructor that allows the user to initialize all 7 attributes of a Minivan with whatever data is passed to the method. • (8 points) A public boolean returning method called needsWash that returns true if the Minivan is dirty and false if it is clean. • (8 points) A public overloaded void member method, named setCarInfo, which has 6 parameters. This method calls the base class setCarInfo method and additionally contains two parameters to set the number of passengers and whether or not the car is clean. • (8 points) An overridden toString() method. The output for a MiniVan should be as follows: (example data) Make: Honda Model: Odyssey Year: 2013 Price: $32000 Mileage: 23000 Number of Passengers: 8 Clean: No • (8 points) A void member method called displayMiniVan that displays the make, model and number of passengers of a Minivan as follows: Make and Model: Honda Odyssey Number of Passengers: 8 Note: To receive full credit you must use the syntax covered in class to call the super class constructors and methods whenever possible. You should not have redundant code. b) (40 pts) Fill in the missing code in CarInheritanceMain.cpp. c) (10 pts) Create a UML diagram to represent the Car Hierarchy. Car.java Car.java /*Car superclass  * March 25, 2020  */ public class Car {         private int year;         private double price, mileage;         private String make, model;                  //default constructor         public Car()         {             setMake("Honda");             setModel("Accord");             setYear(2017);             setPrice(30000);             mileage = 0;         }                  //parameter constructor         public Car(String mak, String mod, int yr, double pr, double mil)         {                setMake(mak);             setModel(mod);             setYear(yr);             setPrice(pr);             mileage = mil;         }                  //getter and setter methods         public String getMake() {             return make;         }         public void setMake(String make) {             this.make = make;         }         public String getModel() {             return model;         }         public void setModel(String model) {             this.model = model;         }         public int getYear() {             return year;         }         public void setYear(int year) {             this.year = year;         }         public double getPrice() {             return price;         }         public void setPrice(double price) {             this.price = price;         }         public double getMileage() {             return mileage;         }         //additional methods         public void driveCar(double mil)         {             this.mileage += mil;         }                  public void setCarInfo(String mak, String mod, int yr, double pr)         {             setMake(mak);             setModel(mod);             setYear(yr);             setPrice(pr);         }         //override the toString() method         public String toString()         {             return "Make: " + this.make + "\nModel: " + this.model + "\nYear: " + this.year;         }               }
Mar 28, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here