Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions