Question

In: Computer Science

In JAVA Use a two-dimensional array to solve the following problem: A company has four salespeople...

In JAVA

Use a two-dimensional array to solve the following problem:

A company has four salespeople - Sales Person 1, Sales Person 2, Sales Person 3, and Sales Person 4.

The company sells 5 products - Product 1, Product 2, Product 3, Product 4, and Product 5.

Each day, a sales person hands in a slip with the following information: Sales Person Number (1,2,3, or 4), Product Number (1,2,3,4, or 5), and dollar value of that product sold. This dollar value should be entered in the appropriate place in the multi-dimensional array with rows representing sales person (1-4) and columns representing products (1-5). Keep asking for data input until -1 is entered for the sales person number (sentinel).

Output: Your output should reflect the array in tabular format ALONG with cross-sectional totals. For example, your program should look something like this:

Enter Sales Person Number (1-4) or -1 to quit and view data:

1

Enter the Product Number (1-5):

1

Enter the dollar value:

1000

Enter Sales Person Number (1-4) or -1 to quit and view data:

2

Enter the Product Number (1-5):

1

Enter the dollar value:

2000

Enter Sales Person Number (1-4) or -1 to quit and view data:

2

Enter the Product Number (1-5):

2

Enter the dollar value:

500

Enter Sales Person Number (1-4) or -1 to quit and view data:

-1

Sales Person      Product 1     Product 2    Product 3   Product 4    Product 5    Sales Person Totals

              1            1000                 0                   0                  0            0                          1000

              2            2000             500                   0                  0              0                          2500

              3                  0                 0                   0                  0              0                               0

              4                  0                 0                   0                  0              0                               0

_____________________________________________________________________________

Product Totals    3000              500                   0                  0              0

Solutions

Expert Solution

Hi Student, I have created the below JAVA code fulfiling the requirements you have asked for in the question.

import java.util. * ;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System. in );
    int[][] dollarvalue = new int[4][5];
    int input = 0;
    while (true) {
      System.out.println("Enter Sales Person Number (1-4) or -1 to quit and view data:");
      input = sc.nextInt();
      if (input == -1) {
        break;
      }
      System.out.println("Enter the Product Number (1-5):");
      int inputproduct = sc.nextInt();
      System.out.println("Enter the dollar value:");
      int inputvalue = sc.nextInt();
      dollarvalue[input - 1][inputproduct - 1] = inputvalue;
    }
    System.out.println("Sales Person    Product 1   Product 2   Product 3   Product 4   Product 5   Sales Person Totals");
    for (int i = 0; i < 4; i++) {
      int sum = 0;
      System.out.print((i + 1) + "  ");
      for (int j = 0; j < 5; j++) {
        System.out.print(dollarvalue[i][j] + "  ");
        sum = sum + dollarvalue[i][j];
      }
      System.out.print(sum);
      System.out.println();
    }
    System.out.println("--------------------------------------------------------------------------");
    System.out.println("Product Totals    ");
    for (int j = 0; j < 5; j++) {
      int sum = 0;
      for (int i = 0; i < 4; i++) {

        sum = sum + dollarvalue[i][j];
      }
      System.out.print(sum + "  ");
    }
  }
}

Hope it helps. Thanks!


Related Solutions

Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to fill the 2-dimensional array with (random numbers, range 0 - 30). The array has rows (ROW) and columns (COL), where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5....
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to find...
Write a Java program that will use a two-dimensional array to solve the following tasks: 1....
Write a Java program that will use a two-dimensional array to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5. Create a...
problem 1 (Duplicate Elimination) code in JAVA please Use a one-dimensional array to solve the following...
problem 1 (Duplicate Elimination) code in JAVA please Use a one-dimensional array to solve the following problem: Write an application that inputs ten numbers, each between 10 and 100, both inclusive. Save each number that was read in an array that was initialized to a value of -1 for all elements. Assume a value of -1 indicates an array element is empty. You are then to process the array, and remove duplicate elements from the array containing the numbers you...
(C programming) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each...
(C programming) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it’s not a duplicate of a number already read. Provide for the “worst case” in which all 20 numbers are different. Use the smallest possible array to solve this problem. Your solution must include a function called isUnique() that returns 1 (true) if the number input is...
In JAVA, Describe a scenario in which you would use a four-dimensional array. Clearly explain the...
In JAVA, Describe a scenario in which you would use a four-dimensional array. Clearly explain the purpose of each dimension of the array in that scenario.
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
Solve the following problem using the simplex method. If the problem is two dimensional, graph the...
Solve the following problem using the simplex method. If the problem is two dimensional, graph the feasible region, and outline the progress of the algorithm. Max               Z = 5X1 + 3X2 + 2X3 Subject to    4X1 + 5X2 + 2X3 + X4≤ 20                      3X1 + 4X2 - X3 + X4≤ 30                       X1, X2, X3, X4 ≥ 0   
Create a game of Connect Four using a two dimensional array (that has 6 rows and...
Create a game of Connect Four using a two dimensional array (that has 6 rows and 7 columns) as a class variable. It should be user friendly and be a two person game. It should have clear directions and be visually appealing. The code MUST have a minimum of 3 methods (other than the main method). The player should be able to choose to play again. **Code must be written in Java**
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT