Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** * A supermarket wants to reward its best customer of each day, showing the customer's name on a screen in the * supermarket. For

/**  * A supermarket wants to reward its best customer of each day, showing the customer's 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 customer's  * name. Use a price of 0 as a sentinel.  */ import java.util.ArrayList; import java.util.Scanner; public class supermarket_customer { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); // creating keyboard for input  String customerName = ""; double amount = 1; int end = 1; ArrayList price = new ArrayList(); // making an arraylist for price  ArrayList names = new ArrayList(); // making an arraylist for names   System.out.println("How many customers' info do you want to input?"); int x = keyboard.nextInt(); for (int i = 0; i < x; i++) { System.out.println("How much did they spend at the supermarket?"); amount = keyboard.nextDouble(); price.add(amount); System.out.println("Next:"); System.out.println("What is the Customer's Name?"); customerName = keyboard.nextLine(); names.add(customerName); } double highestSale = 0; int spacing = 0; String bestCustomer = ""; // Finding the highest spending customer  for (int i = 0; i < price.size(); i++) { double sale = price.get(i); if (sale > highestSale) { highestSale = sale; spacing = i; } } bestCustomer = names.get(spacing); supermarket_customer highest = new supermarket_customer(); System.out.println("Best customer's name "+ bestCustomer); } } 

output:

This code does not let me input the customer's name but I am not sure why...

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

Focus On Geodatabases In ArcGIS Pro

Authors: David W. Allen

1st Edition

1589484452, 978-1589484450

More Books

Students also viewed these Databases questions

Question

=+ What topics are contained in the contracts?

Answered: 1 week ago

Question

=+Are they specific or general in nature?

Answered: 1 week ago