Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java: Create a class called Car, a Car should include three pieces of information as instance variables: make (type String) initialized in the default

In Java: Create a class called Car, a Car should include three pieces of information as instance variables:

  • make (type String) initialized in the default constructor to none.
  • model (type String) initialized in the default constructor to none.
  • model year (type Int) initialized in the default constructor to 0.

The Car class should also include:

  • A default constructor that initializes the 3 instance variables to the values mentioned above.
  • Accessor (get) and mutator (set) for each instance variable.
  • A method named displayInfo that displays the make, model, and model year of the Car.

Create a class called ElectricCar that inherits from the Car class, an ElectricCar should include the following two additional pieces of information as instance variables:

  • attery size (type Int) initialized in the default constructor to 0.
  • miles per charge (type Int) initialized in the default constructor to 0.

The ElectricCar class should also include:

  • A default constructor that initializes the 2 instance variables to the values mentioned above.
  • Accessor (get) and mutator (set) for each instance variable.
  • A method named displayInfo that overrides the Cars displayInfo method and in addition to displaying the make, model, and model year of the Electric Car, it displays the battery size and miles per charge.

Create a tester class called CarTester that will test the Car and ElectricCar classes. The tester class should do the following:

  • Create a Car object using the default constructor.
  • Call the displayInfo method.
  • Prompt the user for the make, model, and model year.
  • Use the set methods to set the make, model, and model year of the Car object.
  • Use the get methods to display the make, model, and model year of the Car object.
  • Create an ElectricCar object using the default constructor.
  • Call the displayInfo method.
  • Prompt the user for the make, model, model year, battery size and miles per charge.
  • Use the set methods to set the make, model, model year, battery size and miles per charge of the ElectricCar object.
  • Use the get methods to display make, model, model year, battery size and miles per charge of the ElectricCar object.

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_2

Step: 3

blur-text-image_3

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

Where are most of these attributes located?

Answered: 1 week ago