Question

In: Computer Science

1. Tracking Sales File Sales.java contains a Java program that prompts for and reads in the...

1. Tracking Sales
File Sales.java contains a Java program that prompts for and reads in the sales for each of 5 salespeople in acompany. It then prints out the id and amount of sales for each salesperson and the total sales. Study the code, thencompile 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 thesale, 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 ofeach salesperson who exceeded that amount, and the amount of their sales. Also print the total number ofsalespeople 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 thatthe ids run from 1-5 instead of 0-4. Do not modify the array—just make the information for salesperson 1 reside inarray location 0, and so on.6. Instead of always reading in 5 sales amounts, at the beginning ask the user for the number of sales people andthen create an array that is just the right size. The program can then proceed as before.Example of fixed sale person number.

// ***************************************************************// 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)
    {

   int numSalesPeople;

   Scanner scan = new Scanner (System.in);

   System.out.print ("How many Sales people are there: ");
   numSalesPeople = scan.nextInt();

   
   int[] sales = new int[numSalesPeople];
   int sum;
   int maxSales, minSales;
   int maxSalesPerson, minSalesPerson;
   int amount;
   int numOver;

        sum = 0;
        for (int i=0; i<sales.length; i++)


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

   System.out.println("\nSalesperson   Sales");
   System.out.println("--------------------");
   // Add your code initialize the values of some variables you declared before //
   
   sum=0;
   int max=0;
   int min=0;



   for (int i=0; i<sales.length; i++)
   {
      System.out.println("     " + (i+1) + "\t\t" + sales[i]);
      sum += sales[i];

      
    }
   
   // Add your code. Please print out Sum, Average Sale, MaxSale by Whom, MinSlae by Whom... 


   // Get a value from the user and search for sale person whose sale exceed this value
   System.out.println();
   System.out.print("Enter a sales amount: ");
   amount = scan.nextInt();

   // Add your code here. Search for sales whose value exceed the above value. Print sale person index and amount
   // print the total number of sales person whose sales exceed the above value. 
   
   
   
    }

Solutions

Expert Solution

Sales.java

import java.util.Scanner;

public class Sales
{
public static void main(String[] args)
{

int numSalesPeople;

Scanner scan = new Scanner (System.in);

System.out.print ("How many Sales people are there: ");
numSalesPeople = scan.nextInt();


int[] sales = new int[numSalesPeople];
int sum;
int maxSales, minSales;
int maxSalesPerson, minSalesPerson;
int amount;
int numOver;
  
for (int i=0; i<sales.length; i++)
{
System.out.print("Enter the sales amount for the salesperson " + (i+1) + ": ");
sales[i] = scan.nextInt();
}

System.out.println("\nSalesperson Sales");
System.out.println("--------------------");
// Add your code initialize the values of some variables you declared before //

sum=0;
numOver=0;
maxSalesPerson=0;
minSalesPerson=0;
maxSales=sales[0];
minSales=sales[0];
  

for (int i=0; i<sales.length; i++)
{
System.out.println(" " + (i+1) + "\t\t" + sales[i]);
sum += sales[i];
if(minSales>sales[i])
{
   minSales=sales[i];
   minSalesPerson=i;
  
}
if(maxSales<sales[i])
{
   maxSales=sales[i];
   maxSalesPerson=i;
  
}
  
}

// Add your code. Please print out Sum, Average Sale, MaxSale by Whom, MinSlae by Whom...
System.out.println("The Total sales by all sales person :$"+sum);
System.out.println("The Average Sales is :$"+(double)(sum/numSalesPeople));
System.out.println("Salesperson "+maxSalesPerson+" had the highest sale with $"+maxSales);
System.out.println("Salesperson "+minSalesPerson+" had the lowest sale with $"+minSales);
  

// Get a value from the user and search for sale person whose sale exceed this value
System.out.println();
System.out.print("Enter a sales amount: ");
amount = scan.nextInt();

// Add your code here. Search for sales whose value exceed the above value. Print sale person index and amount
// print the total number of sales person whose sales exceed the above value.
for(int i=1;i<=5;i++)
{
   if(sales[i-1]>amount)
   {
       System.out.println(i+" $"+sales[i-1]);
       numOver++;
   }
     
}
System.out.println("Total number of sales person whose sales exceed $"+amount+" is :"+numOver);


}
}

______________________

Output:

How many Sales people are there: 5
Enter the sales amount for the salesperson 1: 45000
Enter the sales amount for the salesperson 2: 35000
Enter the sales amount for the salesperson 3: 25000
Enter the sales amount for the salesperson 4: 15000
Enter the sales amount for the salesperson 5: 75000

Salesperson Sales
--------------------
1       45000
2       35000
3       25000
4       15000
5       75000
The Total sales by all sales person :$195000
The Average Sales is :$39000.0
Salesperson 4 had the highest sale with $75000
Salesperson 3 had the highest sale with $15000

Enter a sales amount: 30000
1 $45000
2 $35000
5 $75000
Total number of sales person whose sales exceed $30000 is :3

_________Thank You


Related Solutions

1. Write a program that prompts the user for a filename, then reads that file in...
1. Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba Need Help with this be done in only PERL. Please use "reverse"
C++ Write a program that prompts for a file name and then reads the file to...
C++ Write a program that prompts for a file name and then reads the file to check for balanced curly braces, {; parentheses, (); and square brackets, []. Use a stack to store the most recent unmatched left symbol. The program should ignore any character that is not a parenthesis, curly brace, or square bracket. Note that proper nesting is required. For instance, [a(b]c) is invalid. Display the line number the error occurred on. These are a few of the...
Write a JAVA program that reads a text file. Text file contains three lines. Place each...
Write a JAVA program that reads a text file. Text file contains three lines. Place each line in an array bucket location. Add to the end of the array list. Print the array.
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code. Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code.   Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
Question: Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user...
Question: Write a program in python that reads in the file climate_data_2017_numeric.csv and prompts the user to enter the name of a field (other than Date), and then outputs the highest and lowest values recorded in that field for the month of August. The file climate_data_2017_numeric.csv contains the following fields: Date Minimum temperature (C) Maximum temperature (C) Rainfall (mm) Speed of maximum wind gust (km/h) 9am Temperature (C) 9am relative humidity (%) 3pm Temperature (C) 3pm relative humidity (%) Expected...
Write a Java program that prompts for and reads the number N of cities or locations...
Write a Java program that prompts for and reads the number N of cities or locations to be processed. It then loops N times to prompt for and read, for each location, the decimal latitude, decimal longitude, and decimal magnetic declination. It then computes and displays, for each location, the Qibla direction (or bearing) from Magnetic North. The true bearing from a point A to a point B is the angle measured in degrees, in a clockwise direction, from the...
Create a Python program that: Reads the content of a file (Vehlist.txt) The file contains matching...
Create a Python program that: Reads the content of a file (Vehlist.txt) The file contains matching pairs of vehicle models and their respective makes Separate out the individual make and model on each line of the file Add the vehicle make to one list, and the vehicle model to another list; such that they are in the same relative position in each list Prompt the user to enter a vehicle model Search the list containing the vehicle models for a...
Module 1 Program Write a complete Java program in a file called Module1Program.java that reads all...
Module 1 Program Write a complete Java program in a file called Module1Program.java that reads all the lyrics from a file named lyrics.txt that is to be found in the same directory as the running program. The program should read the lyrics for each line and treat each word as a token. If the line contains a double (an integer is also treated as a double) it should use the first double it finds in line as the timestamp for...
Java Program that prompts the user and reads in an integer between 0 to 50, inclusively....
Java Program that prompts the user and reads in an integer between 0 to 50, inclusively. If the entered value is outside the range, program’s output will display the following message: “Error: the entered number is out of range”, and continually re-prompts the user to enter the integer again until the user enters a valid integer. • Once a valid integer has been entered, program prompts the user and reads in a second integer between -5 to 20, inclusively. If...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT