Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**Language is Java** Unit 5-WS03 Method Overriding and Polymorphism Name: The goal of this assignment is to begin to build your set of dasses that

**Language is Java** image text in transcribed
Unit 5-WS03 Method Overriding and Polymorphism Name: The goal of this assignment is to begin to build your set of dasses that represents the following inheritance hierarchy: Vehicle Car Bike Problem #1 - Create 4 new classes, one called Vehicle, one called Car, one called Bike, and one called vehicle Main Problem #2 - Build the superclass Vehicle. It should have one instance variable speed that tracks the vehicle's speed and is set to zero when when a Vehicle object is created (referring to the constructor method). Problem #3 - Add three more methods to the vehide class using the following as a guideline: on ) - displays that the vehicle is running, off ) - displays that the vehicle is now off. getSpeed) ... returns the current vehicle speed. Problem #4 - Edit the Car class so that it inherits the Vehicle class and adds three more instance variables year (to track the year the car was made), make (who makes the car), and model (type of car). Problem #5 - The Car class should have a constructor method that retrieves the superclass instance variable(s) and requires three parameters fyear, make, and model) when constructing a car. Problem #16 - Add three more methods to the Car class using the following as a guideline: speedUp() .adds 8 to the speed of the car. slowDown() ... subtracts 11 from the speed ...do not allow negative speed. getVehicle)...prints vehicle year, make, model Problem #17 - Make the Bike class a subclass and give a a new instance variable type. The Bike constructor method should call the superclass instance variables) and should require a parameter to determine the type of the Bike object upon creation Problem #8 - Add 5 more methods to the Bike class: speedUp() .adds 3 to the speed of the bike. slow Down() subtracts 5 from the speed. getVehicle) - displays the type of bike. on() overrides superclass, displays bike ready off) - overrides superclass, displays not ready Problem #9 - Edit your classes so the vehicleMain code below yields the exact output shown after the code: public class vehicle Main public static void main(String[] args) { Vehicle this thing new Vehicle This thing on System.out.println("Speed is this thing.getSpeed mething off System.out.println(""); Cor cort-new Can 2014, "Toyoto","Carollo") carton System.out printSpeed is scarl getSpeed). forint) cort.speed Up System.out.println("Speed is corigetSpeedo cort slow Down.dk System.out.printinfort.getSpeed: cari.getVehicle cartoffe System.out.println(""); Skrbiket new Bile("Mountain bilond System.out.println("Spred is "bikelgetSpeed: bike speedUpl). bike speed Up bike slowdown System.out.println("Speed is "bike1.getSpeed: System.out.printin"type of bike bike.typek biel off Rideut The vehicle is now running Speeds: 0 The vehicle is now off. The vehicle is now running Speed is Speed is: 40 A 2014 Toyota Carola The vehicle is now off. Os the bike and ready to pedal Speeds: 0 Speed is: 1 Type of bike: Mountain Nobody is on the be, it can't go

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

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

Describe downsizing.

Answered: 1 week ago