Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add a new instance variable with a feature to class KoenigseggOne and change the parent class and test class accordingly. (java) Class KoenigseggOne: class KoenigseggOne

Add a new instance variable with a feature to class KoenigseggOne and change the parent class and test class accordingly. (java)

Class KoenigseggOne:

class KoenigseggOne extends Car { private String mileage;

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

Step: 3

blur-text-image_3

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

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

Explain the different types of marketing strategies.

Answered: 1 week ago

Question

Explain product positioning.

Answered: 1 week ago

Question

Explain Industrial market segment.

Answered: 1 week ago