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

Eclipse Java Neon A supermarket wants to reward its best customer of each day, s

ID: 3882755 • Letter: E

Question

Eclipse Java Neon

A supermarket wants to reward its best customer of each day, showing the customer's name on a screen in the supermarket. For the 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.

Heres what I need to use:

public class Store

{

public String nameOfBestCustomer(ArrayList<Double> sales,

ArrayList<String> customers)

{

String top = " ";

// Your work starts here

// Your work ends here

return top;

}

public static void main(String[] args)

{

ArrayList<Double> price = new ArrayList<Double>();

ArrayList<String> names = new ArrayList<String>();

Scanner in = new Scanner(System.in);

// Your work starts here

// Your work ends here

Store top = new Store();

System.out.println("Best customer's name "

+ top.nameOfBestCustomer(price, names));

}

}

Thank you!

Explanation / Answer

public class Store

{

public String nameOfBestCustomer(ArrayList<Double> sales, ArrayList<String> customers)

{

String top = " ";

Iterator s = sales.listIterator();

Iterator c = customers.listIterator();

Double max = 0;

while (c.hasNext() && s.hasNext()) {

String curName = c.next();

Double val = s.next();

if (val > max){

max = val;

top = curName;

}

}

return top;

}

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

ArrayList<Double> price = new ArrayList<Double>();

ArrayList<String> names = new ArrayList<String>();

System.out.println("How many customer data you want to enter ?");

int n = in.nextInt();

for (int i = 0; i < n; i++) {

System.out.println("Add name :");

names.add(in.nextLine());

System.out.println("Add price :");

price.add(Double.parseDouble(in.nextLine()));

}

Store top = new Store();

System.out.println("Best customer's name " + top.nameOfBestCustomer(price, names));

}

}

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