Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Cars (25 points) Implement a class car, which contains the fields e.g. Ford, Subaru, Toyota * make, e model, e.g., Escape, Outback, Camry e vear
Cars (25 points) Implement a class car, which contains the fields e.g. Ford, Subaru, Toyota * make, e model, e.g., Escape, Outback, Camry e vear * MPG miles per gallon * milesDriven, the total number of miles ever driven in this car. fuelcapacity in gallons, i.e., the size in gallons of the fuel tank * fuelRemaining, which represents the amount of fuel remaining in the gas tank. Implement at least the following methods within the car class * a constructor, which initializes each of the fields * fillTank (double g), which adds up to g gallons of gas to the fuel tank, but not more than the car's fuel capacity * drive (double m), which simulates driving m miles in the car, adding to the total number of miles driven, and reducing the amount of gas in the car according to this car's average MPG * tostring( ), which returns a string representation of the car. . getFuelRemaining( ), which returns the amount of fuel left in the tank For example, we should be able to do something like the following // creates a new Car object: a 1972 Ford Pinto, which gets 17.2 MPG, has been driven 127,621 miles. It has a gas tank that can hold 12 gallons of gas, but it only has 8 gallons in it. Car oldJunker-new Car( "Ford", "Pinto", 1972, 17.5, 127621, 12, 8); oldJunker.drive(5); // drives the Pinto 5 miles oldJunker.fillTank(1); // put in a gallon of gas System.out.println(oldJunker.getFuelRemaining()) // prints the amount of fuel left System.out.println (oldJunker); // prints the attributes of the car to the screen Write a short driver program to test your Car class with a short array of Cars
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started