Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A Simple Ride - Sharing System Let's consider a two - dimensional city where positions are defined using x and y coordinates. Within this city,
A Simple RideSharing System
Let's consider a twodimensional city where positions are defined using x and y coordinates. Within this city, multiple cars and passengers are situated at various locations. As illustrated in the image above, you can see the positions of two cars and two passengers. The cars, passengers, and their respective positions can be represented by the 'Car, 'Passenger, and 'Location' classes respectively. The UML diagrams depicting these classes are provided below. This city operates a straightforward ridesharing system, which is represented by the RideSharingApp class in the UML diagram below.
UML Class Diagrams
Implement these four classes using Python. Below is a brief description of those classes:
Location
This class has data attributes and methods.
Data attributes
x An integer value representing the xcoordinate
y An integer value representing the ycoordinate
Methods
initself x y: It is the constructor of the class. It should assign the given parameters to the corresponding data attributes.
strself: This method should return a string representation of the location object. The format of the string should be similar to xy
Car
This class has data attributes and methods.
Data attributes
carname A string representing the name of the car.
location An object of the Location class representing the position of the car within the dimensional space.
costpermile A floating point number representing the cars fare per mile.
Methods
initself name, location, cost: It is the constructor of the class. It should assign the given parameters to the corresponding data attributes.
strself: This method should return a string representation of a car object. The format of the string should be similar to carname, location, costpermile
movetoself newx newy: this method should update the x and y coordinates of the location attribute to newx and newy
Passenger
This class has data attributes and methods.
Data attributes
passengername A string representing the name of the passenger.
location An object of the Location class representing the position of the passenger within the dimensional space.
Methods
initself name, location: It is the constructor of the class. It should assign the given parameters to the corresponding data attributes.
strself: This method should return a string representation of a passenger object. The format of the string should be similar to passengername, location
movetoself newx newy: this method should update the x and y coordinates of the location attribute to newx and newy
RideSharingApp
This class has data attributes and instance methods.
Data attributes
cars A list of Car objects
passengers A list of Passenger objects
Methods
initself: It is the constructor of the class. It should set the cars and passengers attributes to empty lists.
addcarself car adds the given car object to the cars attribute
addpassengerself passenger adds the given passenger object to the passengers attribute
removecarself car removes the given car object from the cars attribute
removepassengerself passenger removes the given passenger object from the passengers attribute
findcheapestcarself This method finds the cheapest car and prints the string representation of that car. The cheapest car is determined based on the costpermile attribute of the car objects.
findnearestcarself passenger This method finds the nearest car for the given passenger object and prints the string representation of that car. The nearest car is determined based on the distance between the passenger and the available cars. For example, if a passengers location is x y and a cars location is x y their distance can be calculated according to:
Submission Instructions
Please follow the instructions carefully and submit accordingly.
Regular Submission
Name your source code file as FULLNAMEHWpy
Submit this file in iCollege folder Homework
Due date: Sun, : PM
Late Submission
If you are submitting beyond the due date, please submit your source code file in HomeworkLateSubmissions folder.
The late submissions penalty will be determined based on the following formula:
PENALTY NUMBEROFHOURSLATE
Examples:
If your submission is hours late, PENALTY
If your submission is hours late, PENALTY
If your submission is hours late, PENALTY
Note:
Only late submissions that are days late will be considered for grading.
All submissions must be made through iCollege. No email submission will be accepted.
Example code:
A sample source co
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