Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 Writing Classes: I need help writing three Python classes. They are shown below. It's a bit of a long one so if you're

Python 3 Writing Classes:

I need help writing three Python classes. They are shown below. It's a bit of a long one so if you're up to the task, go for it. Thank you!

image text in transcribedimage text in transcribed

Train class Instance variables: the name of the train String name the maximum number of passengers the train can transport max passengers the number of passengers currentl on the train num passengers speed fps how fast the train travels (in feet per second) Methods name, max passengers, speed fps) constructor, initializes all instance variables, init (self, num passengers should default to 0 when a train is created with the constructor o Assumptions speed fps and max passengers will always be a non-negative number name will be a non-empty string (self) returns string representation with this format str Train named Orient Express with 5 passengers will travel at 10.20mph Notes: The quotes in the example are just our string boundaries! The first character in the above example is T This method reports num passengers (NOT max passengers) Train speed is converted to mile per hour and always presented with 2 digits after the decimal point. time to travel(self, distance feet) Returns how long (in whole seconds) this train will take to travel distance feet (distance in feet) o Notes and Assumptions This always returns an integer- you could use integer division or normal division followed by int conversion to truncate the fractional part. You can assume that distance feet is always a non-negative integer load passengers(self, num people) Attempts to put num people onto the train and update num passengers. If the number of people supplied would not fit on the train, raise a TraincapacityException and do not change the number of passengers currently on the train. [You may imagine this as "the passengers get into a fight and no one is allowed on the train".J o Note and Assumptions: You can assume that num people is always a non-negative integer. When raising the exception, the number to raise is the number of people that cannot fit on the train (not the number of people that try to board) This function should return None. Remember: None is the default return if you don't return anything! You don't need to explicitly return None unload passengers(self, num people) Attempts to remove num people from the train. If the number of people supplied is larger than the number of people on the train currently, raise a TraincapacityException and do not change the number of passengers currently on the train. [You may imagine this as the passengers are so confused by the request that they just stay where they are looking confused" o Note and Assumptions: You can assume that num people is always a non-negative integer When raising the exception, the number to raise is the number of people that cannot unload, not the number of people that try to exit the train This function should return None. Remember: None is the default return if you don't return anything! You don't need to explicitly return None

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

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

More Books

Students also viewed these Databases questions