Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please improve the following code according to the question This code prints the best customer, please improve it so it prints the top customers according

Please improve the following code according to the question image text in transcribed

This code prints the best customer, please improve it so it prints the top customers according to the question : (JAVA)

public static void main(String[] args) { //The input varuables: String CustomerName; double CustomerSales; ArrayList customers = new ArrayList(); //array list for customers' names ArrayList sales = new ArrayList(); //array list for customers' sales

Scanner in = new Scanner(System.in); //A scanner object

// this will be repeated until the user enters zero while (true) {

//prompt user to enter sales System.out.print("Enter Customer's sales: "); //save user's input into this variable CustomerSales = Float.parseFloat(in.nextLine());

if (CustomerSales == 0) { break; } //add users input to the array list sales.add(CustomerSales);

//prompt user to enter customer's name System.out.print("Enter customer's name: "); //Store the input CustomerName = in.nextLine(); //Add the input to the array list customers.add(CustomerName); } String Answer = nameOfBestCustomer(sales, customers); //ensure that the information exist or print a message telling that there is an error if(Answer.isEmpty()) { System.out.println("No information found"); }else { System.out.println("Best customer is: "+Answer); } }

public static String nameOfBestCustomer(ArrayList sales, ArrayList customers) { String FinalResult = ""; //this will execute if the information are valid if (sales.size() > 0) {

double largest = sales.get(0); FinalResult = customers.get(0);

//get the largest sale value and match it with the name for (int i = 1; i

if (sales.get(i) > largest) { largest = sales.get(i); //result store best customer name FinalResult = customers.get(i); } } } return FinalResult; //return best customer }

}

Improve the program from Part 1 so that it displays the top customers, that is, the top customers with the largest sales, where topN is a value that the user of the program supplies. Implement a method public static ArrayList nameOfBestCustomers (ArrayList sales, ArrayList customers, int topN) If there were fewer than topN customers, include all of them

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

Spell out the full name of the compound.

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago