Question
Solve problem P7.13 and test using JUnit to validate the results using a series of increasingly more complex tests. The menu and processing user input
Solve problem P7.13 and test using JUnit to validate the results using a series of increasingly more complex tests. The menu and processing user input should be part of your program but does not have to be in your test suite.
P7.13
A supermarket wants to reward its best customer of each day, showing the customers name on a screen in the supermarket.
For that purpose, the store keeps an ArrayList
In the Store class, implement methods public void addSale(String customerName, double amount) public String nameOfBestCustomer() to record the sale and return the name of the customer with the largest sale.
Write a program that prompts the cashier to enter all prices and names, adds them to a Store object, and displays the best customers name. Use a price of 0 as a sentinel.
===============================================================================================
(JUNIT TEST?) import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; class SupermarketTest { @Test void emptyList() { Supermarket market=new Supermarket(); assertEquals("",market.nameOfBestCustomer()); } @Test void listOfOne() { Supermarket market=new Supermarket(); market.addSale("Alice",100.0); assertEquals("Alice",market.nameOfBestCustomer()); } @Test void listOfTwo() { Supermarket market=new Supermarket(); market.addSale("Alice",100.0); market.addSale("Bob",123.45); assertEquals("Bob",market.nameOfBestCustomer()); } @Test void listOfThree() { Supermarket market=new Supermarket(); market.addSale("Alice",100.0); market.addSale("Bob",123.45); market.addSale("Charlie",25.00); assertEquals("Bob",market.nameOfBestCustomer()); } }
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