Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could someone please help me with this assignment? In this assignment, you will create five classes, some of which are subclasses, and one of which

Could someone please help me with this assignment?

In this assignment, you will create five classes, some of which are subclasses, and one of which is abstract. The goal is to gain practice with the benefits and complexities of inheritance. What you need to do: (1) Create five classes: Vehicle, an abstract class Car, a subclass of vehicle Bicycle, a subclass of vehicle Limo, a subclass of Car MotionWorld, which will have the main() method and utilize each of the classes (2) For the abstract Vehicle class, you should make sure it has: An instance variable called "name" (of type String) A non-abstract method called getName(), which returns the name A constructor which takes the name as a String parameter and sets the name Three abstract methods o getVehicleType(), which returns a String o hasEngine(), which returns a boolean o numWheels(), which returns an integer A method called toString(), which overrides the default toString() and must contain the following code: public String toString() { return "Name: " + getName()+ ", Type: "+getVehicleType() + ", Engine: " + hasEngine() + ", Wheels: " + numWheels(); } (3) For the Car, Limo, and Bicycle class: A constructor that takes a name as a String and uses its superclass constructor Use the following info when implementing methods in each: o Car: It has 4 wheels and an engine o Limo: It has 6 wheels and an engine o Bicycle: it has 2 wheels and no engine (4) The Limo class should be a subclass of Car. Only implement what you need to (i.e., what is truly different about a Limo vs. a Car). (5) You should have one additional class, called MotionWorld, which is the main driver for the program. Use the following code for MotionWorld. public class MotionWorld { public static void main(String[] args) { Car c = new Car("Carla"); Limo l = new Limo("Larry"); Bicycle b = new Bicycle("Bianca"); System.out.println(c); System.out.println(l); System.out.println(b); } } when this class is run, it should produce: Name: Carla, Type: Car, Engine: true, Wheels: 4 Name: Larry, Type: Limo, Engine: true, Wheels: 6 Name: Bianca, Type: Bicycle, Engine: false, Wheels: 2

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

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions