Answered step by step
Verified Expert Solution
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
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