1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Flauer [41]
3 years ago
8

File Sales.java contains a Java program that prompts for 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 salesperson and the total sales. Study the code, then compile and run the program to see how it works. Now modify the program as follows:
1. Compute and print the average sale. (You can compute this directly from the total; no loop is necessary.)
2. Find and print the maximum sale. Print both the id of the salesperson with the max sale and the amount 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 do it in the same loop where the values are read and the sum is computed.
3. Do the same for the minimum sale.
4. After the list, sum, average, max and min have been printed, ask the user to enter a value. Then print the id 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.
5. The salespeople are objecting to having an id of 0—no one wants that designation. Modify your program so that the ids run from 1-5 instead of 0-4. Do not modify the array—just make the information for salesperson 1 reside in array location 0, and so on.
6. Instead of always reading in 5 sales amounts, at the beginning ask the user for the number of salespeople and then create an array that is just the right size. The program can then proceed as before.

// ***************************************************************
// 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;
Scanner scan = new Scanner(System.in);
for (int i=0; i {
System.out.print("Enter sales for salesperson " + i + ": ");
sales[i] = scan.nextInt();
}
System.out.println("\nSalesperson Sales");
System.out.println(" ------------------ ");
sum = 0;
for (int i=0; i {
System.out.println(" " + i + " " + sales[i]);
sum += sales[i];
}
System.out.println("\nTotal sales: " + sum);
}
}
Computers and Technology
1 answer:
myrzilka [38]3 years ago
8 0

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.

You might be interested in
What is a transducer? A. an energy-converting device B. a sensing device C. a robot movement D. a signal display unit
frosja888 [35]

Answer:

Transducer is a device that can convert an electronic controller output signal into a standard pneumatic output.

So our answer would be A

8 0
3 years ago
Consider the definition in OCaml
xenn [34]

Answer:

The type of b is bool ( B )

The type of c is int ( C )

The type of d is int ( D )

Explanation:

The options that must hold zero are: The type of b is bool,The type of d is int and The type of c is int.

If b is true then c or d is true because c and d are int. this is because b been a true/false means that d and c are boolean int. because d and c are assigned to integers  

8 0
3 years ago
HELP ASAP
CaHeK987 [17]
The answer is B, e commerce. Have a good day
3 0
3 years ago
NEED HELP ASAP! Which field best organizes street addresses in a database?
pickupchik [31]

Answer:

name

Explanation:

5 0
3 years ago
Read 2 more answers
Câu 4. Trong môi trường lập trình CodeBlocks phím F9 dùng để: A. Biên dịch chương trình B. Chạy chương trình C. Soạn thảo chương
Debora [2.8K]

Answer:

câu trả lời là c nha

Explanation:

7 0
3 years ago
Other questions:
  • Array elements must be ________ before a binary search can be performed.
    8·1 answer
  • Which of the following are potential drawbacks to the Internet in regard to politics? Select all that apply. Overexposure of can
    10·2 answers
  • Which of these is a way of making applications less vulnerable to hacking?
    7·2 answers
  • What is the best free website to learn phyton programming
    5·1 answer
  • Determine the number of character comparisons made by the brute-force algorithm in searching for the pattern GANDHI in the text
    7·1 answer
  • Please say me the answer fast its really urgent........ ​
    12·1 answer
  • Consider some of the widespread global issues that we face here on Earth and briefly describe them. Then, choose one of the spac
    8·1 answer
  • What is the recipe for enchanting table?
    14·2 answers
  • Which of these would make text on a slide difficult to read?
    7·1 answer
  • Which word did alexander graham bell want adopted as a telephone greeting instead of hello.
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!