Question

CSE 231                                         &n

CSE 231                                                                                                                        Fall 2019

Project #2

## Language Should be Python.

Assignment Specifications

The program will compute and display information for a company which rents vehicles to its customers. For a specified customer, the program will compute and display the amount of money charged for that customer’s vehicle rental.

  1. The program should start by asking the user if he wants to continue. The answer is ‘Y’ for yes or ‘N’ for no. You can check the value with Boolean expressions such as

answer == ‘Y’

or

answer != ‘Y’.

The basic structure of the main loop is

Prompt to see if the user wants to continue

While the value is ‘Y’:

All your other code goes here

Prompt to see if the user wants to continue

  1. It will then continue to prompt the user to enter the following four items for a given customer (in the specified order):
    1. The customer's classification code (a character)
    1. The number of days the vehicle was rented (an integer)
    1. The vehicle's odometer reading at the start of the rental period (an integer)
    1. The vehicle's odometer reading at the end of the rental period (an integer)

It will then process that customer information and display the results. At the end, the program should ask the user if he wants to process another request and it will keep asking until the user enter 0.

  1. The program will compute the amount of money that the customer will be billed, based on the customer's classification code, number of days in the rental period, and number of miles driven. The program will recognize both upper case and lower case letters for the classification codes.

Code 'B' (budget)

base charge: $40.00 for each day

mileage charge: $0.25 for each mile driven

Code 'D' (daily)

base charge: $60.00 for each day

mileage charge: no charge if the average number of miles driven per day is 100 miles or less; otherwise, $0.25 for each mile driven above the 100 mile per day limit.

Code 'W' (weekly)

base charge: $190.00 for each week (or fraction of a week)

mileage charge: no charge if the average number of miles driven per week is 900 miles or less; $100.00 per week if the average number of miles driven per week exceeds 900 miles but does not exceed 1500 miles; otherwise, $200.00 per week plus $0.25 for each mile driven above the 1500 mile per week limit.

The amount billed to the customer is the sum of the base charge and the mileage charge.

  1. The program will compute the number of miles driven by the customer during the rental period. The odometer readings are taken from an odometer which has six digits and records tenths of a mile.
  2. For each customer, the program will display a summary with the following information:
    1. The customer's classification code
    1. The number of days the vehicle was rented
    1. The vehicle's odometer reading at the start of the rental period
    1. The vehicle's odometer reading at the end of the rental period
    1. The number of miles driven during the rental period
    1. The amount of money billed to the customer for the rental period

All output will be appropriately labeled and formatted. The number of miles driven will be rounded to one fractional digit. The amount of money billed will be displayed with a dollar sign and will be rounded to two fractional digits (for example, $125.99 or $43.87). Note that we do not have the ability yet to fine tune the output so if cents end in zero that final zero will not be

displayed—that is fine for this project. We provide a file strings.txt with the strings we used to make it easier for you to match our output.

  1. The program will detect, report and recover from invalid classification codes. When an invalid classification code is detected, the program will display an error message and re-prompt until a correct classification code is entered.

Hint: use a while loop that will loop until a correct classification code is entered. Here is pseudo code of that loop:

Prompt for a value

While the value is not correct:

Print an error message

Prompt for a value

  1. The program will assume that all other user inputs are valid and correct. That is, the program will not check the number of days or odometer readings for validity. However, as noted below you may encounter an ending odometer reading that is less than the beginning reading and you need to handle that correctly.

Assignment Notes

  1. As stated above, the odometer's dial has six digits and records tenths of a mile. For example, if the beginning reading was 100003 and the ending reading was 100135, then the customer drove 13.2 miles during the rental period.
  2. Since the odometer’s dial is fixed with only six digits, the reading at the end of the rental period may be less than the reading at the beginning of the billing period. For example, if the beginning reading was 999997 and the ending reading was 000005, then the customer drove 0.8 miles during the rental period. You need to handle that arithmetic correctly.

Test 1

Welcome to car rentals.

At the prompts, please enter the following:

Customer's classification code (a character: BDW)

Number of days the vehicle was rented (int)

Odometer reading at the start of the rental period (int)

Odometer reading at the end of the rental period (int)

Would you like to continue (Y/N)? N

Thank you for your loyalty.

Test 2

Welcome to car rentals.

At the prompts, please enter the following:

Customer's classification code (a character: BDW)

Number of days the vehicle was rented (int)

Odometer reading at the start of the rental period (int)

Odometer reading at the end of the rental period (int)

Would you like to continue (Y/N)? Y

Customer code (BDW): D

Number of days: 1

Odometer reading at the start: 100003

Odometer reading at the end:      100135

Customer summary:

classification code: D

rental period (days): 1

odometer reading at start: 100003

odometer reading at end:      100135

number of miles driven:    13.2

amount due: $ 60.0

Would you like to continue (Y/N)? Y

Customer code (BDW): D

Number of days: 4

Odometer reading at the start: 101010

Odometer reading at the end:      108200

Customer summary:

classification code: D

rental period (days): 4

odometer reading at start: 101010

odometer reading at end:      108200

number of miles driven:    719.0

amount due: $ 319.75

Would you like to continue (Y/N)? Y

Customer code (BDW): D

Number of days: 2

Odometer reading at the start: 002000

Odometer reading at the end:      004000

Customer summary:

classification code: D

rental period (days): 2

odometer reading at start: 2000

odometer reading at end:      4000

number of miles driven:    200.0

amount due: $ 120.0

Would you like to continue (Y/N)? Y

Customer code (BDW): B

Number of days: 3

Odometer reading at the start: 999997

Odometer reading at the end:      000005

Customer summary:

