Skip to content

Commit 5f0049a

Browse files
committed
E-commerce site functionalities Completed
1 parent 05393ff commit 5f0049a

File tree

8 files changed

+362
-43
lines changed

8 files changed

+362
-43
lines changed

EcommerceApplication/src/AdminControlPanel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public static void AdminControls(String adminId, String password) {
2222
CouponCodes.CouponCodesControlPanel();
2323
break;
2424
case 4:
25+
isAdminWantedToContinue = false;
26+
PublicUserControlPanel.userControls();
2527
break;
2628
}
2729
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,78 @@
1+
import java.util.HashMap;
2+
import java.util.Map;
3+
import java.util.Scanner;
4+
15
public class CouponCodes {
6+
static Map<String, CouponCodes> couponList = new HashMap<>();
7+
static Scanner input = new Scanner(System.in);
8+
String Code;
9+
int DiscountAmount;
10+
boolean isValidCode;
11+
12+
public CouponCodes(String code, int discount) {
13+
this.Code = code;
14+
this.DiscountAmount = discount;
15+
this.isValidCode = true;
16+
}
17+
218
public static void CouponCodesControlPanel() {
19+
System.out.println("1 -> Create CouponCode\n2 -> Update CouponCode\n3 -> Delete CouponCode\n4 -> List of All Coupons\n5 -> Back\nChoice :");
20+
int choice = input.nextInt();
21+
switch (choice){
22+
case 1:
23+
CreateCouponCode();
24+
break;
25+
case 2:
26+
UpdateCoupon();
27+
break;
28+
case 3:
29+
System.out.println("Enter Code");
30+
String code = input.nextLine();
31+
if(!isExistingCoupon(code)) return;
32+
couponList.remove(code);
33+
System.out.println("Coupon Deleted");
34+
break;
35+
case 4:
36+
printAllCouponCodes();
37+
break;
38+
case 5:
39+
AdminControlPanel.AdminControls("admin", "password");
40+
break;
41+
}
42+
CouponCodesControlPanel();
43+
}
44+
45+
private static void printAllCouponCodes() {
46+
System.out.println("Code Discount Amount Availability");
47+
for (CouponCodes code:couponList.values()){
48+
System.out.println(code.Code+" "+code.DiscountAmount+" "+code.isValidCode);
49+
}
50+
System.out.println("========== End Of List ==========");
51+
}
52+
53+
private static void UpdateCoupon() {
54+
System.out.println("Enter Code");
55+
String code = input.nextLine();
56+
if(!isExistingCoupon(code)) return;
57+
CouponCodes currentCoupon = couponList.get(code);
58+
System.out.println("Enter Discount");
59+
currentCoupon.DiscountAmount = input.nextInt();
60+
currentCoupon.isValidCode = true;
61+
System.out.println("Coupon Discount Updated!");
62+
}
63+
64+
private static boolean isExistingCoupon(String code) {
65+
boolean isExistingCode = couponList.containsKey(code);
66+
if(!isExistingCode) System.out.println("Invalid Coupon!");
67+
return isExistingCode;
68+
}
69+
70+
private static void CreateCouponCode() {
71+
System.out.println("Enter Code, Discount value");
72+
String code = input.next();
73+
int discount = input.nextInt();
74+
CouponCodes newCoupon = new CouponCodes(code,discount);
75+
couponList.put(code, newCoupon);
76+
System.out.println("====> Coupon code created!");
377
}
478
}
Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import java.util.ArrayList;
2-
import java.util.HashMap;
3-
import java.util.List;
4-
import java.util.Map;
1+
import java.util.*;
52

