Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

codehs 9 . 6 . 7 cars errors ( below are instructions, my code, and errors ) please help fix it ! : ( In

codehs 9.6.7 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 3. In lesson 3, 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): 57 Model (exit to quit): Tank Electric car (y / n): n Gallons of fuel left: 80 Model (exit to quit): exit Leaf electric car Fuel Amount: 0.57 Tank car Fuel Amount: 80.6private String model; public ElectricCar(String 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. @0verride //(model) is an electric car. - public String toString(){ return super.getModel()+" is an electric car.";9.6.7 Carspublic class Car {// This code is complete private String model; private int fuelLevel; public Car(String 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 milesLeft(double mpg){ return fuelLevel * mpg; public String toString() return model +" car"; }

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

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions