Question

Please answer the following in Python:

The cost of a travel pass includes a $5 administrative charge and the cost of one unit of trips (or 10 trips) at $1.50 per tr

An exception from InputError class is raised whenever the user enters an invalid value when prompted for a menu option or whe

Before top up: Travel Pass: e000001 Number of trips left: 10 After 1 unit top up: Travel Pass: 0000001 Number of trips left:

(d) Write the following functions with relevant parameter(s) if necessary for the application function getMenuoption that dis

An example run (characters in green are user input) Passenger Id: T1234X None Menu 1. Get Travel Card 2. Get refund 3. Make a

2. Get refund 3. Make a trip 4. Top up Travel Pass Exit Enter choice: 1 Enter amount: 1Θ Insufficient amount to Get Travel Ca

Passenger Id: T1234X Travel Pass: eeeeee! Number of trips left: 20 Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. To

Passenger Id: T1234X Travel Pass: 0000002 Number of trips left: e Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top

The cost of a travel pass includes a $5 administrative charge and the cost of one unit of trips (or 10 trips) at $1.50 per trip. A passenger who has a travel pass can perform these operations make trips as long as there is at least one unconsumed trip, top up in multiples of units of trips without incurring administrative charge get a refund at $1.20 per unconsumed trip C) C) C) When a refund is made, the travel pass is surrendered. Thus, the passenger must repurchase a travel pass if he subsequently wishes to make a trip. The following describe the structure of the classes. To demonstrate how classes can be used to organize information, write the following classes and an application that provides a menu to ONE (1) passenger InsufficientAmountException, InputError and TravelException, classes. (a) InsufficientAmountException and InputError are subclasses of TravelException. These classes do not require any additional attributes or methods.
An exception from InputError class is raised whenever the user enters an invalid value when prompted for a menu option or when prompted for an amount for buying or for topping up a travel pass An exception from TravelException class is raised whenever these requests cannot be carried out: purchase travel pass, top up, get refund and make a trip (1 mark) (b TravelPass class The class attributes of this class are cost of a trip (S1.50), the number of trips (10) sold as a unit, the refund amount per unconsumed trip (S1.20), and the administration charge (S5). You can introduce any other necessary class attribute(s) where necessary Write the class methods getNumberOfTripsPerUnit that returns the number of trips in one unit getCostPerUnit that returns the cost of one unit of trips costOfTravelPass that returns sum of the cost of a uni and the administration charge getRefundPerTrip that returns the refund amount per unconsumed trip You must call the class methods for the values in the class attributes as the values in the class attributes may change. Do not hardcode their values in your processing or output statements There are two object attributes: travel pass id and the number of unconsumed trips. Write Python code to complete the class definition for TravelPass constructor with a parameter: an amount in dollars. The constructor raises an InsufficientAmountException exception with the message Minimum amount to buy a pass is $20.00 if the amount is less than the cost of a travel pass. The travel pass id is auto-generated. The id of first travel pass is id 1, the second is 2, and so on getter method for the number of unconsumed trips method makeTrip that raises an TravelException exception with the message Travel pass has 0 trips left if there is no unconsumed trip left. Otherwise, the method decrements the number of unconsumed trip(s) by l method topup with a parameter: the amount to top up. The method raises an InsufficientAmountException exception with the message Min amount to top up is $15.00 if the amount is less than the cost of a unit of trips. If the amount is sufficient, the method computes the number of units possible, and increases the number of unconsumed trips by the number of trips in the units The method returns a string containing the travel pass details before and after the top up, as wel as the amount of change. For example, if the amount is 22 and the travel pass has 10 unconsumed trips, the method returns the following string
Before top up: Travel Pass: e000001 Number of trips left: 10 After 1 unit top up: Travel Pass: 0000001 Number of trips left: 20 Change$7.00 method getRefund that raises an TravelException exception with the message There is no trip refund if there is no unconsumed trip left Otherwise, the method computes the refund amount of all unconsumed trips and sets the number of unconsumed trips to zero. It returns the refund amount method _str_ that returns a string representation of the travel pass. An example is shown here: Travel Pass: 0000001 Number of trips left: 20 (14 marks) (c) Passenger class The object attributes of this class are: passenger id and a travel pass Write Python code for the class definition for Passenger constructor with two parameters: passenger id and a travel pass with default value None. A passenger may be created with or without a travel pass getter method for the travel pass using the property decorator method hasTravelPass that returns True if the passenger has a travel pass and False otherwise method getTravelPass with a parameter amount. The method raises an TravelException exception with the message Please use existing xx trips in current pass or get a refund first if there are xx unconsumed trips left in the passenger has a travel pass with unconsumed trips Otherwise, it creates a travel pass for him with amount method topup with a parameter amount. The method raises an TravelException exception with the message No travel pass! Please get a travel pass if the passenger does not have a travel pass. Otherwise the travel pass is topped up with the amount and the result of the top up operation is returned. The method does not handle exception method refund that raises an TravelException exception with the message No travel pass! Please get a travel pass if the passenger does not have a travel pass. Otherwise, the method gets the refund amount of the travel pass, sets the travel pass of the passenger to None, and returns the refund amount The method does not handle exception. method makeTrip that raises an TravelException exception with the message No travel pass! Please get a travel pass if the passenger does not have a travel pass. Otherwise, the travel pass is used to make trip. The method does not handle exception. method __str__that returns a string representation of the passenger and his travel pass. An example is shown here Passenger Id: T1234X Travel Pass: 00e00e1 Number of trips left: 1e (12 marks)
(d) Write the following functions with relevant parameter(s) if necessary for the application function getMenuoption that displays a menu and prompts the passenger for a choice. If the passenger enters non-numeric value non-whole numbers, the function raises an InputError exception with the message Error in choice. Please enter a whole number to 4, The function returns the passenger's choice as a whole number function getAmount that prompts the passenger for an amount. If the passenger enters a non-numeric value or a number not greater than 0, it raises an InputError exception with the message Error in amount. Please enter a positive decimal number. The function returns the amount as a decimal number function getTravelPass that raises a a TravelException exception with the message Please use existing xx trips in current pass or get a refund first if there is xx unconsumed trip left in the passenger's travel pass. Otherwise, the function prompts the passenger for an amount. If the passenger has a travel pass with no unconsumed trips, the function prompts the passenger whether he wishes to top up instead. If so, it invokes a top up for the passenger. Otherwise, the function gets a travel pass for the passenger and displavs the amount of change function topup that raises a TravelException exception with the message No travel pass! Please get a travel pass if the passenger does not have a travel pass. Otherwise, the function prompts the passenger for an amount and invokes a top up for the passenger function main that creates a passenger with id T1234X but without a travel pass The function displays a menu repeatedly for the passenger to choose an operation until he chooses to exit For the following descriptions for function main, note that xx in the output message refers to the whole number that the passenger has entered for a menu choice, and yy refers to the operation corresponding to the menu choice. For example, if xx is l, then yy is Get Travel Card If the passenger enters an invalid option, that is, not between 0 and 4 print the message Invalid choice: xx If the choice is valid, the function calls the relevant functions to perform the selected operation, o and handles these exceptions InputError by simply printing the exception message InsufficientAmountException by appending a prefix Insufficient amount to yy operation. InReason: to TravelException by appending a prefix yy operation is If the operation is successful, the function prints the passenger detail and (9 marks) the exception message unsuccessful.\nReason: to the exception message o the message yy operation is successful on separate lines
An example run (characters in green are user input) Passenger Id: T1234X None Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass Exit Enter choice: abc Error in choice. Please enter a whole number 0 to 4 same error message for all non-numbers and non whole numbers: * Error in choice. Please enter a whole number to 4 Passenger Id: T1234X None Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass Exit Enter choice: -1 Invalid choice: 1 ***- same error message for all whole numbers no between 0 and 4 where xx is user input:*** Invalid choice: -xx Passenger Id: T1234X None Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass 0. Exit Enter choice: 2 Get refund operation is unsuccessful. Reason: No travel pass! Please get a travel pass choice 3 has the error nessage when passenger has no travel pass Make a trip operation is unsuccessful. Reason: No travel pass! Please get a travel pass choice 4 has error message when passenger has no travel pass Top up Travel Pass operation is unsuccessful. Reason: No travel pass! Please get a travel pass Passenger Id: T1234X None Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass Exit Enter choice: 1 Enter amount: abc Error in amount. Please enter a positive decimal number same error message for all invalid amount such as -1 and 0 and non-numbers: Error in amount. Please enter a positive decimal number Passenger Id: T1234X None Menu 1. Get Travel Card
2. Get refund 3. Make a trip 4. Top up Travel Pass Exit Enter choice: 1 Enter amount: 1Θ Insufficient amount to Get Travel Card operation. Reason: Minimum amount to buy a pass is $20.0e Passenger Id: T1234X None Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass Exit Enter choice: 1 Enter amount: 25 Change$5.00 Passenger Id: T1234X Travel Pass: 0000001 Number of trips left: 10 Get Travel Card operation is successful. Passenger Id: T1234X Travel Pass: e0e0001 Number of trips left: 18 Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass 0. Exit Enter choice: 1 Get Travel Card operation is unsuccessful. Reason: Please use existing 1e trips in current pass or get a refund first Passenger Id: T1234X Travel Pass: e000001 Number of trips left: 1 Menu 1. GetTravel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass θ. Exit Enter choice: 4 Enter amount: 10 Insufficient amount to Top up Travel Pass operation. Reason: Min amount to top up is $15.0e Passenger Id: T1234X Travel Pass: eeeeee! Number of trips left: 1e Menu 1. GetTravel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass 0. Exit Enter choice: 4 Enter amount 22 Before top up : Travel Pass: θθθ0001 Number of trips left: 10 After 1 unit top up: Travel Pass: ee0e001 Number of trips left: 20 Change - $7.00 Passenger Id: T1234X Travel Pass: 0000001 Number of trips left: 20 Top up Travel Pass operation is successful.
Passenger Id: T1234X Travel Pass: eeeeee! Number of trips left: 20 Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass Exit Enter choice: 2 Refund amount at $1.20 per trip: $24.00 Passenger Id: T1234X None Get refund operation is successful. Passenger Id: T1234X None Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass 9. Exit Enter choice: 1 Enter amount: 20 Change$0.00 Passenger Id: T1234X Travel Pass: e000002 Number of trips left: 10 Get Travel Card operation is successful Passenger Id: T1234X Travel Pass 0000002 Number of trips left: 1e Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass 0. Exit Enter choice: 3 Passenger Id: T1234X Travel Pass: e000002 Number of trips left: 9 Make a trip operation is successful. **sinilar output for choice 3 repeatedly until unconsumed trips is 0 Passenger Id: T1234X Travel Pass: e000002 Number of trips left e Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass 0. Exit Enter choice: 3 Make a trip operation is unsuccessful. Reason: Travel pass has 0 trips left Passenger Id: T1234X Travel Pass: e000092 Number of trips left: e Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass e. Exit Enter choice: 2 Get refund operation is unsuccessful. Reason There is no trip refund
Passenger Id: T1234X Travel Pass: 0000002 Number of trips left: e Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass e. Exit Enter choice: 1 Enter amount: 35 To top up instead, enter T. Enter any key to purchase new pass: t Before top up: Travel Pass: eeeeee2 Number of trips left: θ After 2 unit top up: Travel Pass: 0ΘΘΘΘΘ2 Number of trips left: 20 Change - $5.00 Passenger Id: T1234X Travel Pass: 0000002 Number of trips left: 20 Get Travel Card operation is successful Passenger Id: T1234X Travel Pass: 0000002 Number of trips left: 20 Menu 1. GetTravel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass Exit Enter choice: 3 Passenger Id: T1234X Travel Pass e000002 Number of trips left: 19 Make a trip operation is successful. * similar output for choice 3 repeatedly until unconsumed trips is 0*** Passenger Id: T1234X Travel Pass: 0000002 Number of trips left: θ Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass 0. Exiit Enter choice: 1 Enter amount: 20 To top up instead, enter T. Enter any key to purchase new pass: Change $e.0e Passenger Id: T1234X Travel Pass: 0000003 Number of trips left: 1θ Get Travel Card operation is successful Passenger Id: T1234X Travel Pass: ee00003 Number of trips left: 10 Menu 1. Get Travel Card 2. Get refund 3. Make a trip 4. Top up Travel Pass θ. Exit Enter choice: Application Ended
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answering just the first part as per standard:

public class TravelException extends Exception

{

    public TravelException (String s)

    {

    super(s);

    }

}

public class InputError extends TravelException

{

    public InputError (String s)

    {

    super(s);

    }

}

public class InsufficientAmountException extends TravelException

{

    public InsufficientAmountException (String s)

    {

    super(s);

    }

}

Add a comment
Know the answer?
Add Answer to:
Please answer the following in Python: The cost of a travel pass includes a $5 administrative charge and the cost of one unit of trips (or 10 trips) at $1.50 per trip. A passenger who has a tr...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Solve it for java Question Remember: You will need to read this assignment many times to...

    Solve it for java Question Remember: You will need to read this assignment many times to understand all the details of the you need to write. program Goal: The purp0se of this assignment is to write a Java program that models an elevator, where the elevator itself is a stack of people on the elevator and people wait in queues on each floor to get on the elevator. Scenario: A hospital in a block of old buildings has a nearly-antique...

  • SYNOPSIS The product manager for coffee development at Kraft Canada must decide whether to introduce the...

    SYNOPSIS The product manager for coffee development at Kraft Canada must decide whether to introduce the company's new line of single-serve coffee pods or to await results from the product's launch in the United States. Key strategic decisions include choosing the target market to focus on and determining the value proposition to emphasize. Important questions are also raised in regard to how the new product should be branded, the flavors to offer, whether Kraft should use traditional distribution channels or...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT