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 port does rdp use by default and from what range of numbers should you select a private port number?
VARVARA [1.3K]
The default RDP port is 3389 but can be configured in the range of <span>49152-65538</span>
5 0
3 years ago
You want to add a new Product and Services entry to your client's QuickBooks Online company. The service is installation of a se
Kisachek [45]

Answer:  

The correct answer is Option 3: "Select Service"  

You have to select "Service" in the Second Step.  

Only after that, you'll be able to name the Service in the following step.  

Other options are invalid for a given question.

6 0
2 years ago
Who likes sandshrew ​
zvonat [6]

Answer:

sandshrew is a cute character in pokemon

6 0
3 years ago
What is the value of the variable phones after the execution of the following code? phones = {'John': '5555555', 'Julie' : '7777
uysha [10]

Answer:

phones = {'John': '1234567', 'Julie' : '7777777'}

Explanation:

In the code given in the question phones dictionary contains contains two keys John and Julie and have the values '5555555' and '7777777' respectively. Now in the code the key John in the dictionary phones is assigned the value '1234567' .So the value corresponding to the key John becomes '1234567'.

3 0
3 years ago
Which of the following statements is CORRECT? a. Multiple IRRs can occur only if the signs of the cash flows change more than on
BigorU [14]

Answer: i think the answer is

a. Multiple IRRs can occur only if the signs of the cash flows change more than once.

Explanation:

3 0
2 years ago
Other questions:
  • _____ consists of the instructions that direct the operation of the computer system and enable users to perform specific tasks,
    15·1 answer
  • Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all th
    11·1 answer
  • Help me with this, please. Are vacuum cleaners, Cd players, and telephones considered computers? Do they store any data or proce
    8·2 answers
  • A ____ is a statement specifying the condition(s) that must be true before the function is called.
    6·1 answer
  • Write a program using for loop to find the cube of numbers from 50-100 <br> FASTT
    11·1 answer
  • Jackie is planning a surprise birthday party for her best friend and is researching a location to have the party. Jackie found a
    6·1 answer
  • Tiền tệ ra đời là kết quả
    7·2 answers
  • Please help I’ll give 10 points
    6·1 answer
  • What is the first phase of the project process?
    14·2 answers
  • Sftp uses which mechanism to provide security for authentication and data transfer?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!