Write a Java program that prompts for and reads in the name and sales for each o
ID: 3759972 • Letter: W
Question
Write a Java program that
prompts for and reads in the name and sales for each of 5 salespeople in a company;
prints out name and amount of sales for each salesperson and the total sales of all salespersons;
modify the program as follows:
Compute and print the average sale.
Find and print the maximum sale. Print both the name of the salesperson with the max sale and the amount of the sale, e.g., “Salesperson Joes smith had the highest sale with $4500.”
Do the same for the minimTracking Sales
um sale.
After the list, sum, average, max and min have been printed, ask the user to enter a value. Then print the name of each salesperson who exceeded that amount, and the amount of their sales. Also print the total number of salespeople whose sales exceeded the value entered.
Instead of always reading in 5 sales amounts, at the beginning ask the user for the number of sales people.
Explanation / Answer
// *********************
// Sales.java
//
// Reads in and stores sales for each of 5 salespeople. Displays
// sales entered by salesperson id and total sales for all salespeople.
//
// ***********************
import cs1.Keyboard;
public class Sales
{
public static void main(String[] args)
{
final int SALESPEOPLE = 5;
int[] sales = new int[SALESPEOPLE];
int sum;
for (int i=0; i<sales.length; i++)
{
System.out.print("Enter sales for salesperson " + i + ": ");
sales[i] = Keyboard.readInt();
}
System.out.println(" Salesperson Sales");
System.out.println("--------------------");
sum = 0;
for (int i=0; i<sales.length; i++)
{
System.out.println(" " + i + " " + sales[i]);
sum += sales[i];
}
System.out.println(" Total sales: " + sum);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.