Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implement a simple speed detection system for police to monitor drivers on the highway. This system comprised three classes: Police, Driver, and Car. Exception handling
Implement a simple speed detection system for police to monitor drivers on the highway. This system comprised three classes: Police, Driver, and Car. Exception handling is required.
Class Police:
One private attribute: policeNamestring
One parameterized constructor that assigns the parameter value to policeName attribute.
The detectSpeed method takes two parameters: Driver and Car objects. This method determines if the driver overspeeding, underspeeding, or driving an ambulance. It does not return a value.
Prototypes:
Police;
Policestring;
void setPoliceNameString;
static void detectSpeedDriver Car;
Class Car:
Two private attributes: speedint and carTypestring representing TruckPassenger or Ambulance
Twoparameterized constructor for initializing: speed and carType
Getter and setter methods for speed and carType attributes.
Prototypes:
Carint string;
void setSpeedint;
int getSpeed;
void setCarTypestring;
string getCarType;
Class Driver:
One private attribute: driver name string
Method driveCarCar
Throws "EmergencyException" if the car is an ambulance.
Throws "OverSpeedException" if the car's speed is over mph
Throws "UnderSpeedException" if the speed is lower than mph
Create three exception classes in a single file.
OverSpeedException
UnderSpeedException
EmergencyException
Each exception class must override the what method to display a specific message.
Prototype:
Driver;
void setDriverNamestring;
void driveCarCar;
The main function:
Create instances of Car and Driver.
Set up a Police object.
The Police object detects the speed when the driver drives their car on the road.
Test the program.
Rubrics
pt Create Exception Handler classes.
pts Implement a Police class.
pts Implement a Driver class.
pt Implement a Car class.
pts Ensure correct throwing and catching of exceptions.
pt Create a main function to test the program.
Sample outputs:
What is the cars type? Passenger
What is the cars speed?
The driver is over the speed limit
What is the cars type? Truck
What is the cars speed?
The driver is a good citizen!
What is the cars type? Passenger
What is the cars speed?
The driver is going to slow!!
What is the cars type? Ambulance
What is the cars speed?
The driver is in an Emergency Vehicle!
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