-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomerDashboard.java
More file actions
70 lines (61 loc) · 2.77 KB
/
CustomerDashboard.java
File metadata and controls
70 lines (61 loc) · 2.77 KB
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
import javax.swing.*;
import java.util.Arrays;
import java.util.List;
/**
* CustomerDashboard
*
* CustomerDashboard is the interface in which a customer can view much of the data involving:
* Stores - List of stores and how many products are for sale
* Products Bought - List of products and the store the customer bought the item at.
*/
public class CustomerDashboard {
public String username;
public String password;
//Constructor for CustomerDashboard
public CustomerDashboard(String username, String password) {
this.username = username;
this.password = password;
}
public void viewDashboard(String[] storesList, String[] productsList, String[] productsBought) {
//storesList - each store index corresponds to the productList index
//productsList - list of products for the store/index
//productsBought - index separated list of particular products bought by customer (from customers.java)
//Stores by number of products sold (from sellers.java)
String dashboardMessage = "Stores: \n";
StringBuilder storeMessage = new StringBuilder();
for (int i = 0; i < storesList.length; i++) {
List<String> products = Arrays.asList(productsList[i].split(","));
String[] storeProducts = products.toArray(new String[0]);
storeMessage.append(storesList[i]).append(" - Number of Products: ").append(storeProducts.length).append("\n");
}
if (storeMessage.length() == 0) {
storeMessage = new StringBuilder("No stores exist.\n");
}
dashboardMessage += storeMessage + "\n";
//Stores by products bought
dashboardMessage += "Products Bought: \n";
boolean print = false;
StringBuilder productNums = new StringBuilder();
for (int i = 0; i < storesList.length; i++) {
List<String> products = Arrays.asList(productsList[i].split(","));
String[] storeProducts = products.toArray(new String[0]);
for (int j = 0; j < storeProducts.length; j++) {
for (int k = 0; k < productsBought.length; k++) {
if (productsBought[k].equals(storeProducts[j])) {
print = true;
productNums.append(productsBought[k]).append(" - ").append(storesList[i]).append("\n");
}
}
}
}
if (!print) {
productNums = new StringBuilder("None\n");
//This is for situations where no products have been bought
}
dashboardMessage += productNums;
JOptionPane.showMessageDialog(null, dashboardMessage,
"Dashboard", JOptionPane.INFORMATION_MESSAGE);
//This displays the dashboardMessage
}
//end of the class
}