Skip to content

Commit 5a51555

Browse files
authored
Merge pull request #7 from AvatarTheLastAirbender/MockEcommerceSite
Mock ecommerce site
2 parents 2313475 + 5f0049a commit 5a51555

File tree

7 files changed

+469
-1
lines changed

7 files changed

+469
-1
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import java.util.Scanner;
2+
3+
public class AdminControlPanel {
4+
public static void AdminControls(String adminId, String password) {
5+
if(!adminId.equals("admin") && !password.equals("password")){
6+
System.out.println("Wrong Credentials!");
7+
return;
8+
}
9+
boolean isAdminWantedToContinue = true;
10+
while (isAdminWantedToContinue){
11+
System.out.println("1 -> Products\n2 -> Customers\n3 -> Coupon Codes\n4 -> Back To Home\nEnterChoice");
12+
Scanner adminInput = new Scanner(System.in);
13+
int adminChoice = adminInput.nextInt();
14+
switch (adminChoice){
15+
case 1:
16+
Product.ProductsControlPanel();
17+
break;
18+
case 2:
19+
Customer.CustomerControlPanel();
20+
break;
21+
case 3:
22+
CouponCodes.CouponCodesControlPanel();
23+
break;
24+
case 4:
25+
isAdminWantedToContinue = false;
26+
PublicUserControlPanel.userControls();
27+
break;
28+
}
29+
}
30+
}
31+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import java.util.HashMap;
2+
import java.util.Map;
3+
import java.util.Scanner;
4+
5+
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+
18+
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!");
77+
}
78+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import java.util.*;
2+
3+
public class Customer {
4+
static int id=1;
5+
static Map<Integer, Customer> allCustomers = new HashMap<>();
6+
static Scanner input = new Scanner(System.in);
7+
int Customer_id;
8+
String Customer_name;
9+
String Customer_Contact;
10+
List<Integer> CartItems;
11+
List<String> CustomerInvoices;
12+
13+
public Customer(String customerName,String customerContact) {
14+
this.Customer_id = id++;
15+
this.Customer_name = customerName;
16+
this.Customer_Contact = customerContact;
17+
this.CartItems = new ArrayList<>();
18+
this.CustomerInvoices = new ArrayList<>();
19+
}
20+
21+
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");
95+
}
96+
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();
101+
Customer newCustomer = new Customer(customerName, customerContact);
102+
allCustomers.put(newCustomer.Customer_id, newCustomer);
103+
System.out.println("Customer Id Created for "+newCustomer.Customer_name+"\nCustomerId : "+newCustomer.Customer_id);
104+
}
105+
}

EcommerceApplication/src/Main.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
1+
import java.util.Scanner;
2+
3+
/*
4+
* E-Commerce Applications
5+
1 -> Admin
6+
2 -> Client
7+
3 -> Create New User
8+
9+
* Entire Client List -> List
10+
* Entire Purchase List -> List
11+
* Entire Product List -> Map
12+
* Entire Customer Purchase List -> Map
13+
14+
* Admin
15+
-> Add Product
16+
-> Can view/Add/Delete/Update Customers List
17+
-> Can view/Add/Delete/Update Products List
18+
-> Can view/Add/Delete/Update Coupon Codes
19+
-> Can view All Sales
20+
* Product Registration
21+
-> Product Id
22+
-> Product Name
23+
-> Product Stock
24+
25+
* Client
26+
-> Can View/AddToCart/Buy a Product
27+
-> Can View Invoice
28+
-> Delete Product while checkout
29+
30+
* New Client Registration
31+
-> Client Name
32+
-> Client User ID
33+
-> Admin Password To Verifications
34+
35+
*
36+
*/
137
public class Main {
238
public static void main(String[] args) {
3-
System.out.println("Hello world!");
39+
System.out.println("=================================" +
40+
"\n======E-Commerce Application=====" +
41+
"\n=================================");
42+
PublicUserControlPanel.userControls();
443
}
544
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import java.util.*;
2+
3+
public class Product {
4+
static List<Product> productArrayList = new ArrayList<>();
5+
static Map<Integer, Product> allProducts = new HashMap<>();
6+
static Scanner input = new Scanner(System.in);
7+
static int id = 1;
8+
int productId;
9+
String productName;
10+
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+
}
19+
20+
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+
}
76+
}
77+
}

0 commit comments

Comments
 (0)