- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomerDB.java
More file actions
Latest commit
68 lines (55 loc) · 1.99 KB
/
Copy pathCustomerDB.java
File metadata and controls
68 lines (55 loc) · 1.99 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
importjava.util.Scanner;
publicclassCustomerDB
{
privateCustomer[] customers;
privateintcount;
publicCustomerDB() {
this.customers = newCustomer[10];
this.count = 0;
}
publicvoidaddCustomer(Customercustomer) {
if (count < 10) {
this.customers[count++] = customer;
} else {
System.out.println("Database is full!");
}
}
publicvoidshowAllCustomers() {
for (inti = 0; i < count; i++) {
System.out.println((i + 1) + "." + customers[i].toString());
}
}
publicstaticvoidmain(String[] args) {
Scannerscanner = newScanner(System.in);
CustomerDBdb = newCustomerDB();
while (true) {
System.out.println("===Main menu of Customer Database===");
System.out.println("[1] Add new customer");
System.out.println("[2] Show all customers");
System.out.print("Your option [1,2] : ");
intoption = scanner.nextInt();
scanner.nextLine();
switch (option) {
case1:
System.out.println("===Add new customer===");
System.out.print("First Name: ");
StringfName = scanner.nextLine();
System.out.print("Last Name: ");
StringlName = scanner.nextLine();
System.out.print("Age: ");
intage = scanner.nextInt();
System.out.print("Mobile Phone: ");
StringmPhone = scanner.next();
db.addCustomer(newCustomer(fName, lName, age, mPhone));
break;
case2:
System.out.println("===Show all customers===");
db.showAllCustomers();
break;
default:
System.out.println("Invalid option");
break;
}
}
}
}