Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a program called ShopperRewardsYourLastName. A supermarket awards coupons depending on how much a customer spends on groceries. For example, if you spend $50, you

Create a program called ShopperRewardsYourLastName.

A supermarket awards coupons depending on how much a customer spends on groceries. For example, if you spend $50, you will get a coupon worth four percent of that amount. The following table shows the percent used to calculate the coupon awarded for different amounts spent. Write a program that accepts the user's grocery bill total and returns the percentage of the coupon earned and the discount coupon amount the coupon, along with the total cents off the user will earn. Details on implementation below.

Sample runs and output:

Please enter the cost of your groceries: 99.01

You receive a discount coupon of $6.93. (7% of your purchase)

You have earned a 2 discount per gallon of gas.

Please enter the cost of your groceries: 45.01

You receive a discount coupon of $1.80. (4% of your purchase)

You have earned a 1 discount per gallon of gas.

Main method: Accept the grocery amount from the user and complete all the printing in the main method. No println or other printing statements should happen in your methods.

Discount coupon method: Create a method to pass the grocery bill amount into. Receive a double back that represents the percentage discount. Use the value to compute the discount (percent * grocery bill) and to print the percentage of the user. Use the table below to determine the discount earned.

Money Spent

Coupon Percentage

Less than $10

No coupon

From $10 to $70

4%

More than $70 to $150

7%

More than $150 to $250

10%

More than $250

15%

Again, no printing should be happening in your if statements or methods. Set your variables. Use printf( ) or DecimalFormatting class to format the output ONE TIME after you set the values.

Fuel Rewards Method: In addition to providing coupons, our Shopper Rewards program has decided to expand. It is also awarding gas discounts. Based on their purchase price, also provide them with information on a gas discount. If they spend between $1 and $49, they receive a 1 discount per gallon of gas. If they spend between $49.01 and $100, they receive a 2 discount per gallon of gas. If they spend more than $100.01, they receive a 3 discount per gallon of gas. Report their discount savings, amount of discount (formatted to two decimal places) and gas discount back to them.

Create a method to accept the grocery bill amount and return a double that represents the gas discount.

Tests: Create two tests to test your methods. Test all possible outputs for both methods.

Minimally, you'll have at least 5 tests to test the coupon if statements - possibly more because you want to test the endpoint of the ranges.

To test the gas discount, you'll have at least three tests.

Helpful hints:

No magic numbers! Very important: Remove the magic numbers from your program. Your ranges should NOT look like this:

if ( groceryCost < 10)

But use variables instead: if ( groceryCost < LOW_GROCERY_PURCHASE_RANGE)

Use good variable and method names. Follow the Java naming conventions for all method and variable names.

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

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students also viewed these Databases questions

Question

5. Discuss the key components of behavior modeling training.

Answered: 1 week ago

Question

4. Develop a self-directed learning module.

Answered: 1 week ago