Question: Problem: 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

Problem:

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 type of product sold. Each slip contains the following:

  • The salesperson number
  • The product number
  • 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 the slips for last month is available. Write an application that will read all this information for last months sales and summarize the total sales by salesperson and by product. All totals should be stored in the two-dimensional array sales. After processing all the information for last month, display the results in tabular format, with each column representing a salesperson and each row 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 output should include these cross-totals to the right of the totaled rows and to the bottom of the totaled columns.

I keep getting an error, what do I need to fix?

What I have:

import java.util.Scanner; public class TotalSales { public static void main (String[] args) { Scanner input = new Scanner(System.in); double sales[][] = new double[5][4]; double salespersonTotal[] = new double[4]; System.out.print("Enter the salesperson number (1-4) or enter -1 to finish: "); int salesperson = input.nextInt(); while (salesperson != -1) { System.out.print("Enter the product number (1-5):"); int product = input.nextInt(); System.out.print("Enter the total dollar value of that product sold that day:"); double dollarValue = input.nextDouble(); System.out.print(" "); if (salesperson >= 1 && salesperson <= 4 && product >=1 && product <= 5 && dollarValue >= 0) sales[product -1][salesperson -1] =+ dollarValue; else System.out.println("The input is not valid!");

System.out.print("Enter the salesperson number (1-4) or enter -1 to finish: "); salesperson = input.nextInt(); } 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"); for (int row = 0; row < 5; row ++) { System.out.printf("%8d%",(row +1) ); double productTotal = 0.0; for ( int column = 0; column < 4; column ++) { System.out.printf("%14.2f", sales[row][column]); productTotal += sales[row][column]; salespersonTotal[column] += sales[row][column]; } } System.out.printf("8%s", "Total"); for (int column = 0; column < 4; column ++) System.out.printf("14.2%f", salespersonTotal[column]); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!