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

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...
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 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...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the...
Programming Language: JAVA In this assignment you will be sorting an array of numbers using the bubble sort algorithm. You must be able to sort both integers and doubles, and to do this you must overload a method. Bubble sort work by repeatedly going over the array, and when 2 numbers are found to be out of order, you swap those two numbers. This can be done by looping until there are no more swaps being made, or using a...
this a continuation of my previous question. answer with Java programming language and Netbeans idk 1,...
this a continuation of my previous question. answer with Java programming language and Netbeans idk 1, 2, 3, 4) CODE class Device { private String serialNumber, color, manufacturer; private double outputPower; public Device () { serialNumber = ""; color = ""; manufacturer = ""; outputPower = 0.0; } public Device(String serialNumber, String color, String manufacturer, double outputPower) { this.serialNumber = serialNumber; this.color = color; this.manufacturer = manufacturer; this.outputPower = outputPower; } public String getSerialNumber() { return serialNumber; } public void...
Using JAVA Write a program that uses a 2-D array to store the highest and lowest...
Using JAVA Write a program that uses a 2-D array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and highest and lowest temperatures of the year. Your program must consist of the following methods with their appropriate parameters: a.) getData: This method reads and stores the data in the 2-D array. b.) averageHigh: This method calculates and returns the average high temperature of the year. c.)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT