Question

In: Computer Science

Using Java language (in program NetBeans). 1) Using a 2 dimensional array Your company has 4...

Using Java language (in program NetBeans).

1) Using a 2 dimensional array

Your company has 4 grocery stores. Each store has 3 departments where product presentation affects sales (produce, meat, frozen). Every so often a department in a store gets a bonus for doing a really good job.

You need to create a program that keeps a table of bonuses in the system for departments. Create a program that has a two dimensional array for these bonuses. The stores can be the rows and the departments can be the columns. Have the program ask the user three times for a bonus amount, grocery store number (1-4), and department number (1-3) and add the bonus amount to the appropriate place in the array based on the numbers they gave. After this is done, add up the bonuses for each of the 4 stores [the 4 rows in your 2 dimensional array] and display them for the user.

Solutions

Expert Solution

/* Java program to add bonuses to deparment of stores*/                                                           

/* import packeges and necessary classs */
import java.util.Scanner;

/* Java class */
public class Main{
        /* Driver method */
        public static void main(String[] args){
                /* declare object(s) */
                Scanner sc = new Scanner(System.in);
                
                /* declare & initialize variable(s) */
                double bonuses[][] = new double[4][3];
                double bonus_amount = 0, sum = 0;
                int store_no = 0, dept_no = 0;
                
                /* Take input(s) */
                System.out.print("Enter bonus amount: ");
                bonus_amount = sc.nextDouble();
                System.out.print("Enter grocery store no (1 - 4): ");
                store_no = sc.nextInt();
                System.out.print("Enter department no (1 - 3): ");
                dept_no = sc.nextInt();
                
                /* add bonus amount to appropriate place */
                bonuses[store_no - 1][dept_no - 1] = bonus_amount;
                
                /* add up the bonuses for each of the 4 stores */
                /* display bonuses */
                for(int i = 0; i < 4; i++){
                        sum = 0;
                        for(int j = 0; j < 3; j++)
                                sum += bonuses[i][j];
                        System.out.println("Store "+(i+1)+" bonuses: "+sum);
                }
        }
}

___________________________________________________________________

___________________________________________________________________

Enter bonus amount: 2000
Enter grocery store no (1 - 4): 3
Enter department no (1 - 3): 3
Store 1 bonuses: 0.0
Store 2 bonuses: 0.0
Store 3 bonuses: 2000.0
Store 4 bonuses: 0.0

___________________________________________________________________


Note: If you have queries or confusion regarding this question, please leave a comment. I would be happy to help you. If you find it to be useful, please upvote.


Related Solutions

JAVA LANGUAGE Write a program that declares a 2-Dimensional Array with 4 rows and 4 columns...
JAVA LANGUAGE Write a program that declares a 2-Dimensional Array with 4 rows and 4 columns to store integer values, and then: fill elements with values as the sum of its column index and row index, e.g., the element at row index 0 and column index 0 is (0+0=0), the element at row index 0 and column index 1 is (0+1=1). compute the sum of elements at the second row. compute the sum of elements at the third column. compute...
In Java please Your program will sort a two dimensional array (5 * 4) based on...
In Java please Your program will sort a two dimensional array (5 * 4) based on the following: The entire array should be sorted using bubble sort based on the 1st column in ascending order and display the entire array. Reset the array to its original contents. The entire array should again be sorted using selection sort based on the 2nd column in descending order and display the entire array. Reset the array to its original contents. The entire array...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
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...
Question 2. Write a complete C++ program that uses a 2-dimensional array with 4 rows and...
Question 2. Write a complete C++ program that uses a 2-dimensional array with 4 rows and 30 columns. Row represents sections of a course and column represents the students, value inside each position of the array is the final exam grade for each students. Fill the array with random numbers between 40 and 100. Calculate the total, average, maximum, minimum for each section. Please do it simple. code
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...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. Your program should output all the values in the array and then output the average high and the average low. im trying to...
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers...
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers as follows: Assign {35,20,-43,-10,6,7,13} -Create a one dimensional array of 7 Boolean values as follows: Assign {true,false,false,true,false,true,false} -Create a one dimensional array of 7 floating-point values as follows: Assign {12.0f,1.5f,-3.5f,-2.54f,3.4f,45.34f,22.13f} -Declare sum as integer and set it to 0. -Declare sumf as float and set it to 0.0f. -Use a for loop to go through each element of the Boolean array, and if an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT