Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with this Java project please: Create a class for a car. This class should hold the minimum following data items: Create a constant

Need help with this Java project please:

  1. Create a class for a car. This class should hold the minimum following data items:
  • Create a constant called maxCapacity and set to 16; (represents gas capacity max)
  • cost (cost of the car)
  • numSeats (2 or 4, default is 2)
  • engineSize (4, 6, or 8 cylinders, default is 4)
  • model (string)
  • year (integer)
  • currentGas (between 0 and maxCapacity)
  • color (string).

Add the following:

  1. Add 4 more additional properties (choose intelligent ones please...)
  2. 4 constructors (your choice, but include a no-arg one)
  3. Create the following methods as members of the class (member methods):
    1. 4 get methods (your choice, but 1 should be a getcurrentGas and another should be getmaxCapacity)
    2. 4 set methods (again, your choice but at least 2 of your set modules should have some error checking it in)
  4. A utility method print (have it print out the model, year, and color as a minimum)
  5. Create a static variable called count for this class. Have the constructors bump the counter each time a car is created. . Create also a static function called getCount which will print out the number of cars currently created. ** Do a little internet research on Javas finalize method, and then write a SIMPLE finalize method that just decrements count

NOTES:

* use private visibility modifiers, make only appropriate behaviors/properties static

* Default values used in constuctors or sets if correct value isnt given (or none given)

  1. Research a bit on chaining of constructors: re-write (or write) 2 constructors for your above class that are chained to another.

  1. Create (just write the method, dont re-write the class) a utility method (a function) called CalcDistance. It will take in a value (which represents miles per gallon) and using the member property currentGas, will return the distance the car can travel. Once this is done, consider if this member method should be static or not. Give a brief (2 or 3 sentences) on your decision and why.

  1. Create (just write the method, dont re-write the class) a utility method called CalcFillCost. It will take in a value (representing cost per gallon of gas), and return how much it will cost to fill up the car based on the instantiated objects current capacity and maximum.

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

Microsoft Office 365 For Beginners 2022 8 In 1

Authors: James Holler

1st Edition

B0B2WRC1RX, 979-8833565759

More Books

Students also viewed these Databases questions

Question

Explain what is meant by the terms unitarism and pluralism.

Answered: 1 week ago