Question: Add a new instance variable with a featureto class FerrariLaferrari and change the parent class and test class accordingly. (java) class ferrarilaferrari: class FerrariLaferrari extends

Add a new instance variable with a featureto class FerrariLaferrari and change the parent class and test class accordingly. (java)

class ferrarilaferrari:

class FerrariLaferrari extends Car { private String mileage;

public FerrariLaferrari(double mileage) { super(false, "2"); this.mileage = mileage + " miles/km"; System.out.println("A FerrariLaferrari is a sedan =" + getIsSedan() + " .It has " + getSeats() + ", seats, and the mileage/kilometers (whatever you chose) is=" + getMileage()); }

public String getMileage() { return this.mileage; } }

Parent Class:

abstract class Car { protected Boolean isSedan; protected String seats;

public Car(Boolean isSedan, String seats) { this.isSedan = isSedan; this.seats = seats; }

public Boolean getIsSedan() { return this.isSedan; }

public String getSeats() { return this.seats; }

public abstract String getMileage(); }

Test Class:

public class CarInheritance { public static void main(String[] args) { Scanner input = new Scanner(System.in); boolean notFinished = false; do { CarFactory carFactory = new CarFactory(); Scanner scanner = new Scanner(System.in); System.out.println("For Ferrari Laferrari type 0. For Pagani Huayra type 1. For Koenisgsegg One type 2. For BMW M3 type 3."); int type = scanner.nextInt(); System.out.println("Type your cars mileage"); double mileage = scanner.nextInt(); System.out.println("If you want your miles to be converted to kilometers type 1. If not, press any other number."); double kmh = scanner.nextInt(); if (kmh == 1) { CarFactoryKMH.getCarKMH(type, mileage); } else { CarFactory.getCar(type, mileage); } System.out.print("Do you want to run the program again [Y/N]?"); String repeat = input.nextLine(); notFinished = (repeat.equals("Y")) || (repeat.equals("y")); System.out.println(); } while (notFinished); } }

Car Factory and Car Factory KMH classes (if needed to reference/modify)

class CarFactory { public static Car getCar(int type, double mileage) { if (type == 0) { return new FerrariLaferrari(mileage); } else if (type == 1) { return new PaganiHuayra(mileage); } else if (type == 2) { return new KoenigseggOne(mileage); } else if (type == 3) { return new BmwM3(mileage); } return null; } }

class CarFactoryKMH extends CarFactory {

public static Car getCarKMH(int type, double mileage) { return getCar(type, mileage * 1.6); } }

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!