-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainApp1.java
100 lines (88 loc) · 3.13 KB
/
MainApp1.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
92
93
94
95
96
97
98
99
100
package Day7.Task;
import java.util.HashMap;
import java.util.Scanner;
public class MainApp1 {
static HashMap<String, String> userMap = new HashMap<>();
static Scanner sc = new Scanner(System.in);
static BLClass bl = new BLClass();
public static void main(String[] args) {
// Add some users to the userMap
userMap.put("user1", "password1");
userMap.put("user2", "password2");
boolean status = false;
while (!status) {
displayMenu();
int choice = sc.nextInt();
switch (choice) {
case 1:
login();
break;
case 2:
buyProduct();
break;
case 3:
cancelProduct();
break;
case 4:
bl.displayAllProducts();
break;
case 5:
logout();
break;
case 6:
status = true;
break;
default:
System.out.println("Invalid choice");
}
}
}
private static void displayMenu() {
System.out.println("=================================");
System.out.println("1. Log in");
System.out.println("2. Buy product");
System.out.println("3. Cancel product");
System.out.println("4. Display all products");
System.out.println("5. Sign out");
System.out.println("6. Exit");
System.out.println("==================================");
System.out.print("Enter your choice: ");
}
private static void login() {
System.out.print("Enter username: ");
String username = sc.next();
System.out.print("Enter password: ");
int password=sc.nextInt();
if (userMap.containsKey(username)) {
userMap.get(username);
}
System.out.println("Login successful");
} {
System.out.println("Invalid username or password");
}
private static void buyProduct() {
int loggedInUser=0;
if (loggedInUser == 0) {
System.out.print("Enter product name: ");
String productName = sc.next();
System.out.print("Enter product price: ");
double productPrice = sc.nextDouble();
bl.buyProduct(productName, productPrice);
} else {
System.out.println("You need to log in first");
}
}
private static void cancelProduct() {
int loggedInUser=0;
if (loggedInUser == 0) {
System.out.print("Enter product name: ");
String productName = sc.next();
bl.cancelProduct(productName);
} else {
System.out.println("You need to log in first");
}
}
private static void logout() {
System.out.println("Logged out");
}
}