classification code: B

rental period (days): 3

odometer reading at start: 999997

odometer reading at end:      5

number of miles driven: 0.8

amount due: $ 120.2

Would you like to continue (Y/N)? N

Thank you for your loyalty.

Test 3

Welcome to car rentals.

At the prompts, please enter the following:

Customer's classification code (a character: BDW)

Number of days the vehicle was rented (int)

Odometer reading at the start of the rental period (int)

Odometer reading at the end of the rental period (int)

Would you like to continue (Y/N)? Y

Customer code (BDW): D

Number of days: 3

Odometer reading at the start: 002000

Odometer reading at the end:      002100

Customer summary:

classification code: D

rental period (days): 3

odometer reading at start: 2000

odometer reading at end:      2100

number of miles driven:    10.0

amount due: $ 180.0

Would you like to continue (Y/N)? Y

Customer code (BDW): D

Number of days: 8

Odometer reading at the start: 000200

Odometer reading at the end:      010000

Customer summary:

classification code: D

rental period (days): 8

odometer reading at start: 200

odometer reading at end:      10000

number of miles driven:    980.0

amount due: $ 525.0

Would you like to continue (Y/N)? N

Thank you for your loyalty.

Homework Answers

Answer #1
Here is the code, I ran for all examples in the question and its running all good.

Let me know for any changes, and I'll update it accordingly,


thank you & do give a up Vote please : )

-------------------------------------------------------------------------------------------------


def compute_bill(code,days,start_reading,end_reading):
    distance=getDistance(start_reading,end_reading)
    if code=='B':
        return 40*days + (distance)*0.25
    elif code=='D':
        average= (distance)/days
        if average<=100:
            return 60*days
        else:
            print(distance)
            return 60*days+ 0.25*(distance-days*100)
    elif code=='W':
        average_weekly=(distance)*7/days
        if average_weekly<=900:
            return 190*(days)/7
        elif average_weekly<=1500:
            return 100*(days)/7
        else:
            return 200*days/7 + (average_weekly-1500)*0.25
    else:
        return 0

def getDistance(start_reading,end_reading):
    if start_reading > end_reading:
        distance = (1+(999999 - start_reading) + end_reading) / 10.0
    else:
        distance = end_reading - start_reading
    distance /= 10.0
    return distance


def printInstructions():
    print('Welcome to car rentals.')
    print('At the prompts, please enter the following:')
    print('Customer\'s classification code (a character: BDW)')
    print('Number of days the vehicle was rented (int)')
    print('Odometer reading at the start of the rental period (int)')
    print('Odometer reading at the end of the rental period (int)')
def main():
    #printInstructions()
    while True:
        answer=input('Would you like to continue (Y/N)? ')
        if answer=='Y':
            code = input('Customer code (BDW): ')
            days=int(input("Number of days: "))
            start_reading=int(input('Odometer reading at the start: '))
            end_reading=int(input('Odometer reading at the end: '))
            bill=compute_bill(code,days,start_reading,end_reading)
            print('Customer summary:')
            print('classification code: {}'.format(code))
            print('rental period (days): {}'.format(days))
            print('odometer reading at start:  {}'.format(start_reading))
            print('odometer reading at end:     {}'.format(end_reading))
            print('number of miles driven:      {}'.format(getDistance(start_reading,end_reading)))
            print('amount due: $ {0:.2f}'.format(bill))
        else:
            print('Thank you for your loyalty.')
            break
main()

=============================================================================================

Know the answer?
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
Similar Questions
Python code only! (Do not include breaks or continue functions) Write a program that asks the...
Python code only! (Do not include breaks or continue functions) Write a program that asks the user to enter the amount that they budgeted for the month. A loop should then prompt the user to enter their expenses, one at a time and to enter 0 to quit. When the loop finishes, the program should display the the amount of budget left. (a negative number indicates the user is over budget and a positive number indicates the user is under...
Design a program that calculates the amount of money a person would earn over a period...
Design a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what salary was for each day, and then show the total pay at the end of the period. The output should be displayed in a...
n this lab, you use what you have learned about parallel arrays to complete a partially...
n this lab, you use what you have learned about parallel arrays to complete a partially completed C++ program. The program should: Either print the name and price for a coffee add-in from the Jumpin’ Jive Coffee Shop Or it should print the message Sorry, we do not carry that. Read the problem description carefully before you begin. The file provided for this lab includes the necessary variable declarations and input statements. You need to write the part of the...
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1....
Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January - December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs to adjust the...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
This is a very short trivia game. See if the user can guess the year that...
This is a very short trivia game. See if the user can guess the year that MDC (formerly Dade County Junior College) first started offering classes (1960). If the user guesses incorrectly, ask if they want another attempt. Once the user gets it right, report the number of guesses needed and end the program. Initial Output: MDC was originally named Dade County Junior College. Output (per loop) In what year were classes first offered? [user types: 1980] That answer is...
How much money do you think you would earn in a period of 30 days if...
How much money do you think you would earn in a period of 30 days if you were paid as follows: one cent for the first day, two cents for the second day, four cents for the third day, eight cents for the fourth day, and so on (i.e. your salary doubles each day)? Do you think you would make very little money, just a few dollars, at the end of the 30-day period? Let us write a program to...
import java.util.Scanner; public class ListDriver {    /*    * main    *    * An...
import java.util.Scanner; public class ListDriver {    /*    * main    *    * An array based list is populated with data that is stored    * in a string array. User input is retrieved from that std in.    * A text based menu is displayed that contains a number of options.    * The user is prompted to choose one of the available options:    * (1) Build List, (2) Add item, (3) Remove item, (4) Remove...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT