KnowledgeBoat Logo

Computer Applications

A Departmental Shop has 5 stores and 6 departments. The monthly sale of the department is kept in the Double Dimensional Array (DDA) as m[5][6]. The Manager of the shop wants to know the total monthly sale of each store and each department at any time. Write a program to perform the given task.
(Hint: Number of stores as rows and Number of departments as columns.)

Java

Java Arrays

33 Likes

Answer

import java.util.Scanner;

public class KboatDepartmentalStore
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        long m[][] = new long[5][6];
        
        for (int i = 0; i < 5; i++) {
            System.out.println("Store " + (i + 1) + " Sales");
            for (int j = 0; j < 6; j++) {
                System.out.print("Enter monthly sale of department " + 
                    (j + 1) + ": ");
                m[i][j] = in.nextInt();   
            }
        }
        
        System.out.println("\nMonthly Sale by store: ");
        for (int i = 0; i < 5; i++) {
            long storeSale = 0;
            for (int j = 0; j < 6; j++) {
                storeSale += m[i][j];
            }
            System.out.println("Store " + (i + 1) 
                + " Sales: " + storeSale);
        }
        
        System.out.println("\nMonthly Sale by Department: ");
        for (int i = 0; i < 6; i++) {
            long deptSale = 0;
            for (int j = 0; j < 5; j++) {
                deptSale += m[j][i];
            }
            System.out.println("Department " + (i + 1) 
                + " Sales: " + deptSale);
        }
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of A Departmental Shop has 5 stores and 6 departments. The monthly sale of the department is kept in the Double Dimensional Array (DDA) as m[5][6]. The Manager of the shop wants to know the total monthly sale of each store and each department at any time. Write a program to perform the given task. (Hint: Number of stores as rows and Number of departments as columns.)BlueJ output of A Departmental Shop has 5 stores and 6 departments. The monthly sale of the department is kept in the Double Dimensional Array (DDA) as m[5][6]. The Manager of the shop wants to know the total monthly sale of each store and each department at any time. Write a program to perform the given task. (Hint: Number of stores as rows and Number of departments as columns.)

Answered By

7 Likes


Related Questions