Answer:
import java.util.Scanner;
public class Sales
{
public static void main(String[] args) {
int sum;
Scanner input = new Scanner(System.in);
System.out.print("Enter number of salespeople: ");
int salespeople = input.nextInt();
int[] sales = new int[salespeople];
for (int i=0; i<sales.length; i++)
{
System.out.print("Enter sales for salesperson " + (i+1) + ": ");
sales[i] = input.nextInt();
}
System.out.println("\nSalesperson Sales");
System.out.println("--------------------");
sum = 0;
int maxSale = sales[0];
int minSale = sales[0];
int minId=1;
int maxId=1;
for (int i=0; i<sales.length; i++)
{
System.out.println(" " + (i+1) + " " + sales[i]);
sum += sales[i];
if(maxSale < sales[i])
{
maxSale = sales[i];
maxId = i+1;
}
if(minSale > sales[i])
{
minSale = sales[i];
minId = i+1;
}
}
System.out.println("Total sales: " + sum);
System.out.println("The average sale is: " + sum / salespeople );
System.out.println("Salesperson "+ maxId + " had the highest sale with "+ maxSale + ".");
System.out.println("Salesperson "+ minId + " had the lowest sale with "+ minSale + ".");
int amount = 0;
int counter = 0;
System.out.print("Enter an amount: ");
amount = input.nextInt();
for (int i=0; i<sales.length; i++)
{
if(sales[i] > amount) {
counter++;
System.out.println("Salesperson "+ (i+1) + " exceeded given amount. (Number of sales: " + sales[i] +")");
}
}
System.out.println("Number of salespeople exceeded given amount is: "+ counter);
}
}
Explanation:
- Ask the user for the number of salesperson
- According to entered number, create an array called sales to hold sale number for each person
- In the first for loop, assign the given sales numbers
- In the second for loop, print all the sales people with sales, calculate the total sales. Also, find the minimum and maximum sales numbers with associated individuals.
- Print total, average, highest, and lowest sales.
- Ask user enter an amount
- In the third for loop, find the sales people who exceeded this amount.
- Print number of sales people who exceeded the amount.