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
Answered By
7 Likes
Related Questions
A Class Teacher wants to keep the records of 40 students of her class along with their names and marks obtained in English, Hindi, Maths, Science and Computer Science in a Double Dimensional Array (DDA) as M[40][5]. When the teacher enters the name of a student as an input, the program must display the name, marks obtained in the 5 subjects and the total. Write a program in Java to perform the task.
A double dimensional array is defined as N[4][4] to store numbers. Write a program to find the sum of all even numbers and product of all odd numbers of the elements stored in Double Dimensional Array (DDA).
Sample Input:12 10 15 17 30 11 32 71 17 14 29 31 41 33 40 51
Sample Output:
Sum of all even numbers: ……….
Product of all odd numbers: ……….A Metropolitan Hotel has 5 floors and 10 rooms in each floor. The names of the visitors are entered in a Double Dimensional Array (DDA) as M[5][10].The Hotel Manager wants to know from the "Enquiry" about the position of a visitor (i.e. floor number and room number) as soon as he enters the name of the visitor. Write a program in Java to perform the above task.
Write a program to input and store roll numbers, names and marks in 3 subjects of n number of students in five single dimensional arrays and display the remark based on average marks as given below:
Average Marks Remark 85 — 100 Excellent 75 — 84 Distinction 60 — 74 First Class 40 — 59 Pass Less than 40 Poor