In: Computer Science
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.
/* 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.