Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I need help with the following question: A supermarket wants to reward it

ID: 3763949 • Letter: H

Question

Hello, I need help with the following question:

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<Customer>. 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.

Explanation / Answer

import java.util.*;
class Store
{
  
   public ArrayList<String> Customer=new

ArrayList();
   public double[] sale=new double[100];
   public static int c=0;

   public void addSale(String customername, double

amount)
   {
       Customer.add(customername);
       sale[c]=amount;      
       c++;
   }

   public String nameOfBestCustomer()
   {
       int i,ind=0;
       double max=0;
       for(i=0;i<=c;i++)
       {
           if(sale[i]>max)
           {
               max=sale[i];
               ind=i;
           }
       }
       return Customer.get(ind);
   }

}

class Bestcustomer
{
   public static void main(String args[])
   {
       Scanner scan=new Scanner(System.in);
       Store o = new Store();
       char ans='y';
       String n;
       double s;
       while(ans=='y')
       {
                      

           System.out.println("Enter

Customer name");
           n=scan.nextLine();
           System.out.println("Enter

Sale");
           s=scan.nextDouble();

           o.addSale(n,s);
           System.out.println("Add

more Customer[y/n]");
           ans=scan.next().charAt(0);
       }
       String cname=o.nameOfBestCustomer

();
       System.out.println("Best Customer is

"+cname);
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote