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

In Java use a two-dimensional array to solve the following problem. A company ha

ID: 3770073 • Letter: I

Question

In Java

use a two-dimensional array to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each different type of product sold.

Each slip contains the following:
a) The salesperson number
b) The product number
c) The total dollar value of that product sold that day

Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last month is available. Write a program that will read all this information for last month’s sales and summarize the total sales by salesperson by product. All totals should be stored in the two-dimensional array sales. After processing all the information for last month, print the results in tabular format with each of the columns representing a particular salesperson and each of the rows representing a particular product. Cross total each row to get the total sales of each product for last month; cross total each column to get the total sales by salesperson for last month. Your tabular printout should include these cross totals to the right of the totaled rows and to the bottom of the totaled columns

Explanation / Answer

import java.util.Scanner;
public class Sales2
{
    public void Sales()
    {
        Scanner input = new Scanner(System.in);
        //Sales array data on products sold by salesman
        double sales[][] = new double[5][4];

        System.out.print("Enter sales person number (-1 to end):");
        int person = input.nextInt();

        while (person != -1)
        {
            System.out.print("Enter product number:");
            int product = input.nextInt();
            System.out.print("Enter sales amont:");
            double amount = input.nextDouble();

        //error check input
        if (person >= 1 && person < 5 && product >=1 && product < 6 &&
            amount >= 0)
            sales[product -1][person -1] =+ amount;
       else
            System.out.println("Invalid Input!");

       System.out.print("Enter sales person number(-1 to end):");
       person = input.nextInt();
       }//end while


        //salesperson totals
        double salesPersonTotal[] = new double[4];

        //display data table
        for (int column = 0; column < 4; column ++)
            salesPersonTotal[column] = 0;

        System.out.printf("%8s%14s%14s%14s%14s%10s ",
            "Product", "Salesperson 1", "Salesperson 2","Salesperson 3",
            "Salesperson 4", "Total");


       //Printing a person's sales of a product
       for (int row = 0; row < 5; row ++)
       {
        double productTotal = 0.0;
        System.out.printf("%8d%",(row +1) );
        }

        for ( int column = 0; column < 4; column ++){
            System.out.printf("%14.2f", sales[row][column]);
            productTotal += sales[row][column];
            salesPersonTotal[column] += sales[row][column];
            } //end for loop


        System.out.printf("8%s", "Total");

        for (int colum = 0; column < 4; column ++)
            System.out.printf("14.2%f", salesPersonTotal[column]);

       System.out.println();
    }// end calculations
}// end class sales


public class sales_slips
{
    public static void main(String args[])
    {
        Sales2 application = new Sales2();
        application.Sales();

}//end main
}

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