Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Implement these four classes using Python. Below is a brief description of those classes: 1. Location < This class has 2 data attributes and

imageimageimageimage

Implement these four classes using Python. Below is a brief description of those classes: 1. Location < This class has 2 data attributes and 2 methods. < Data attributes < x - An integer value representing the x-coordinate < y - An integer value representing the y-coordinate < Methods 2. Car _init__(self, x, y): It is the constructor of the class. It should assign the given parameters to the corresponding data attributes. _str_(self): This method should return a string representation of the location object. The format of the string should be similar to - '(x,y)' < This class has 3 data attributes and 3 methods. < Data attributes < car_name - A string representing the name of the car. < location - An object of the 'Location' class representing the position of the car within the 2-dimensional space. < cost per mile - A floating point number representing the car's fare per mile. Methods _init__(self, name, location, cost): It is the constructor of the class. It should assign the given parameters to the corresponding data attributes. < _str_(self): This method should return a string representation of a car object. The format of the string should be similar to - [car_name, location, cost_per_mile]' move_to(self, new_x, new_y): this method should update the x and y coordinates of the 'location' attribute to new_x and new_y 3. Passenger This class has 2 data attributes and 3 methods. < Data attributes < passenger_name - A string representing the name of the passenger. < location An object of the 'Location' class representing the position of the passenger within the 2-dimensional space. < Methods _init__(self, name, location): It is the constructor of the class. It should assign the given parameters to the corresponding data attributes. < _str_(self): This method should return a string representation of a passenger object. The format of the string should be similar to - '[passenger_name, location]' < move_to(self, new_x, new_y): this method should update the x and y coordinates of the 'location' attribute to new_x and new_y. 4. RideSharingApp < This class has 2 data attributes and 7 instance methods. < Data attributes < cars - A list of 'Car' objects < passengers A list of 'Passenger' objects < Methods _init_(self): It is the constructor of the class. It should set the 'cars' and 'passengers' attributes to empty lists. < add_car(self, car) - adds the given car object to the 'cars' attribute < add passenger(self, passenger) 'passengers' attribute < - adds the given passenger object to the remove_car(self, car) - removes the given car object from the 'cars' attribute < remove passenger(self, passenger) - removes the given passenger object from the 'passengers' attribute < find_cheapest_car(self) This method finds the cheapest car and prints the string representation of that car. The cheapest car is determined based on the 'cost_per_mile' attribute of the car objects. < find_nearest_car(self, passenger) This method finds the nearest car for the given 'passenger' object and prints the string representation of that car. The nearest car CSC 1302/DSCI 1302 Homework 1 Due date: Sun, 28-Jan-2024 11:59PM < is determined based on the distance between the passenger and the available cars. For example, if a passenger's location is (X1, y) and a car's location is (X2, y2), their distance can be calculated according to: < d = (x2-2 x1) +(32-41) passenger1 (-2,3) car2 (-4,1) carl (2,1) car2 (-4,1) passenger2 (0,0) passenger1 (0,3) passenger2 (0,0) car1 (0,-5) car2 (-4,1) passenger1 (0,3) car3 (0,2) passenger2 (0,0) car1 (0,-5) Scenario 1 Scenario 2 Scenario 3+ If your class implementations are correct, the program produce the following output: < ---Object creation------- Car object 1 created: [car1, (2,1), 0.61] < Car object 2 created: [car2, (-4,1), 0.5] < Passenger object 1 created: [passenger1, (-2,3)] < Passenger object 2 created: [passenger2, (0,0)] < Scenario 1 Cheapest car available: car2, Cost per mile: 0.5 < Cheapest car available: car2, Cost per mile: 0.5 < Nearest car for passenger1: car2, Distance: 2.83 < Nearest car for passenger2: carl, Distance: 2.24 < -Scenario 2---- carl's location has been updated: [car1, (0,-5), 0.61] < passengerl's location has been updated: [passenger1, (0,3)] < Cheapest car available: car2, Cost per mile: 0.5 < Cheapest car available: car2, Cost per mile: 0.5 < Nearest car for passenger1: car2, Distance: 4.47 < Nearest car for passenger2: car2, Distance: 4.12 < -Scenario 3--- New car added: [car3, (0,2), 0.3] < Cheapest car available: car3, Cost per mile: 0.3 < Cheapest car available: car3, Cost per mile: 0.3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

The image you provided contains information about three different scenarios in what appears to be a ridehailing or vehicle assignment program Heres a ... 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

Fixed Income Analysis

Authors: Barbara S. Petitt

5th Edition

1119850541, 978-1119850540

More Books

Students also viewed these Algorithms questions