Question

In: Computer Science

Problem #2: Going to the Fair Assignment Goals: understanding problem requirements, logical thinking, if-elif-else, and logical...

Problem #2: Going to the Fair Assignment Goals: understanding problem requirements, logical thinking, if-elif-else, and logical operators.
Suppose the Great Frederick Fair wants to update its ticketing software. They need you to write a program to handle the price calculations, using the rules*:
• The basic price of a ticket is $40. • Senior citizens (age >= 65) get a 50% discount. • Children under 6 are free. • For residents of Frederick County, the basic price is $35; the same discounts still apply.
So the possible ticket prices are $0, $17.50, $20, $35, and $40.   
Your program should request age and county name from the user. The age will be entered as an integer and the county name as a string.
Before calculating the price, confirm that the user's age is valid – not negative and not more than 110. If it is not, give a message and do not do the calculation. Also, the county name should not be case sensitive – for example, Frederick, frederick, and FREDERICK should all be acceptable.
Test your program with a variety of ages and counties to be sure you have considered all the conditions. Here are some samples to use.
Test run # County Age 1 Frederick 12 2 Frederick 72 3 Carroll 2 4 Howard 65 5 Washington 0 6 Frederick 5 7 Montgomery 6 8 Carroll 35 9 Frederick -15 10 Frederick 44 11 Howard 112 12 Cecil 13

Your program should be written with the future in mind. The Great Frederick Fair might need to raise the basic prices or modify the discounts in the future. (Hint: named constants, not hard-coded literals!)   
*These aren’t the real prices. The real system is much more complicated. My favorite among the real ones is the Carload Special Tuesday - $60 for everyone legally buckled in a vehicle, buses NOT included.

Solutions

Expert Solution

Screenshot

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

Program

#Constants
BASE_PRICE=40
FREDERICK_PRICE=35
SENIOR_RATEPERCENTAGE=50
FREE_AGE=6
SENIOR_AGE=65
#Function to get the ticket rate
#Take age and country names as arguments
#return ticket rate
def calculateRate(age,county):
    if(age<0 or age>110):
        print('Invalid age!!!')
    elif(age<FREE_AGE):
        return 0
    elif(age>=SENIOR_AGE and county.upper()=='FREDERICK'):
        return FREDERICK_PRICE*(SENIOR_RATEPERCENTAGE/100)
    elif(age>=SENIOR_AGE):
        return BASE_PRICE*(SENIOR_RATEPERCENTAGE/100)
    elif(county.upper()=='FREDERICK'):
        return FREDERICK_PRICE
    else:
        return BASE_PRICE
#Test cases
test1=calculateRate(12,'Frederick')
if(test1!=None):
    print('Test1 ticket rate is $',test1)
test2=calculateRate(72,'Frederick')
if(test2!=None):
    print('Test2 ticket rate is $',test2)
test3=calculateRate(2,'Carroll')
if(test3!=None):
    print('Test3 ticket rate is $',test3)
test4=calculateRate(65,'Howard')
if(test4!=None):
    print('Test4 ticket rate is $',test4)
test5=calculateRate(0,'Washington')
if(test5!=None):
    print('Test5 ticket rate is $',test5)
test6=calculateRate(5,'Frederick')
if(test6!=None):
    print('Test6 ticket rate is $',test6)
test7=calculateRate(6,'Montgomery')
if(test7!=None):
    print('Test7 ticket rate is $',test7)
test8=calculateRate(35,'Carroll')
if(test8!=None):
    print('Test8 ticket rate is $',test8)
test9=calculateRate(-15,'Frederick')
if(test9!=None):
    print('Test9 ticket rate is $',test9)
test10=calculateRate(44,'Frederick')
if(test10!=None):
    print('Test10 ticket rate is $',test10)
test11=calculateRate(112,'Howard')
if(test11!=None):
    print('Test11 ticket rate is $',test11)
test12=calculateRate(13,'Cecil')
if(test12!=None):
    print('Test12 ticket rate is $',test12)

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

Output

Test1 ticket rate is $ 35
Test2 ticket rate is $ 17.5
Test3 ticket rate is $ 0
Test4 ticket rate is $ 20.0
Test5 ticket rate is $ 0
Test6 ticket rate is $ 0
Test7 ticket rate is $ 40
Test8 ticket rate is $ 40
Invalid age!!!
Test10 ticket rate is $ 35
Invalid age!!!
Test12 ticket rate is $ 40


Related Solutions

