Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java... Implement a class, called Car , with the following instance variables/fields and methods. Exact spelling is required for the name of the Car

In Java...

Implement a class, called Car, with the following instance variables/fields and methods. Exact spelling is required for the name of the Car class and the headers of all the methods within the Car class. Do not make any changes to the following requirements.

Class Fields/Instance Variables

Declare meaningful names with appropriate data types for each of these private instance variables:

  • String for the make of the car (e.g. Ford)
  • String for the model of the car (e.g. Explorer)
  • an integer for the year of the car
  • a double for the odometer
  • a double for the mileage of the next oil change
  • a double for the gallons of gas in the tank
  • a double for miles per gallon
  • a constant for the gas tank capacity

private static final double TANK_CAPACITY = 12.5;

  • a constant for the number of miles in between oil change.

private static final int MILES_BETWEEN_OIL_CHANGE = 5000;

  • an object of the DecimalFormat class to format the numbers (miles and gas)

private static DecimalFormat df = new DecimalFormat ("###,##0.00");

Constructors

  • public Car () this is the default constructor; it assigns the following initial values to the instance variables:
    • make: Ford
    • model: Explorer
    • year of the car: 2020
    • miles per gallon: 29.0
    • fills the tank
    • sets the odometer to zero
    • sets the next oil change reminder.
  • public Car (String make, String model, int y, double mpg) - this constructor sets the make, model, year and miles per gallon to the provided input parameters and sets the rest of the instance variables to the same values as the default constructor does.

Accessor Methods

  • public String getMake ( ) - return the make of the car.
  • public String getModel ( ) - return the model of the car.
  • public double getMpg ( ) - return the miles per gallon.
  • public int getYear ( ) - return the year of the car
  • public double getMileageNextOilChange ( ) - return mileage of next oil change
  • public double checkOdometer ( ) - return the current mileage.
  • public double checkGasGauge ( ) - return the amount of gas in the tank.

Mutator Methods

  • public void setMake (String make) set the make of the car to the value of the input parameter
  • public void setModel (String model) set the model of the car to the value of the input parameter
  • public void setMpg (double value) set the miles per gallon of the car to the value of the input parameter
  • public void setYear (int y) set the year of the car to the value of the input parameter
  • public void honkHorn ( ) - print a message more creative than "beep beep!"

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

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

=+ How would you advise those problems be resolved?

Answered: 1 week ago