Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

class PaganiHuayra:

class PaganiHuayra extends Car { private String mileage;

public PaganiHuayra(double mileage) { super(false, "2"); this.mileage = mileage + " miles/km"; System.out.println("A PaganiHuayra 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

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

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

=+1. Describe the value chain of the media industry!

Answered: 1 week ago