-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSalesTable.java
91 lines (46 loc) · 1.5 KB
/
SalesTable.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.util.Scanner;
public class SalesTable{
static Scanner input=new Scanner(System.in);
static double[][] tableofsales=new double[5][6];
public static void main(String[]args) {
askuserfornumbers();
crosstotalcalculate();
displayresults();
}
private static void askuserfornumbers() {
String yesorno;
do {
System.out.println("Enter da product no.");
int productno=input.nextInt();
System.out.println("Enter da salesperson no.");
int salespersonno=input.nextInt();
System.out.printf("Enter da value of product %d sold by the salesperson no. %d",productno,salespersonno);
tableofsales[salespersonno-1][productno-1]=input.nextDouble();
System.out.println("enter Y if u wanna continue");
yesorno=input.next();
}while(yesorno.equalsIgnoreCase("Y"));
displayresults();
}
private static void crosstotalcalculate() {
for (int uu=0; uu<=4; uu++ ) { //sum for the bottom rows
for (int yy=0; yy<=5; ) { //outta bounds
tableofsales[yy][5]+=tableofsales[uu][yy];
}
}
for (int jj=0; jj<=5; jj++ ) { //sum for the leftmost columns
for (int yyy=0; yyy<=4; yyy++) {
tableofsales[5][yyy]+=tableofsales[jj][yyy];
}
}
}
private static void displayresults() {
int ii=0;
int kk=0;
for (;ii<=4; ii++) {
System.out.println(tableofsales[ii][5]);
}
for (;kk<=5; kk++) {
System.out.println(tableofsales[4][kk]);
}
}
}