63
public class Customer {
74
static int id=1;
5+
static Map<Integer, Customer> allCustomers = new HashMap<>();
6+
static Scanner input = new Scanner(System.in);
87
int Customer_id;
98
String Customer_name;
109
String Customer_Contact;
11-
static Map<Integer, Customer> allCustomers = new HashMap<>();
12-
List<Product> CartItems;
13-
List<Invoice> CustomerInvoices;
10+
List<Integer> CartItems;
11+
List<String> CustomerInvoices;
1412

1513
public Customer(String customerName,String customerContact) {
1614
this.Customer_id = id++;
@@ -21,10 +19,87 @@ public Customer(String customerName,String customerContact) {
2119
}
2220

2321
public static void CustomerControlPanel() {
22+
System.out.println("1 -> Create New Customer\n2 -> Update Customer Details\n3 -> Delete Customer\n4 -> List All Customers\n5 -> Back\nChoice :");
23+
Scanner input = new Scanner(System.in);
24+
int AdminSelection = input.nextInt();
25+
switch (AdminSelection){
26+
case 1:
27+
CreateNewCustomer();
28+
break;
29+
case 2:
30+
System.out.println("Enter Customer Id");
31+
int customerId = input.nextInt();
32+
if(!isExistingCustomer(customerId)) CustomerControlPanel();
33+
updateCustomerDetails(customerId);
34+
break;
35+
case 3:
36+
System.out.println("Enter Customer Id");
37+
customerId = input.nextInt();
38+
if(!isExistingCustomer(customerId)) CustomerControlPanel();
39+
allCustomers.remove(customerId);
40+
System.out.println("Successfully Deleted!");
41+
break;
42+
case 4:
43+
printAllCustomers();
44+
break;
45+
case 5:
46+
AdminControlPanel.AdminControls("admin", "password");
47+
break;
48+
}
49+
CustomerControlPanel();
50+
}
51+
52+
private static boolean isExistingCustomer(int customerId) {
53+
boolean isExistingUser = allCustomers.containsKey(customerId);
54+
if(!isExistingUser) System.out.println("User Not Found!");
55+
return isExistingUser;
56+
}
57+
58+
private static void updateCustomerDetails(int customerId) {
59+
Customer customerDetails = allCustomers.get(customerId);
60+
if(!isExistingCustomer(customerId)) CustomerControlPanel();
61+
System.out.println("1 -> Update Name\n 2 -> Update Contact\n3 -> Update Name and Contact\n4 -> Back\nChoice :");
62+
int choice = input.nextInt();
63+
switch (choice){
64+
case 1:
65+
System.out.println("Enter Name:");
66+
String customerName = input.next();
67+
customerDetails.Customer_name = customerName;
68+
break;
69+
case 2:
70+
System.out.println("Enter Contact:");
71+
String customerContact = input.next();
72+
customerDetails.Customer_Contact = customerContact;
73+
break;
74+
case 3:
75+
System.out.println("Enter Name and Contact :");
76+
customerName = input.next();
77+
customerContact = input.next();
78+
customerDetails.Customer_name = customerName;
79+
customerDetails.Customer_Contact = customerContact;
80+
break;
81+
case 4:
82+
break;
83+
}
84+
System.out.println("Customer Details Updated for "+customerDetails.Customer_name);
85+
CustomerControlPanel();
86+
}
87+
88+
private static void printAllCustomers() {
89+
System.out.println(
90+
"======================= Customers List ==============\n== CustomerId == Customer Name == Customer Contact ==");
91+
for (Customer currentCustomer : allCustomers.values()) {
92+
System.out.println(currentCustomer.Customer_id+" "+currentCustomer.Customer_name+" "+currentCustomer.Customer_Contact);
93+
}
94+
System.out.println("======================= End Of List ==============\n");
2495
}
2596

26-
public static void CreateNewCustomer(String customerName,String customerContact) {
97+
public static void CreateNewCustomer() {
98+
System.out.println("Enter Customer Name and Customer Contact");
99+
String customerName = input.next();
100+
String customerContact = input.next();
27101
Customer newCustomer = new Customer(customerName, customerContact);
28102
allCustomers.put(newCustomer.Customer_id, newCustomer);
103+
System.out.println("Customer Id Created for "+newCustomer.Customer_name+"\nCustomerId : "+newCustomer.Customer_id);
29104
}
30105
}

EcommerceApplication/src/Invoice.java

Lines changed: 0 additions & 2 deletions
This file was deleted.

EcommerceApplication/src/Main.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,6 @@ public static void main(String[] args) {
3939
System.out.println("=================================" +
4040
"\n======E-Commerce Application=====" +
4141
"\n=================================");
42-
Scanner input =new Scanner(System.in);
43-
boolean isUserWantedToContinue = true;
44-
while (isUserWantedToContinue){
45-
System.out.println("1 -> Admin LogIn\n2 -> Customer LogIn\n3 -> Create New User\n4 -> Exit\nEnter Choice:");
46-
int userChoice = input.nextInt();
47-
switch (userChoice){
48-
case 1:
49-
System.out.println("Enter AdminId and Password");
50-
String AdminId = input.nextLine();
51-
String Password = input.nextLine();
52-
AdminControlPanel.AdminControls(AdminId,Password);
53-
break;
54-
case 2:
55-
System.out.println("Enter Customer Id:");
56-
int CustomerId = input.nextInt();
57-
ProductListPage.CustomerControls();
58-
break;
59-
case 3:
60-
System.out.println("Enter Customer Name and Customer Contact");
61-
String CustomerName = input.next();
62-
String CustomerContact = input.next();
63-
Customer.CreateNewCustomer(CustomerName, CustomerContact);
64-
65-
break;
66-
case 4:
67-
isUserWantedToContinue = false;
68-
break;
69-
};
70-
}
42+
PublicUserControlPanel.userControls();
7143
}
7244
}
Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,77 @@
1-
import java.util.ArrayList;
2-
import java.util.List;
1+
import java.util.*;
32

43
public class Product {
5-
static List<Product> allProducts = new ArrayList<>();
4+
static List<Product> productArrayList = new ArrayList<>();
5+
static Map<Integer, Product> allProducts = new HashMap<>();
6+
static Scanner input = new Scanner(System.in);
67
static int id = 1;
78
int productId;
89
String productName;
910
int productCount;
11+
int productPrice;
12+
13+
public Product(String productName, int productPrice, int stockCount) {
14+
this.productId = id++;
15+
this.productName = productName;
16+
this.productPrice = productPrice;
17+
this.productCount =stockCount;
18+
}
1019

1120
public static void ProductsControlPanel() {
21+
System.out.println("1 -> Add new Product\n2 -> Update Product Stock\n3 -> Delete Product\n4 -> Back\nChoice");
22+
int choice = input.nextInt();
23+
switch (choice){
24+
case 1:
25+
createNewProduct();
26+
break;
27+
case 2:
28+
System.out.println("Enter Product Id:");
29+
int productId = input.nextInt();
30+
if(!isExistingProduct(productId)) break;
31+
updateProductStock(productId);
32+
break;
33+
case 3:
34+
System.out.println("Enter Product Id:");
35+
productId = input.nextInt();
36+
if(!isExistingProduct(productId)) break;
37+
allProducts.remove(productId);
38+
System.out.println("=====================> Product Deleted!");
39+
break;
40+
case 4:
41+
AdminControlPanel.AdminControls("admin", "password");
42+
break;
43+
}
44+
ProductsControlPanel();
45+
}
46+
47+
private static void updateProductStock(int productId) {
48+
Product currentProduct = allProducts.get(productId);
49+
System.out.println("Enter Stock:");
50+
int stockCount = input.nextInt();
51+
currentProduct.productCount =stockCount;
52+
System.out.println("=====================> Stock Updated!");
53+
}
54+
55+
private static boolean isExistingProduct(int productId) {
56+
boolean isExisting = allProducts.containsKey(productId);
57+
if(!isExisting) System.out.println("Product Not Available!");
58+
return isExisting;
59+
}
60+
61+
private static void createNewProduct() {
62+
System.out.println("Enter Product name, Price, Stock Count");
63+
String productName = input.next();
64+
int productPrice = input.nextInt();
65+
int stockCount = input.nextInt();
66+
Product newProduct = new Product(productName,productPrice,stockCount);
67+
allProducts.put(newProduct.productId, newProduct);
68+
System.out.println("Product "+newProduct.productName+" added with Stock Count : "+newProduct.productCount);
69+
}
70+
71+
static void updateProductList() {
72+
productArrayList.clear();
73+
for (Product currentProduct : allProducts.values()) {
74+
productArrayList.add(currentProduct);
75+
}
1276
}
1377
}

0 commit comments

Comments
 (0)