Answered step by step
Verified Expert Solution
Link Copied!

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: policeName(string)
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();
Police(string);
void setPoliceName(String);
static void detectSpeed(Driver, Car);
Class Car:
Two private attributes: speed(int) and carType(string), representing Truck,Passenger, or Ambulance
Two-parameterized constructor for initializing: speed and carType
Getter and setter methods for speed and carType attributes.
Prototypes:
Car(int, string);
void setSpeed(int);
int getSpeed();
void setCarType(string);
string getCarType();
Class Driver:
One private attribute: driver name (string)
Method driveCar(Car)
Throws "EmergencyException" if the car is an ambulance.
Throws "OverSpeedException" if the car's speed is over 80 mph.
Throws "UnderSpeedException" if the speed is lower than 50 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 setDriverName(string);
void driveCar(Car);
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
(1 pt) Create Exception Handler classes.
(4 pts) Implement a Police class.
(4 pts) Implement a Driver class.
(1 pt) Implement a Car class.
(4 pts) Ensure correct throwing and catching of exceptions.
(1 pt) Create a main function to test the program.
Sample outputs:
What is the cars type? Passenger
What is the cars speed? 100
The driver is over the speed limit!!
What is the cars type? Truck
What is the cars speed? 75
The driver is a good citizen!
What is the cars type? Passenger
What is the cars speed? 30
The driver is going to slow!!
What is the cars type? Ambulance
What is the cars speed? 200
The driver is in an Emergency Vehicle!

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago