Create an array to hold the IDs int of 10 sales employees Th

Create an array to hold the ID’s (int) of 10 sales employees. Then create an array to hold the sales amounts for each employee that will parallel the array of IDs.

Write a loop to read in (Scanner) data for both arrays. (what type of loop is this?)

Write a second loop to display the data from both arrays lined up with column headings.

ID      Sales

2121   $3456

        2235   $5324

highestSales(): Method that accepts ID array and Sales array to find which salesperson had the highest sales. Print the employee’s ID and sales amount.

lowestSales(): Method that accepts ID array and Sales array to find which salesperson had the lowest sales. Print the employee’s ID and sales amount.

averageSales(): Method that takes in the Sales array and returns and prints the average sales record.

In main, print the IDs of the salespeople who have below average sales and print the IDs of the salespeople who have above average sales.

searchID(): Method accepts the ID array, Sales array and the target ID that needs to be searched (Accept the ID to be searched from the user in Main and pass it as input). Search the ID array for that target ID and then print the ID and the sales for that salesperson. If the ID is not present in the array of IDs print a message stating the search ID was not found.

In this program you will use two arrays in parallel and perform some useful tasks that can be done using arrays. Create an array to hold the ID\'s (int) of 10 sales employees. Then create an array to hold the sales amounts for each employee that will parallel the array of IDs. Write a loop to read in (Scanner) data for both arrays, (what type of loop is this?) Write a second loop to display the data from both arrays lined up with column headings. IDSales highest Sales (): Method that accepts ID array and Sales array to find which salesperson had the highest sales. Print the employee\'s ID and sales amount. lowestSales (): Method that accepts ID array and Sales array to find which salesperson hed th elowest sales. Print the employee\'s ID and sales amount. averageSales(): Method that takes in the Sales array and returns and prints the average sales record. In main, print the IDs of the salespeople who have below average sales and print the IDs of the salespeople who have above average sales. searchiD (): Method accepts the ID array, Sales array and the target ID that needs to be searched (Accept the ID to be searched from the user in Main and pass it as input). Search the ID array for that target ID and then print the ID and the sales for that salesperson. If the ID is not present in the array of IDs print a message stating the search ID was not found.

Solution

// java code EmployeeSale.java

import java.util.Scanner;

public class EmployeeSale
{

    public static void lowestSales( int Id[], int[] sales)
    {
        int min = 0;
        for (int i = 1; i < sales.length; i++)
        {
            if (sales[i] < sales[min])
            {
                min = i;
            }
        }
        System.out.println(\"\ Minimum Sale:\");
        System.out.println(\"Employee ID: \" + Id[min]);
        System.out.println(\"Sales Amount: \" + sales[min]);
    }

    public static void highestSales( int Id[], int[] sales)
    {

        int max = 0;
        for (int i = 1; i < sales.length; i++)
        {
            if (sales[i] > sales[max])
            {
                max = i;
            }
        }
        System.out.println(\"\ Maximum Sale:\");
        System.out.println(\"Employee ID: \" + Id[max]);
        System.out.println(\"Sales Amount: \" + sales[max]);
    }

    public static double averageSale(int[] sales)
    {

        double mean = 0.0;
        for (int i = 0; i < sales.length; i++)
        {
            mean = mean + sales[i];
        }
      
        return mean/(sales.length);
    }

    public static void searchID( int Id[], int[] sales, int search)
    {

        for (int i = 0; i < sales.length; i++)
        {
            if (Id[i] == search)
            {
                System.out.println(\"Employee found\");
                System.out.println(\"Employee ID: \" + Id[i]);
                System.out.println(\"Sales Amount: \" + sales[i] + \"\ \");
                return;
            }
        }
      
        System.out.println(\"Employee not found\ \");
    }


    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);

        int employee = 10;
        int[] Id = new int[employee];
        int[] sales = new int[employee];

        for (int i = 0; i < sales.length; i++)
        {
           System.out.print(\"Enter employee \" + (i+1) + \" id: \");
           Id[i] = scan.nextInt();
           System.out.print(\"Enter sales amount: \");
           sales[i] =scan.nextInt();

           System.out.println();
        }

        System.out.println(\"\ ID\\tSales\ \");
        for (int i = 0; i < sales.length; i++)
        {
           System.out.println(Id[i] + \"\\t$\" + sales[i]);
        }

        System.out.println();
        highestSales(Id,sales);
        lowestSales(Id,sales);

        double avg = averageSale(sales);
        System.out.print(\"\ Above averageSale ID:\");
        for (int i = 0; i < sales.length ;i++ )
        {
            if(sales[i] > avg)
                System.out.print(Id[i] + \" \");  
        }
        System.out.println(\"\ \");
        System.out.print(\"Below averageSale ID:\");
        for (int i = 0; i < sales.length ;i++ )
        {
            if(sales[i] < avg)
                System.out.print(Id[i] + \" \");  
        }
        System.out.println(\"\ \");

        System.out.print(\"Enter an ID tp search: \");
        int search = scan.nextInt();
        searchID(Id,sales,search);
    }

}

/*
output:

Enter employee 1 id: 1
Enter sales amount: 234

Enter employee 2 id: 2
Enter sales amount: 345

Enter employee 3 id: 3
Enter sales amount: 765

Enter employee 4 id: 4
Enter sales amount: 654

Enter employee 5 id: 5
Enter sales amount: 987

Enter employee 6 id: 6
Enter sales amount: 345

Enter employee 7 id: 7
Enter sales amount: 589

Enter employee 8 id: 8
Enter sales amount: 189

Enter employee 9 id: 9
Enter sales amount: 481

Enter employee 10 id: 10
Enter sales amount: 590


ID Sales

1   $234
2   $345
3   $765
4   $654
5   $987
6   $345
7   $589
8   $189
9   $481
10 $590


Maximum Sale:
Employee ID: 5
Sales Amount: 987

Minimum Sale:
Employee ID: 8
Sales Amount: 189

Above averageSale ID:3 4 5 7 10

Below averageSale ID:1 2 6 8 9

Enter an ID tp search: 5
Employee found
Employee ID: 5
Sales Amount: 987

*/

Create an array to hold the ID’s (int) of 10 sales employees. Then create an array to hold the sales amounts for each employee that will parallel the array of I
Create an array to hold the ID’s (int) of 10 sales employees. Then create an array to hold the sales amounts for each employee that will parallel the array of I
Create an array to hold the ID’s (int) of 10 sales employees. Then create an array to hold the sales amounts for each employee that will parallel the array of I
Create an array to hold the ID’s (int) of 10 sales employees. Then create an array to hold the sales amounts for each employee that will parallel the array of I

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site