-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
146 lines (130 loc) · 5.63 KB
/
Copy pathMain.java
File metadata and controls
146 lines (130 loc) · 5.63 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
* Develop a mini-project ‘Invoice Management’ with the following modules :
1. Add a customer
-> Customer Id
-> Customer Name
-> Customer Contact
-> Customer TotalPurchase
-> List of Invoices
2. Add an invoice
-> InvoiceId
-> List of Products
-> Total Purchase Amount
3. Add items to an invoice
-> ProductId
-> Buying Count
-> Product Amount
4. List all customers
-> List of all Customers
5. List all invoices
-> List of all invoices
6. List all invoices for a customer
-> List of Customer Invoices
7. Display the full details of an invoice
-> Print Specific Invoice
*/
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("=================================\n"+
"=== Invoice Management System ===\n"+
"=================================\n");
boolean isUserWantsToContinue = true;
while (isUserWantsToContinue) {
System.out.println("Following Features are Available\n1 -> Add a Customer\n2 -> Generate an Invoice\n3 -> List all customers\n4 -> List all Invoices\n5 -> List all Invoices for a customer\n6 -> Display the full details of an invoice\n7 -> Exit\nEnter Selection :");
int userChoice = input.nextInt();
switch (userChoice) {
case 1:
System.out.println("\nEnter Customer Name:");
String CustomerName = input.next();
System.out.println("\nEnter Customer Contact:");
String CustomerContact = input.next();
Customer newCustomer = new Customer(CustomerName, CustomerContact);
Customer.UpdateCustomer(newCustomer);
System.out.println("\nRegistration Success -> " + newCustomer.CustomerName);
System.out.println("=============================================================");
break;
case 2:
List<Product> ProductList = new ArrayList<>();
System.out.println("\nEnter CustomerId:");
int CustomerIdForInvoice = input.nextInt();
if (validateExistingCustomers(CustomerIdForInvoice)) break;
Invoice newInvoice = new Invoice();
Customer.AddInvoiceToCustomer(CustomerIdForInvoice, newInvoice);
Customer currentCustomer =
Customer.AllCustomers.get(CustomerIdForInvoice);
currentCustomer.PurchaseHistory.add(newInvoice);
Invoice.AllInvoices.put(newInvoice.InvoiceId, newInvoice);
System.out.println("Enter No of Products:");
int NoOfProducts = input.nextInt();
for (int i = 0; i < NoOfProducts; i++) {
System.out.println("Enter Product Name");
String ProductName = input.next();
System.out.println("Enter Product Price");
int ProductPrice = input.nextInt();
System.out.println("Enter Product Count");
int ProductCount = input.nextInt();
Product newProduct = new Product(ProductName, ProductPrice, ProductCount);
ProductList.add(newProduct);
}
Customer.UpdateCustomerInvoice(CustomerIdForInvoice, newInvoice.InvoiceId, ProductList);
System.out.println("Invoice Created For " + currentCustomer.CustomerName);
System.out.println("=============================================================");
break;
case 3:
System.out.println("CustomerName CustomerContact TotalPurchase");
for (Customer CustomerDetails : Customer.AllCustomers.values()) {
System.out.println(
CustomerDetails.CustomerName
+ " "
+ CustomerDetails.Contact
+ " "
+ CustomerDetails.TotalPurchase);
}
System.out.println("=========================================================");
break;
case 4:
for (Invoice userInvoice : Invoice.AllInvoices.values()) {
Invoice.ShowInvoiceDetails(userInvoice);
}
System.out.println("=========================================================");
break;
case 5:
System.out.println("\nEnter CustomerId:");
int getInvoiceCustomerId = input.nextInt();
if (validateExistingCustomers(getInvoiceCustomerId)) break;
List<Invoice> getUserInvoices = Customer.getCustomerInvoices(getInvoiceCustomerId);
for (Invoice userInvoice : getUserInvoices) {
Invoice.ShowInvoiceDetails(userInvoice);
}
System.out.println("=========================================================");
break;
case 6:
System.out.println("Enter InvoiceId:");
int invoiceId = input.nextInt();
if (!Invoice.AllInvoices.containsKey(invoiceId)) {
System.out.println("Invoice Not Available");
break;
}
Invoice userInvoice = Invoice.AllInvoices.get(invoiceId);
Invoice.ShowInvoiceDetails(userInvoice);
System.out.println("=========================================================");
break;
case 7:
isUserWantsToContinue = false;
break;
}
}
}
private static boolean validateExistingCustomers(int customerIdForInvoice) {
boolean notRegisteredCustomer = false;
if (!Customer.AllCustomers.containsKey(customerIdForInvoice)) {
System.out.println("Not Registered Customer");
notRegisteredCustomer = true;
}
return notRegisteredCustomer;
}
}