Question
Create a program called Bagel BonusYourLastName. A bagel shop offers awards coupons depending on how much a customer spends on bagels per month. For example,
Create a program called Bagel BonusYourLastName.
A bagel shop offers awards coupons depending on how much a customer spends on bagels per month. For example, if you spend $50 in one month, you will get a coupon worth five percent of that amount to use during the next month. The following table shows the percent used to calculate the coupon awarded for different amounts spent. Write a program that accepts the user's monthly total spent in the bagel shop. Return the percentage of the coupon earned and the total discount coupon amount for us in the next month. Details on implementation below.
Sample runs and output:
Monthly amount spent at the Bagel Shop: 99.01 You receive a discount coupon of $8.91. (9.0% of your previous month's purchase) You have earned 2 cup(s) of coffee. | Monthly amount spent at the Bagel Shop: 45.01 You receive a discount coupon of $3.15. (7.0% of your previous month's purchase) You have earned 1 cup(s) of coffee. |
Main method: Accept the monthly amount spent 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 monthly amount spent into. Receive a double back that represents the percentage discount. Use the value to compute the discount (percent * monthly amount spent) and to print the percentage of the user. Use the table below to determine the discount earned.
Money Spent | Coupon Percentage |
Up to $20 | No coupon |
From $20.01 to $35.00 | 5% |
$35.01 to $75 | 7% |
$75.01 to $150 | 9% |
More than $150 | 12% |
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.
Coffee Rewards Method: In addition to providing coupons, the Bagel Bonus program has decided to expand. It is also awarding free cups of coffee. Based on their prior months total purchases, also provide them with free cups of coffee. If they spend between $25 and $50, they receive a 1 free cup of coffee. If they spend between $50.01 and $100, they receive 2 free cups of coffee. If they spend more than $100.01, they receive 3 free cups of coffee. Report their earned cups of coffee back to them.
Tests: Create two tests to test your methods. Test all possible outputs for both methods. The tests should be done with Junit 5 not 4 or any lower version. This is the assignment i'm very stuck on. I have the code done. I need the Tests. Please help.
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 coffee rewards method, 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 (monthlyTotal < 10)
But use variables instead: if (monthlyTotal < LOW_PURCHASE_RANGE)
Use good variable and method names. Follow the Java naming conventions for all method and variable names.
Secondy, there should be no compound conditions in your if statements. If there are any compound conditions, re-write them. Do no use any && or ||.
The tests should be done with Junit 5. This is the assignment i'm very stuck on.
The code: (I need the tests again JUNIT 5)
import java.util.Scanner;
public class BagelBonusSivakumar {
public static double getDiscountPercentage(double spent) {
final double TWENTY_DOLLARS = 20.0; final double THIRTY_FIVE_DOLLARS = 35.0; final double SEVENTY_FIVE = 75.0; final double ABOVE_150_DOLLARS = 150.0; if (spent <= TWENTY_DOLLARS) return 0.0; else if (spent <= THIRTY_FIVE_DOLLARS) return 5.0; else if (spent <= SEVENTY_FIVE) return 7.0; else if (spent <= ABOVE_150_DOLLARS) return 9.0; else return 12;
}
public static int cupsWon(double spent){
final double $25 = 20.0; final double $50 = 50; final double $100 = 100.0; if(spent<=$25)return 0; else if(spent<=$50)return 1; else if(spent<=$100)return 2; else return 3; }
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); double spent, discountPercentage,disount; int cupsWon =0; System.out.println("Monthly amount spent at the Bagel Shop:"); spent = scanner.nextDouble();
discountPercentage = getDiscountPercentage(spent); disount = discountPercentage*spent/100;
cupsWon = cupsWon(spent);
System.out.printf("You received a discount coupon of $%.2f.(%.1f)%% of your previous" + " month\'s purchase) ",disount,discountPercentage); System.out.println("You have earned "+cupsWon+" cup(s) of coffee.");
} }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started