The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Inheritance 1: Vehicle: A Vehicle class has been pre-coded in VPL. Within this class there are attributes, an integer noOfDoors representing the number of doors on a vehicle and a String brand representing the car’s brand. There is a Default and General Constructor along with relevant Getter and Setter Methods. This will act as a Parent Class from which you will inherit from with Car and SUV classes. Some methods and constructors are pre-coded for you and do not need to be changed. You should read through Vehicle.java and the pre-coded sections of each other class. a) In the car class: Make the Car class allow inheritance from Vehicle using a keyword. Create a Boolean attribute in Car called sportsModel that is true if the car is a sports model otherwise false. Write a default constructor for Car which should use the keyword super to invoke Vehicles constructor and sets sportsModel to false. Look at Vehicles General Constructor to see what the parameters are for correct use. A second constructor with an integer parameter, a String parameter and a boolean parameter. These parameters invoke Vehicles General Constructor and set sportsModel to the Boolean parameter. b) In the SUV class: Make the SUV class allow inheritance from Vehicle using a keyword. Write a default constructor for SUV that takes in an integer, and 2 Strings as parameters. wheelDrive should equal the 2nd String. wheelDrive represents whether the drive of SUV is “rear”, “front” or “4”. The other two parameters will be used for Vehicle’s constructor. Create getter and setter methods for wheelDrive with the signature getDrive() and setDrive(<…>). c) Create a tester class Tester which is a simple program with only a main method. Create a SUV object called suv1 using it’s default constructor. Create another SUV object using the general constructor, called suv2, with the values 2 for number of doors, “Nissan” for brand and “4” to represent 4-wheel-drive. Create a Car object called car1 with the values 3, “Ford” and true (to represent sports model). Use the relevant setter method to set suv1’s brand to “BMW”. Set the drive to “rear” and set noOfDoors to 5. Use Vehicle’s printDetails() method to print out suv1’s details and use getDrive() and a print statement to print suv1’s wheelDrive. See sample output. Set car1’s noOfDoors to 5. Use printDetails() on car1. Use a print statement and isSportsModel() to show whether car1 is a sportsModel. See sample output. Note: Notice how you are able to use Vehicle’s constructors as part of your more specific Car and SUV constructors. You are able to use Vehicle’s methods with the Car and SUV objects you created. Notice with the print statements in Vehicle’s constructors whether the general or default constructor is being invoked. Sample output: Default Constructor of the Super class called General Constructor of Vehicle called General Constructor of Vehicle called 5 BMW rear 5 Ford false
Attachments:
-----------