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

File Sales.java contains a Java program that promptsfor and reads in the sales f

ID: 3617787 • Letter: F

Question

File Sales.java contains a Java program that promptsfor and reads in the sales for each of 5 salespeople in a company.It then prints out the id and amount of sales for each salespersonand the total sales. Study the code, then compile and run theprogram to see how it works. Now modify the program as follows:

1.      Compute and print the averagesale. (You can compute this directly from the total; no loop isnecessary.)

2.      Find and print the maximum sale.Print both the id of the salesperson with the max sale and theamount of the sale, e.g., "Salesperson 3 had the highest sale with$4500." Note that you don't need another loop for this; you can doit in the same loop where the values are read and the sum iscomputed.

3.      Do the same for the minimumsale.

4.      After the list, sum, average, maxand min have been printed, ask the user to enter a value. Thenprint the id of each salesperson who exceeded that amount, and theamount of their sales. Also print the total number of salespeoplewhose sales exceeded the value entered.

5.      The salespeople are objecting tohaving an id of 0—no one wants that designation. Modify yourprogram so that the ids run from 1–5 instead of 0–4.Do not modify the array—just make theinformation for salesperson 1 reside in array location 0, and soon.

6.      Instead of always reading in 5sales amounts, at the beginning ask the user for the number ofsales people and then create an array that is just the right size.The program can then proceed as before.


HERES HOW FARIVE GOTTEN>

//****************************************************************
// Sales.java
//
// Reads in and stores sales for each of 5 salespeople. Displays
// sales entered by salesperson id and total sales for allsalespeople.
//
//****************************************************************
import java.util.Scanner;

public class Sales
{
    public static void main(String[] args)
    {
       final int SALESPEOPLE =5;
       int[] sales = newint[SALESPEOPLE];
       int sum;
       int max = sales[0];
       int min = sales[0];

       Scanner scan = newScanner(System.in);

       for (int i=0;i<sales.length; i++)
        {
           System.out.print("Enter sales for salesperson " + i + ":");
           sales[i] =scan.nextInt();
        }

       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];

           if(sales[i] > max)
           {
              max = sales[i];
              int max_id = i+1;


           }
           if(sales[i] < min)
           {
              min = sales[i];
              int min_id = i+1;


           }

           System.out.println("The max sale is: " + max);
           System.out.println("The min sale is: " + min);
           System.out.println("The person with the max sales is: " +max_id);
           System.out.println("The person with the minimum sales is: " +min_id);
           System.out.println("The total sales is: " + sum);
           System.out.println("The average sales is: " +(sum/SALESPEOPLE));
       }
   }
}


Explanation / Answer

x.Xlor="red">please rate - thanks parts 1-5 // **************************************************************** // 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 java.util.Scanner; public class Sales {     public static void main(String[] args)     {        final int SALESPEOPLE = 5;         int[] sales = new int[SALESPEOPLE];         int sum;         int max = sales[0];         int min = sales[0];         int max_id=0,min_id=0,val,greater=0;         Scanner scan = new Scanner(System.in);         for (int i=0; i
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