Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are modelling the different vehicles operated by the public transportation agency of your home city. Design a class named Vehicle and its two subclasses

image text in transcribedimage text in transcribed
You are modelling the different vehicles operated by the public transportation agency of your home city. Design a class named Vehicle and its two subclasses named RailVehicle and BusVehicle. A Vehicle has a unique ID. Make TrainCar and MetroCar subclasses of RailVehicle, given the information that train cars are arranged in a chain to form a single train on which only certain cars have a driver, whereas metro cars are typically one long driverless vehicle driven by a computer system. Define relevant attributes for the BusVehicle class, identifying characteristics of buses that rail vehicles do not have (if you are not sure, ask a friend or read about Buses). Override the toString method in each class, and write a test program to display the exact output as follows: TEXT 1 This is a Vehicle, with unique ID = E7BC This is a Vehicle, with unique ID = BB77 3 This is a RailVehicle, with unique ID = 120B This is a TrainCar, in chain 721X5, with no driver 5 This is a TrainCar, in chain 721X5, with no driver 6 This is a TrainCar, in chain 721X5, with driver 7 This is a MetroCar, automated under route plan 470 8 This is a MetroCar, automated under route plan 47R 9 This is a BusVehicle, with unique ID = 12AA If you have completed this question, go back to your code and think about how you could make use of the concept of polymorphism in this question. Try coding it and discuss with your tutor your approach.+ A Vehicle.java . RailVehicle.java BusVehicle.java TrainCar.java MetroCar.java . Exercise1.java 1 public class Exercisel { 2 / / This is just for your testing - we will run your classes against our own tests 3 / / Make sure you have the correct toString for all classes 4 public static void main (String args) { 5 6 ArrayList vehicles = new ArrayList( ) ; 7 vehicles . add (new Vehicle() ) ; 8 LD / / continue here. .. 10 11 12 }

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions