Question: Need some help with a Java program. Write a class called Car that has a static field name VINnumber that stores the car ID number

Need some help with a Java program.

Write a class called Car that has a static field name VINnumber that stores the car ID number (The first car we create will get the vin number 100000)...

Give your class these instance fields:

~carIdNumber - stores the cars unique ID number ~fuelLevel - stores the amount of gas the car's tank can hold in gallons ~maxFuelLevel - stores the amount of gas that can fit in the cars tank, in gallons ~odometerNumber - stores the value of the cars odometer from a single trip. ~maxFuelEfficiency - stores the fuel effciency whe nthe vehicle is traveling at a standard speed, in MPG(miles per gallon)

Add a constructor to your class that has two parameters. The first param contains the new cars max fuel level, and the second one contains the cars max fuel efficiency. A new car always has an odometer reading of 0 and a full fuel tank. It should also assign the car the next available id number.(Hence first call is 100000, second call would be 100001 etc etc.)..... Make sure both parameters are positive for the constructor and if the max fuel level param is not a positive number, it should print out a warning message and should just set the value to 14.0 gallons instead of the invalid parameter. If the max fuel effciency param is nt positive, it should also give a warning message and set the parameter to 25.0.

-Next create an accessors(basic getters) for three of your fields... (cardIdNumber, fuelLevel, and odometerReading)

-After that, create a method called resetOdometer that doesnt have parameters and no return value, it just resets the Odometer back to 0.0 miles.

-Create another method named refuel has a parameter for the amount of gas added to the tank, and no return value. This method should do the following: 1. If the amount of gas to add is not positive, print a warning message and just set it to 10.0 gallons instead of the invalid parameter. 2. update the current fuel level 3. If the fuel level is above the max fuel level, set the value to the max level and print a warning say "gas tank overflow"

-Create another method called getEffectiveEffciency that has one parameter(which is speed in miles per hour) and returns a floating point number. The purpose of this method is to compute and return the efficiency of the vehicle given the speed with the following... below 25 is 50% effective fuel efficiency(EFF).. at least 25 to 45 is 80% max EFF... at least 45 to 65 is 100% max EFF. At least 65 to 85 is 80% max EFF. and at least 85 is 50% max EFF.

-Create one last method called 'drive' that has two parameters, one for the amount of time(in minutes) and speed(in miles per hour) and it doesnt have a return value... This method does the following in this order: 1. If the time parameter is not positive, give a warning message and set it to 60.0 instead of the parameter. 2. If the speed param is not positive, give a warning message and set it to 55.0 instead of the parameter. 3. Compute the distance that would be traveled during the drive. 4. Call the getEffectiveEffciency method to get the fuel effeciency at the specific speed. 5. Compute the amount of fuel that would be used during the drive. 6. If the car does not have enough fuel to make the trip, give a warning message about not having enough gas. 7. Otherwise, update the odometer and fuel level.

-Lastly, create a Main class for your program that tests our created methods above. Since java can't store floating point number exactly and will give calculations slighly off, we are going to create a hlper method for main. Create a private staic method named approxEqual with two parameters, both being doubles and it should return a boolean. If the difference between the two parameters is less than 0.0000001, it should return true, otherwise return false.(the parameters are not approximately equal).

Create the main method in here to test our Car class. It should do the following:

1. Create a new Car instance with a tank that holds 15.0 gallons of fuel and a maximum fuel eciency of 20.0 miles per gallon

2. Call the three accessor methods, and print an error message if what they returned does not match what you believe they should have returned.

3. Drive the Car for 120 minutes at 20 miles per hour.

4. Call the three accessor methods, and print an error message if what they returned doesnt match what you believe they should have returned. the total distance traveled should be 20 miles per hour * 120 minutes / 60 minutes per hour = 40 miles, that the effective fuel effciency should be 50% * 20 miles per gallon = 10 miles per gallon, and that the fuel used should be 40 miles / 10 miles per gallon = 4 gallons. Thus, I would expect the new odometer reading to be 0 + 40 = 40 miles, and the new fuel level to be 15 - 4 = 11 gallons.

5. Reset the odometer, then call the three accessor methods and print an error message if what they returned does not match what you expect them to return.

6. Refuel the Car with 3.5 gallons of gasoline, then call the three accessor methods and print an error message if what they returned does not match what you expect them to return.

7. Drive the Car for some amount of time at a moderate speed, determine what you believe the odometer reading and fuel level should be, using calculations similar to the ones above, and print an error message if the accessors do not return the expected values.

8. Create a second Car instance, then call all the accessors on both and print an error message if any return the wrong value.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!