Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python Do-from-scratch Exercises File: taxi_simulator.py Write a taxi simulator program that uses your Taxi and SilverServiceTaxi classes. Each time, until they quit: The user should

python

Do-from-scratch Exercises

File: taxi_simulator.py

Write a taxi simulator program that uses your Taxi and SilverServiceTaxi classes.

Each time, until they quit:

The user should be able to choose from a list of available taxis,

They can choose how far they want to drive,

At the end of each trip, show them the trip cost and add it to their bill.

Note: Use a list of taxi objects, which you create in main and pass to functions that need it. When you choose the taxi object, your code will call the drive() method on that object, and it will use the right method for that class... so from the client code point of view, driving a taxi will work the same whether the object is a Taxi or a SilverServiceTaxi, but the results (including the price) depend on the class. This is polymorphism.

Another note: In this program, there's the chance the user will drive a taxi before choosing one. This shouldn't crash. A good option is to maintain something like a current_taxi... but what will the initial value of this variable be? When you want a default starting value for an object, don't use a string or other unrelated type... Instead, you use None:

current_taxi = None 

The taxis used in the example below would be like:

taxis = [Taxi("Prius", 100), SilverServiceTaxi("Limo", 100, 2), SilverServiceTaxi("Hummer", 200, 4)] 

Sample Output:

Let's drive! q)uit, c)hoose taxi, d)rive >>> d You need to choose a taxi before you can drive Bill to date: $0.00 q)uit, c)hoose taxi, d)rive >>> P Invalid option Bill to date: $0.00 q)uit, c)hoose taxi, d)rive >>> c Taxis available: 0 - Prius, fuel=100, odometer=0, 0km on current fare, $1.23/km 1 - Limo, fuel=100, odometer=0, 0km on current fare, $2.46/km plus flagfall of $4.50 2 - Hummer, fuel=200, odometer=0, 0km on current fare, $4.92/km plus flagfall of $4.50 Choose taxi: 3 Invalid taxi choice Bill to date: $0.00 q)uit, c)hoose taxi, d)rive >>> c Taxis available: 0 - Prius, fuel=100, odometer=0, 0km on current fare, $1.23/km 1 - Limo, fuel=100, odometer=0, 0km on current fare, $2.46/km plus flagfall of $4.50 2 - Hummer, fuel=200, odometer=0, 0km on current fare, $4.92/km plus flagfall of $4.50 Choose taxi: 0 Bill to date: $0.00 q)uit, c)hoose taxi, d)rive >>> d Drive how far? 333 Your Prius trip cost you $123.00 Bill to date: $123.00 q)uit, c)hoose taxi, d)rive >>> c Taxis available: 0 - Prius, fuel=0, odometer=100, 100km on current fare, $1.23/km 1 - Limo, fuel=100, odometer=0, 0km on current fare, $2.46/km plus flagfall of $4.50 2 - Hummer, fuel=200, odometer=0, 0km on current fare, $4.92/km plus flagfall of $4.50 Choose taxi: 1 Bill to date: $123.00 q)uit, c)hoose taxi, d)rive >>> d Drive how far? 60 Your Limo trip cost you $152.10 Bill to date: $275.10 q)uit, c)hoose taxi, d)rive >>> c Taxis available: 0 - Prius, fuel=0, odometer=100, 100km on current fare, $1.23/km 1 - Limo, fuel=40.0, odometer=60.0, 60.0km on current fare, $2.46/km plus flagfall of $4.50 2 - Hummer, fuel=200, odometer=0, 0km on current fare, $4.92/km plus flagfall of $4.50 Choose taxi: 2 Bill to date: $275.10 q)uit, c)hoose taxi, d)rive >>> d Drive how far? 61 Your Hummer trip cost you $304.60 Bill to date: $579.70 q)uit, c)hoose taxi, d)rive >>> c Taxis available: 0 - Prius, fuel=0, odometer=100, 100km on current fare, $1.23/km 1 - Limo, fuel=40.0, odometer=60.0, 60.0km on current fare, $2.46/km plus flagfall of $4.50 2 - Hummer, fuel=139.0, odometer=61.0, 61.0km on current fare, $4.92/km plus flagfall of $4.50 Choose taxi: 1 Bill to date: $579.70 q)uit, c)hoose taxi, d)rive >>> d Drive how far? 59 Your Limo trip cost you $102.90 Bill to date: $682.60 q)uit, c)hoose taxi, d)rive >>> Q Total trip cost: $682.60 Taxis are now: 0 - Prius, fuel=0, odometer=100, 100km on current fare, $1.23/km 1 - Limo, fuel=0, odometer=100.0, 40.0km on current fare, $2.46/km plus flagfall of $4.50 2 - Hummer, fuel=139.0, odometer=61.0, 61.0km on current fare, $4.92/km plus flagfall of $4.50

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

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

1. Write down two or three of your greatest strengths.

Answered: 1 week ago

Question

What roles have these individuals played in your life?

Answered: 1 week ago

Question

2. Write two or three of your greatest weaknesses.

Answered: 1 week ago