Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Body - width height : double - seats int cost double + Body(width : double, height : double, seats: int, cost : double) + set
Body - width height : double - seats int cost double + Body(width : double, height : double, seats: int, cost : double) + set Width(width : double): void + getWidthO: double + setHeight(height : double): void + getHeight0 double setSeats(seats : int) : void + getSeats0: int + setCost(cost: double): void + getCostO: double + toStringO: String In this problem, you should use inheritance to create a car and a train. The Vehicle class is made up of an Engine and a Body and some other variables. It has setter and getter methods and a method called calculateTotalPrice which should be implemented by subclasses of Vehicle. The Car class and the Train class are both subclasses of Vehicle. This means that you have to use inheritance to create both classes. Each of these classes' constructors must call the superclass constructor. Moreover, both of these classes have to implement the calculateTotalPrice method which has to sum up the total price of the vehicle plus the compartments' price if it is a train or the gear price if it is a car Write a tester class which has an array of Vehicles. The array should contain two cars and two trains. Printing format is as follows: (manufacturer) (name) ne: (id) S(cost) Body: (width)x(height)M (seats) seats (compartments) compartments (if train) (doors) doors (if car) Price S(calculateTotalPrice0) Problem 2: Vehicle - manufacturer : String -name String engine : Engine Bod - profit: double + Vehicle(manufacturer String, name : String, engine : Engine, body : Body, profit : double) + setManufacturer(manufacturer String): void + getManufactuer String + setName(name : String): void + getName0 : String + setEngine(engine: Engine): void +getEngine0 : Engine + setBody(body: Body): void + getBody0 body + setProfit(profit : double) void + getProfit0 double # abstract calculateTata!Price() : double + toString0 : String Car 6oors. gringuble gear: String - gearPrice: double + Car(manufacturer : String, name : String, engine Engine, body : Body, profit : double, doors : int, gear : String, gearPrice : double) + setDoors(doors: int): void + getDoors: int + setGear(gear: String) void + getGearO : String + setGearPrice(gearPrice : double) void + getGearPrice0 double + calculateTotalPrice): double + toStringO: String Train - compartments: int - fuel: String rtmentPrice double + Train manufacturer : Stricw, name String, engine: Engine, body : Body, profit double, compartments: int, fuel: String, compartmentPrice double) + setCompartments (compartments: int): void getCompart ments() : int + setFuel(fuel : String): void + getFuel0: String + setCompartmentPrice(compartmentPrice : double):void + getCompartmentPrice 0 : double + calculateTotalPrice): double + toStringO: String Engine id: String - cost: double + Engine id: String, cost : double) + setld(id: String) : void + getld0 : String + setCost(cost: double): void + getCost0: double + toString0: String
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started