CMPS 134 Fall 2023
Prog. Assg. #2: Purchase Calculator
Due: 11:59pm, Sunday, September 24

Provided to you is an incomplete version of the Java program PurchaseCalculator. Your task is to complete it.

The table below shows user/program interactions for three separate runs of the program (Each cell in the table depicts one run.) User input is shown in boldface.

The program prompts the user to enter a unit price and reads the user's response. The program then prompts the user to enter the quantity to be purchased and reads the user's response. (The unit price is expected to be a positive real number; the quantity is expected to be a positive integer.)

The program responds to the inputs by displaying the discount rate (which is a function of quantity), the total price, and the discounted price.

User/Program Interactions
for three runs of the program
Enter the unit price (in dollars):>1.5
Enter the quantity:>1
The discount rate is 0.0%
The total price is $1.50
The discounted price is $1.50
Enter the unit price (in dollars):>12.50
Enter the quantity:>8
The discount rate is 33.33333333333333%
The total price is $100.00
The discounted price is $66.67
Enter the unit price (in dollars):>10.0
Enter the quantity:>100
The discount rate is 48.292682926829265%
The total price is $1000.00
The discounted price is $517.07

Variables and Formulae
unit price: U (input)
quantity: Q (input)
total price: TP = U·Q
discount rate: R = (Q−1) / (2Q + 5)
discounted price: DP = TP·(1−R)
To the right are shown the relevant variables, which include the two inputs and the three whose values depend upon the inputs. The given formulae describe those dependencies exactly.

The variable names used here are concise, as is the convention when presenting a mathematical model; the corresponding variables in the given Java program are longer and more descriptive, as is the convention in computer programming.

To successfully complete the program, you will need to make use of arithmetic expressions that mimic the formulae appearing here. You are expected to employ procedural decomposition, which would most likely translate into the use of separate methods for computing total price, discount rate, and discounted price. As a model, you may want to examine the GrossNetPay2 program.

Use the appropriate Brightspace dropbox to submit your Java source code (meaning the PurchaseCalculator.java file, not the corresponding .class file).