Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a public class named Vehicle with fields: manufacturer of type String model of type String year of type int. The Vehicle class should have

Write a public class named Vehicle with fields:

manufacturer of type String

model of type String

year of type int.

The Vehicle class should have a constructor with parameters for each field. The constructor should set the value of each of its fields. The Vehicle class should have get and set methods for each field. The get and set methods should not call any other method. The Vehicle class should have a toString( ) method that returns a String containing the values of each of its fields. The toString( ) method should not call any other method. The Vehicle class should contain an abstract method named numberWheels( ) with return type int. The Vehicle class should not contain any additional fields or methods besides those listed in this paragraph. The Vehicle class should not implement any interfaces. The Vehicle class should not extend any other class.

Write a public interface named Measurable. The interface should contain a constant named mileageRate of type double initialized to 1.38. The interface should have one method named getMileage( ) with return type double. The Measurable interface should not contain any additional methods besides those listed in this paragraph.

Write a public class named Car. The Car class should be a child class of the Vehicle class. The Car class should have a field of type int named numberDoors. The Car class should have a constructor with parameters for each of its fields. The Car class constructor should set the values of each its fields. The Car class should have a toString( ) method that returns a String containing the values of each of its fields. The toString( ) method should not call any other method other than methods in the parent class. The class has get and set methods for each of its fields. The get and set methods should not call any other method. The Car class should implement the Measurable interface.

Write a public class named MotorCycle. The MotorCycle class should be a child class of the Vehicle class. The MotorCycle class should have a field of type int named engineDisplacement. The MotorCycle class should have a constructor with parameters for each of its fields. The MotorCycle class constructor should set the values of each of its fields. The MotorCycle class should have a toString( ) method that returns a String containing the values of each of its fields. The toString( ) method should not call any other method other than methods in the parent class. The class has get and set methods for each of its fields. The get and set methods should not call any other method. The MotorCycle class should implement the Measurable interface. The class should contain no other fields, constructors, or methods other than those listed in this paragraph.

Write a public class named TestVehicle with a main( ) method that creates a single array that contains two different anonymous Car objects and two different anonymous MotorCycle objects. Use a for loop to print the objects in the array, one per line. Inside the for loop, also call the numberWheels( ) and getMileage( ) method of each object and print the results to the screen. Your code should work correctly for any array containing Car and Motorcycle objects. The class should contain no other fields, constructors, or methods other than those listed in this paragraph.

I am getting an error for abstract, please help.

image text in transcribed

public class Vehicle private String manufacturer; private String model; private int year; public Vehicle(String manufacturer, String model, int year) \{ this.manufacturer = manufacturer; this.model = model; this.year = year; public String getManufacturer() \{ return manufacturer; public void setManufacturer(String manufacturer) \{ \} this.manufacturer = manufacturer; public String getModel() \{ -.-jGRASP wedge2: exit code for process is 1. -jGRASP: operation complete. -.-jGRASP exec: javac -g Vehicle.java Vehicle.java:1: error: Vehicle is not abstract and does not override abstract method numberWheels() in Vehicle public class Vehicle 1 error -.-jGRASP wedge2: exit code for process is 1. -.-jGRASP: operation complete

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

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

Students also viewed these Databases questions