Question: I wrote these 3 classes - public class Car { // This code is complete public String model; public double fuelLevel; public Car(String model, double
I wrote these 3 classes - public class Car { // This code is complete public String model; public double fuelLevel; public Car(String model, double 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"; } } ######################### public class ElectricCar extends Car { // Complete the constructor // Note we're reinterpreting "fuelLevel" as "batteryLevel" public ElectricCar(String model, double batteryLevel){ super(model,batteryLevel); } // Override getFuelLevel // Reinterprets fuelLevel() as a percentage // Remember super.getFuelLevel will return fuelLevel! public double getFuelLevel(){ return fuelLevel/100; } // Override milesLeft // Takes one parameter - the total number of miles an ElectricCar // gets on a full charge. // Computes miles left by interpreting fuelLevel as the // battery percentage left in the car public double milesLeft(double mpg){ return (fuelLevel/100) * mpg; } // Override toString // Should print: model electric car public String toString(){ return model + " electric car"; } } ####################### import java.util.ArrayList; import java.util.Scanner; public class CarTester { public static void main(String[] args) { ArrayList carList = new ArrayList(); boolean repeat = true; Scanner scanner = new Scanner(System.in); Car car = null; ElectricCar electricCar = null; System.out.println("Enter your car's information: "); while (repeat) { System.out.println("Model (exit to quit): "); String model = scanner.next(); if (!model.equals("exit")) { System.out.println("Electric car (y/n): "); //String carType = scanner.next(); String carType = scanner.next(); double batteryFuel; if (carType.equals("y")) { System.out.println("Percent of battery left (as a whole number): "); batteryFuel = scanner.nextDouble(); electricCar = new ElectricCar(model, batteryFuel); carList.add(electricCar); }else{ System.out.println("Gallons of fuel left: "); batteryFuel = scanner.nextDouble(); car = new Car(model, batteryFuel); carList.add(car); } } // if (!model.equals("exit")) { else { repeat = false; scanner.close(); } } // end of while loop for(Car car1: carList) { System.out.println(car1); System.out.println("Fuel Amount: " + car1.getFuelLevel()); System.out.println(""); } } } Getting below error. please help. Testing 2 Electrics then a Gas Great! ERROR Testing your input It looks like there is a problem with your prompts. Make sure your prompts match the example
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
