Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Add a private double lowestSales to SalesReporter class, find it and print the related SalesAssociate with lowestSales, and write the method to find the lowestSales.

Add a private double lowestSales to SalesReporter class, find it and print the related SalesAssociate with lowestSales, and write the method to find the lowestSales.

import java.util.Scanner; /** Program to generate a sales report. */ public class SalesReporter { private double highestSales; private double averageSales; private SalesAssociate[] team; //The array object is //created in getData. private int numberOfAssociates; //Same as team.length /** Reads the number of sales associates and data for each one. */ public void getData( ) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter number of sales associates:"); numberOfAssociates = keyboard.nextInt( ); team = new SalesAssociate[numberOfAssociates + 1];//We won't use team[0] for (int i = 1; i <= numberOfAssociates; i++) { team[i] = new SalesAssociate( ); System.out.println("Enter data for associate " + i); team[i].readInput( ); System.out.println( ); } } /** Computes the average and highest sales figures. Precondition: There is at least one salesAssociate. */ public void computeStats( ) { double nextSales = team[1].getSales( ); highestSales = nextSales; double sum = nextSales; for (int i = 2; i <= numberOfAssociates; i++) { nextSales = team[i].getSales( ); sum = sum + nextSales; if (nextSales > highestSales) highestSales = nextSales; //highest sales so far. } averageSales = sum / numberOfAssociates; } /** Displays sales report on the screen. */ public void displayResults( ) { System.out.println("Average sales per associate is $" + averageSales); System.out.println("The highest sales figure is $" + highestSales); System.out.println( ); System.out.println("The following had the highest sales:"); for (int i = 1; i <= numberOfAssociates; i++) { double nextSales = team[i].getSales( ); if (nextSales == highestSales) { team[i].writeOutput( ); System.out.println("$" + (nextSales - averageSales) + " above the average."); System.out.println( ); } } System.out.println("The rest performed as follows:"); for (int i = 1; i <= numberOfAssociates; i++) { double nextSales = team[i].getSales( ); if (team[i].getSales( ) != highestSales) { team[i].writeOutput( ); if (nextSales >= averageSales) System.out.println("$" + (nextSales - averageSales) + " above the average."); else System.out.println("$" + (averageSales - nextSales) + " below the average."); System.out.println( ); } } } public static void main(String[] args) { SalesReporter clerk = new SalesReporter( ); clerk.getData( ); clerk.computeStats( ); clerk.displayResults( ); } }

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_2

Step: 3

blur-text-image_3

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

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

5. Have you stressed the topics relevance to your audience?

Answered: 1 week ago