PURPOSE The purpose of this assignment is to enable students in understanding an organisation’s financial goals...
PURPOSE The purpose of this assignment is to enable students in understanding an organisation’s financial goals through the preparation of functional and cash budgets that together integrate into a business plan. Explain how cash budgets help in: (i) forecasting future needs; (ii) controlling cash expenditure; (iii) evaluation of performance; and (iv) acting as a sound dividend policy.
Requirements: In this assignment, you are going to create two switch functions. The first function is...
Requirements: In this assignment, you are going to create two switch functions. The first function is going to be called switchVal and the second is going to be called switchRef. The goal of this assignment is to demonstrate the understanding of what pass-by-reference (Links to an external site.) and pass-by-value (Links to an external site.) do when working with functions that you create. The two functions that you will modify need to accept two parameters and inside them they need...
For this assignment, I'm going to give a series of problem statements and you need to...
For this assignment, I'm going to give a series of problem statements and you need to state whether the problem would be more appropriately solved with a linear or logistic regression. You also have to give a short defense of why this is the correct regression for each one (only need a sentence or two for each). I have a dataset of soil sample attributes (acidity, density, clay content, etc.) and whether Kentucky bluegrass successfully grew in the soil. I...
CS 400 Assignment 2: applying ArrayList In this assignment, you are going to build a program...
CS 400 Assignment 2: applying ArrayList In this assignment, you are going to build a program that can help rental car companies to manage their rental fleet. Requirement: - build ArrayList class as container. - build Car class/structure to represent car objects. - An ArrayList object is to hold Car objects. Car class should have following fields: - id (int) - make (string) - model (string) - color (string) Instructions: - make up 15 cars and save them into a...
This assignment tests your understanding of abstract classes, inheritance, and requirements modeling using class-based methods. The...
This assignment tests your understanding of abstract classes, inheritance, and requirements modeling using class-based methods. The assignment scenario involves an abstract vehicle class and concrete subclasses Jeep and Ford. The vehicle class has the following variables (manufacturer, language), and methods (getManufacturer( ), and getLanguage( )). The manufacturer builds a specific vehicle (a Jeep and a Ford). The manufacturer will notify the consumer class that a Jeep and a Ford are available for purchase. The consumer class purchases the Jeep. Your...
Assignment Problem: Matt Profitt, an MBA student, is studying companies that are going public for the...
Assignment Problem: Matt Profitt, an MBA student, is studying companies that are going public for the first time. He is curious about whether or not there is a significant relationship between the size of the offering (in millions of dollars) and the price per share. Size    108     4.4      3.5      8.6      139     228     47.5    5.5      175     12        51        66 Price   12        4          5          6          13        19        8.5      5          15        6          12        12         a. Develop the appropriate scatterplot for the two variables in the Excel spreadsheet. b. Based upon the visual inspection of the plot, what type (directional) of relationship do you anticipate between the dependent...
Assignment #2: Individual Macronutrient Requirements and Diet Report Required to Submit: Previous assignment #1 and …....
Assignment #2: Individual Macronutrient Requirements and Diet Report Required to Submit: Previous assignment #1 and …. Your Individual Macronutrient Requirements for: Total kcals, Protein, Fat, Carbohydrate & Fiber Completed Diet Report Complete the Report Questions Completing the Diet Report Once you have recorded your 3-day diet, . You can also access the website in the Diet Project Resources module in Canvas. Instructions on how to generate the Cronometer nutrition analysis report can be found in the Diet Project Resources module....
For this 1-2 page assignment, you are going to watch the video of a speech and...
For this 1-2 page assignment, you are going to watch the video of a speech and write a peer review as if the speaker would get the feedback from you in written form. In the review please address the following aspects of the speech, giving clear examples from the speech and then critique the student’s performance. At least three aspects of delivery At least two aspects of content Was the speech effective? Student Speeches for Analysis
pseudocode please! Assignment 5B: Moneyball: Part 2. Similar to the previous assignment, you’re going to read...
pseudocode please! Assignment 5B: Moneyball: Part 2. Similar to the previous assignment, you’re going to read in the number of years the player played and the starting year of that player – followed by the statistics for those years. This time, however, you’re going to print out the years from worst to best in sorted order. Hint: this will require a second array to store years. If you can sort one array, can you sort both? Sample Output #1: Enter...
Please Note: Only do Problem 2 and please read Problem 2 carefully the requirements thanks /***********************************...
Please Note: Only do Problem 2 and please read Problem 2 carefully the requirements thanks /*********************************** * Filename: arraySorted.c * Author: Last name, first name * Email: Your preferred email address * Login ID: Your EECS login ID ************************************/ #include <stdio.h> /********* DO NOT CHANGE THESE CONSTANTS IN THE FINAL SUBMISSION *********/ #define MAX_SIZE 20 #define SUCCESS 0 /****************** YOUR CODE STARTS HERE ******************/ /************************************************************/ /* Input: array A with "size" elements and an integer d Output: d is added...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT