Answered step by step
Verified Expert Solution
Question
1 Approved Answer
codehs 9 . 6 . 7 cars errors ( below are instructions, my code, and errors ) please help fix it ! : ( In
codehs cars errors below are instructions, my code, and errors please help fix it: In this exercise, we are going to revist our Car and ElectricCar class from lesson In lesson you were given the Car class and needed to complete the ElectricCar class. You can use your code from that exercise to get started here. The focus of this exercise is the CarTester class. In this class, create an ArrayList that can hold Cars and ElectricCars. Then, you will prompt the user for a car model. Ask for either the remaining battery percentage or the amount of fuel left, depending on whether the car is electric. Add each car to the ArrayList. You will continue asking the user until they exit, then you will loop through your ArrayList and print the results. Remember, for a method call to compile, it needs to be defined in the reference type the Car class in this exercise but the actual method that executes will be based on the instantiated class. In this exercise, we want electric cars to run the Override methods. Sample Output Enter your cars' information: Model exit to quit: Leaf Electric car y n: y Percent of battery left as a whole number: Model exit to quit: Tank Electric car y n: n Gallons of fuel left: Model exit to quit: exit Leaf electric car Fuel Amount: Tank car Fuel Amount: private String model; public ElectricCarString model this.model model; Override the getMPG here It should return: "Electric cars do not calculate MPG public String getMPG return "Electric cars do not calculate MPG; Override the toString here. @verride model is an electric car. public String toString return super.getModel is an electric car."; Carspublic class Car This code is complete private String model; private int fuelLevel; public CarString model, int fuelLeft this. model model; this. fuelLevel fuelLeft; public String getModel return model; public double getFuelLevel return fuelLevel; Returns how many more miles the car can go with the fuel left public double milesLeftdouble mpg return fuelLevel mpg; public String toString return model car";
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