Lab 03 - Java

profilejehboy
5390_Lab03_Problem_Statement.pdf

BCIS 5390 Lab 03 Problem Statement 

Lab 3 will consist of modifying Lab 2 in the following manner: 

 Implement a loop with a sentinel value to allow the user to control the number of times the program  executes. When the user enters ‐1 for the hours used the program should end, otherwise it should  continue (hint: see section “Using a Sentinel Value” on pgs. 223‐225 [5th]; pgs. 219‐221 [6th]) 

 Replace the decision structures with an appropriate loop for implementing input validation as follows  (hint: see section “Using the while Loop for Input Validation on pgs. 204‐207 [5th]; pgs. 200‐203 [6th]): 

o hours used must be greater than zero otherwise an error message is displayed and the user is  prompted to enter the hours used until it is valid 

o the first character of the zip code must be greater than zero otherwise an error message is  displayed and the user is prompted to enter the zip code until it is valid 

o the county name must be entered (i.e., cannot be blank) otherwise an appropriate message is  displayed and the user is prompted to enter the county name until it is valid. the user should be  able to enter the county name in uppercase, lowercase, and mixed case 

o when an incorrect package letter is entered the program should display an error message to the  user and then prompt the user to enter a package letter until it is valid. the user should be able to  enter the package letter in uppercase or lowercase 

 Implement a counter which tracks the number of times the program executes which represents the  number of customers and display the result in the output (hint: see section “Running Totals and Sentinel  Values” on pgs. 220‐225 [5th]; pgs. 216‐221 [6th]) 

 Implement an accumulator which calculates a running total for discount amount and display the result in  the output (hint: see section “Running Totals and Sentinel Values on pgs. 220‐225 [5th]; pgs. 216‐221 [6th]) 

 Implement an accumulator which calculates a running total for total charge and display the result in the  output (hint: see section “Running Totals and Sentinel Values on pgs. 220‐225 [5th]; pgs. 216‐221 [6th]) 

 Calculate the average discount amount as running total of discount divided by number of customers and  display it in the output 

 Calculate the average of total charge as running total of total charge divided by number of customers and  display it in the output 

 When the program ends display “Good‐bye!” to the user   All monetary output should be formatted the DecimalFormat class (pgs. 174‐181 [5th]) or String.format() 

method (pgs. 164, 175‐177 [6th]) to display as currency (i.e., leading dollar sign, appropriate comma(s),  and two‐decimal places). 

 Use the horizontal tab escape sequence to format output to line up appropriately (see p. 37).   The newline escape sequence can be used to format spacing between output (see p. 37). 

Sample input/output has been provided below: 

Enter hours used: 0 Invalid hours used. Must be greater than zero. Try again: 25 Enter zip code: 01234 Invalid zip code. First character must be greater than zero. Try again: 76401 Enter county: Invalid County. County is required. Try again: Erath Enter package type: d Invalid package type. Must be A, B, or C. Try again: A Base Charge for Package A: $9.95 Additional Charge for Package A: $30.00 Surcharge for Zip Code: $0.00 Subtotal for Package A: $39.95 Discount Amount for County: $7.99 Total Charge for Package A: $31.96 Package B Savings: $16.80 Package C Savings: $16.00 Total Discount Amount for All Packages: $7.99 Total Charge for All Packages $31.96 Average Discount Amount: $7.99 Average Total Charge: $31.96 Total Customers: 1

Enter hours used: 25 Enter zip code: 56789 Enter county: Parker Enter package type: B Base Charge for Package B: $13.95 Additional Charge for Package B: $5.00 Surcharge for Zip Code: $1.75 Subtotal for Package B: $20.70 Discount Amount for County: $2.07 Total Charge for Package B: $18.63 Total Discount for All Packages: $10.06 Total Charge for All Packages: $50.59 Average Discount Amount: $5.03 Average Total Charge: $25.30 Total Customers: 2 Enter hours used: 50 Enter zip code: 76401 Enter county: Erath Enter package type: C Base Charge for Package C: $19.95 Surcharge for Zip Code: $0.00 Subtotal for Package C: $19.95 Discount Amount for County: $3.99 Total Charge for Package C: $15.96 Total Discount for All Packages: $14.05 Total Charge for All Packages: $66.55 Average Discount Amount: $4.68 Average Total Charge: $22.18 Total Customers: 3 Enter hours used: 5 Enter zip code: 12345 Enter county: Winkler Enter package type: A Base Charge for Package A: $9.95 Surcharge for Zip Code: $0.00 Subtotal for Package A: $9.95 Discount Amount for County: $0.00 Total Charge for Package A: $9.95 Total Discount Amount for All Packages: $14.05 Total Charge for All Packages $76.50 Average Discount Amount: $3.51 Average Total Charge: $19.12 Total Customers: 4 Enter hours used: -1 Good-bye!