Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by

1.  Write a program that translates a letter grade into a number grade.  Letter grades are A, B, C, D, and F, possibly followed by + or -.  Their numeric values are 4, 3, 2, 1 and 0.  There is no F+ or F-.  A "+" increases the numeric value by 0.3, a "-" decreases it by 0.3.  However, an A+ has value 4.0.  Your program must ask the user to input a grade, then you will print the results. See below: 4 pts

Enter a Letter grade: B-

The numeric value is 2.7

a)  Your code with comments

b)  A screenshot of the execution

Test Cases:

         B-   (should print 2.7)

         A+  (should print 4.0)

         B+  (should print 3.3)

         C (should print 2.0) 

         F+  (should print 0.0)

         G (should print "no such grade")

2.  Write a program that reads in the name and salary of an employee.  Here the salary will denote an hourly wage, such as $9.25.   Then, ask how many hours the employee worked in the past week.  Be sure to accept fractional hours.  Compute the pay.  Any overtime work (over 40 hours per week) is paid at 150 percent of the regular wage.4 pts

a)  Your code with comments

b)  A screenshot of the execution

Test Cases:

Enter name: Jorge

Enter wage: 9.25

Enter hours: 10

               Total pay is: $92.50

Enter name: John

Enter wage: 20.00

Enter hours: 50

Total pay is: $1100 ($800 + $300 overtime)

3.  Write a program that reads a word and then prints the word in reverse separated by a comma. 3 pts

 

Note: No comma at the end of the reversed word.

 

Enter word: Harry

The reversed word is: y,r,r,a,H

a)  Your code with comments

b)  A screenshot of the execution

 

4.  Write a program to pre-sell a limited number of cinema tickets.  Each buyer can buy as many as 4 tickets.  No more than 20 tickets can be sold.  Implement a program called TicketSeller that prompts the user for the desired number of tickets and then displays the number of remaining tickets.  Repeat until all tickets have been sold, and then display the total number of buyers.4 pts

Loop

There are currently xxx tickets remaining.

How many tickets would you like to purchase?

(make sure you print an error message if they try to buy more than 4)

The total number of buyers was xxx.

                       

                     Note: The number of tickets must be a constant. You can test with a value of 20.

a)  Your code with comments

b)  A screenshot of the execution

 

5.  Having a secure password is a very important practice, when much of our information is stored online.  Write a program that validates a new password, following these rules:5 pts

 

A) The password must be at least 8 characters long

B) The password must have at least one uppercase and one lowercase letter

C) The password must have at least one digit

 

The program must also ask for a user to enter it and then confirm it:

Enter your password:

Re-enter your password:

 if the passwords don't match or the rules are not fulfilled, a message is printed as to what the error is and the user is prompted again.  Your program must include a function that checks whether the rules are passed and if the password is valid (returns True if it is valid):

   defisValidPassword(password)

 

Note: Re-enter password AFTER you validate the password first

a)  Your code with comments

b)  A screenshot of the execution

Test Cases:

         Abcdefgh - (should print "must have at least one digit")

         1BCDEFGH - (should print "must have at least one lower case")

         1abcdefgh - (should print "must have at least one upper case")

         1Abcdef - (should print "must be at least 8 characters long")

         1Abcdefg - (Valid: should ask to Re-enter password)

6.  A non-governmental organization needs a program to calculate the amount of financial assistance for needy families.  The formula is as follows:5 pts

·    If the annual household income is between $30,000 and $39,999 and the household has at least three children, the amount is $1000 per child.

·    If the annual household income is between $20,000 and $29,999 and the household has at least two children, the amount is $1500 per child.

·    If the annual household income is less than $20,000, the amount is $2000 per child.

 

(Note: anything outside these conditions, there is NO financial assistance)

 

Implement a function for this computation.  Write a program that asks for the household income and number of children for each applicant, printing the amount returned by your function.  Use a -1 as a sentinel value for the input.

 

DefcomputeAssistance (income, children)

 

a)  Your code with comments

b)  A screenshot of the execution

Test Cases:

         Household income = $35,000         No. of children = 4 (should return $1000/child)

         Household income = $25,000         No. of children = 3 (should return $1500/child)

         Household income = $18,000         No. of children = 2 (should return $2000/child)

         Household income = $40,000         No. of children = 1 (should return "No assistance")

 


7.  A supermarket wants to reward its best customer of each day, showing the customer's name on a screen in the supermarket.  For that purpose, the customer's sales are stored in a list and the customer's name is stored in a corresponding list.  Implement a function:5 pts

 

DefnameofBestCustomer(Sales, Customers)

 

that returns the name of the customer with the largest sale.

 

Write a program that prompts the cashier to enter all sales and customers, adds them to two lists, calls the function that you implemented, and displays the result.  Use a sales of 0 as a sentinel.

 

                     Loop

                                 Enter customer:

                                 Enter Sales:

                     Store these in 2 lists

                     Call function nameofBestCustomer

                     Print the name of the best customer

a)  Your code with comments

b)  A screenshot of the execution

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

Java Concepts Late Objects

Authors: Cay S. Horstmann

3rd Edition

1119186714, 978-1119186717

More Books

Students also viewed these Programming questions

Question

8.4 Fill in the blanks in the following flexible budget:

Answered: 1 week ago

Question

Name one ethical issue in a buyers job, and explain it.

Answered: 1 week ago