Project 1:
Create an ecommerce console project with the following specifications-
● That ecommerce should have these classes:
- Administration, Store, Cart,Customer, Product, Seller, Catalog, User
● Admin class will check whether the user is an admin or normal user if it is admin he/she can modify the catalog.
● User class will check all the user authentication and will check user Id and Password for all users.
● Cart will be taking care of all the cart items and will be having the option of checkout as well.
● Catalog is responsible for all the catalog activities.
● In the Store class-
○ Create an order object and assign this user to the order with an order id at the appropriate place.
○ Complete the logical store functionalities for seller and administrator.
○ Make your code modular- divide it in many different small methods.
● In all the remaining classes-
○ Add default and parameterized constructors.
A. Add some dummy products data in your code with categories for each product added. Add subcategories to relevant categories. Now, Ask the customer to view products based on categories and display those products based on categories in the ecommerce store to the Customer if yes.
B. The seller should be able to add products to different categories as well.
C. Divide your project in different packages.
D. Add relevant exception handling to different methods.
E. On checkout by the Customer, create an order and write all the order details to a file with the filename same as the customer id.
Ecomerce:
package Ecomerce;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import Orders.Cart;
import Orders.Orders;
import Orders.Orders;
import ProductDetails.Catalogue;
import ProductDetails.Product;
import Users.customer;
import Users.Administrator;
import Users.Seller;
import Users.customer;
/*
* Ask which type of user are you? Customer, Seller, Administrator
* User- Customer, Seller, Administrator
* Customer- View products, View cart, Contact Us.
* View products- Add the product to the cart, View cart- Checkout.
* Seller- View your products, Add a product, Contact Us
* View your products- delete this product. Add a product- Submit details of the product.
* Administrator- ...
* Product
* Category
* Cart
* Order
*/
public class Storee {
public static void main(String[] args) {
System.out.println("Welcome to the ecommerce store!");
System.out.println("Which user are you? 1. Customer 2. Seller 3. Admin");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
String typeOfUser;
if (choice == 1) {
typeOfUser = "Customer";
customer current = new customer();
System.out.println("What is your userId?");
sc.nextLine();
current.setUserId(sc.nextLine());
System.out.println("What is your passWord?");
sc.nextLine();
current.setPassword(sc.nextLine());
if (current.verifyUser() == true) {
System.out.println("User verified!");
while (true) {
System.out.println("Do you want to- 1. View products 2. View Cart 3. Contact Us 4. Exit");
choice = sc.nextInt();
if (choice == 1) {
System.out.println("choose category");
Catalogue catalogue = new Catalogue();
Product[] allProducts = catalogue.getListofAllProducts();
System.out.println("1-Phones 2-Shoes 3-Child Clothes 4-Adult Clothes ");
sc.nextLine();
int choseCategory = sc.nextInt();
String selected = "";
if (choseCategory == 1)
selected = "Phones";
else if (choseCategory == 2)
selected = "Shoes";
else if (choseCategory == 3)
selected = "Child Clothes";
else if (choseCategory == 4)
selected = "Adult Clothes";
for (int i = 0; i < allProducts.length; i++) {
// System.out.println(allProducts[i].getCategory().getCategoryName());
if (allProducts[i].getCategory().getCategoryName() == selected) {
System.out.println(allProducts[i].getProductId() + " " + allProducts[i].getProductName()
+ " " + allProducts[i].getCost());
}
}
System.out.println("Do you want to add any product to the cart? Y/N");
sc.nextLine();
String addToCart = sc.nextLine();
if (addToCart.equals("Y")) {
System.out.println("Input the product id of the product which you want to add to cart.");
String productId = sc.nextLine();
Product[] cartProducts = new Product[1];
for (int i = 0; i < allProducts.length; i++) {
if (allProducts[i].getProductId().equals(productId))
cartProducts[0] = allProducts[i];
}
Cart cart = new Cart();
cart.setCartId("1");
cart.setListOfProducts(cartProducts);
current.setCart(cart);
System.out.println("The product is successfully added to the cart");
}
} else if (choice == 2) {
try {
Product[] cartProducts = current.getCart().getListOfProducts();
for (int i = 0; i < cartProducts.length; i++) {
System.out.println(cartProducts[i].getProductId() + " "
+ cartProducts[i].getProductName() + " " + cartProducts[i].getCost() + " "
+ cartProducts[i].getCategory().getCategoryName());
}
} catch (Exception e) {
System.out.println("Cart is Empty");
continue;
}
System.out.println("Do you want to checkOut? Y/N");
sc.nextLine();
String checkout = sc.nextLine();
if (checkout.equals("Y"))
if(current.getCart().checkOut())
//create an order object and assign this user to the order with an order id.
System.out.println("Your order is placed successfully");
}else if (choice == 3) {
} else if (choice == 4)
break;
else
System.out.println("Invalid choice, please try again.");
}
}
} else if (choice == 2) {
typeOfUser = "Seller";
Seller currentSeller = new Seller();
System.out.println("Enter your SellerId");
sc.nextLine();
currentSeller.setUserId(sc.nextLine());
System.out.println("What is your password?");
sc.nextLine();
currentSeller.setPassword(sc.nextLine());
if (currentSeller.verifyUser() == true)
System.out.println("Seller Verified");
while (true) {
System.out.println("Do you want to - 1.View Your Product 2.Add a product 3.Contact us");
choice = sc.nextInt();
if (choice == 1) {
Catalogue catalogueS = new Catalogue();
Product[] SellerProduct = catalogueS.getSellerProduct();
for (int i = 0; i < SellerProduct.length; i++) {
System.out.println(" " + SellerProduct[i].getProductId() + " "
+ SellerProduct[i].getProductName() + " " + SellerProduct[i].getCost());
}
} else if(choice==2) {
Product listOfAllProducts= new Product();
System.out.println("Enter Your ProductId? ");
sc.nextLine();
listOfAllProducts.setProductId(sc.nextLine());
System.out.println("Enter Your Product Cost?");
sc.nextLine();
listOfAllProducts.setCost(sc.nextLine());
System.out.println("Enter Your Product Name");
sc.nextLine();
listOfAllProducts.setProductName(sc.nextLine());
System.out.println("Add Product Successfully");
}
else if (choice == 3) {
} else
System.out.println("Invalid choice");
}
} else if(choice==3) {
typeOfUser="Admin";
Administrator admin =new Administrator();
System.out.println("What is your Admin Id?");
sc.nextLine();
admin.setUserId(sc.nextLine());
System.out.println("What is Your Password?");
sc.nextLine();
admin.setPassword(sc.nextLine());
if(admin.verifyUser()==true) {
System.out.println("Admin Verified");
while(true) {
System.out.println("Do You want to 1-View Product 2-Contact 3-Exit ");
choice=sc.nextInt();
if(choice==1) {
Catalogue catalogue2 = new Catalogue();
Product[] Show = catalogue2.getListofAllProducts();
System.out.println("Customer Product");
for (int i = 0; i < Show.length; i++) {
System.out.println(
"" + Show[i].getProductId() + " " + Show[i].getProductName() + " " + Show[i].getCost());
}
Product[] Show2 = catalogue2.getSellerProduct();
System.out.println("Seller Product");
for (int i = 0; i < Show2.length; i++) {
System.out.println("" + Show2[i].getProductId() + " " + Show2[i].getProductName() + " "
+ Show2[i].getCost());
}
}
else if(choice==2){
}
else if(choice==3)
break;
else
System.out.println("Invalid choice, Please try again");
}
}
}
else
System.out.println("Invaild input. Try again");
}
}
package Ecomerce;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import Orders.Cart;
import Orders.Orders;
import Orders.Orders;
import ProductDetails.Catalogue;
import ProductDetails.Product;
import Users.customer;
import Users.Administrator;
import Users.Seller;
import Users.customer;
/*
* Ask which type of user are you? Customer, Seller, Administrator
* User- Customer, Seller, Administrator
* Customer- View products, View cart, Contact Us.
* View products- Add the product to the cart, View cart- Checkout.
* Seller- View your products, Add a product, Contact Us
* View your products- delete this product. Add a product- Submit details of the product.
* Administrator- ...
* Product
* Category
* Cart
* Order
*/
public class Storee {
public static void main(String[] args) {
System.out.println("Welcome to the ecommerce store!");
System.out.println("Which user are you? 1. Customer 2. Seller 3. Admin");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
String typeOfUser;
if (choice == 1) {
typeOfUser = "Customer";
customer current = new customer();
System.out.println("What is your userId?");
sc.nextLine();
current.setUserId(sc.nextLine());
System.out.println("What is your passWord?");
sc.nextLine();
current.setPassword(sc.nextLine());
if (current.verifyUser() == true) {
System.out.println("User verified!");
while (true) {
System.out.println("Do you want to- 1. View products 2. View Cart 3. Contact Us 4. Exit");
choice = sc.nextInt();
if (choice == 1) {
System.out.println("choose category");
Catalogue catalogue = new Catalogue();
Product[] allProducts = catalogue.getListofAllProducts();
System.out.println("1-Phones 2-Shoes 3-Child Clothes 4-Adult Clothes ");
sc.nextLine();
int choseCategory = sc.nextInt();
String selected = "";
if (choseCategory == 1)
selected = "Phones";
else if (choseCategory == 2)
selected = "Shoes";
else if (choseCategory == 3)
selected = "Child Clothes";
else if (choseCategory == 4)
selected = "Adult Clothes";
for (int i = 0; i < allProducts.length; i++) {
// System.out.println(allProducts[i].getCategory().getCategoryName());
if (allProducts[i].getCategory().getCategoryName() == selected) {
System.out.println(allProducts[i].getProductId() + " " + allProducts[i].getProductName()
+ " " + allProducts[i].getCost());
}
}
System.out.println("Do you want to add any product to the cart? Y/N");
sc.nextLine();
String addToCart = sc.nextLine();
if (addToCart.equals("Y")) {
System.out.println("Input the product id of the product which you want to add to cart.");
String productId = sc.nextLine();
Product[] cartProducts = new Product[1];
for (int i = 0; i < allProducts.length; i++) {
if (allProducts[i].getProductId().equals(productId))
cartProducts[0] = allProducts[i];
}
Cart cart = new Cart();
cart.setCartId("1");
cart.setListOfProducts(cartProducts);
current.setCart(cart);
System.out.println("The product is successfully added to the cart");
}
} else if (choice == 2) {
try {
Product[] cartProducts = current.getCart().getListOfProducts();
for (int i = 0; i < cartProducts.length; i++) {
System.out.println(cartProducts[i].getProductId() + " "
+ cartProducts[i].getProductName() + " " + cartProducts[i].getCost() + " "
+ cartProducts[i].getCategory().getCategoryName());
}
} catch (Exception e) {
System.out.println("Cart is Empty");
continue;
}
System.out.println("Do you want to checkOut? Y/N");
sc.nextLine();
String checkout = sc.nextLine();
if (checkout.equals("Y"))
if(current.getCart().checkOut())
//create an order object and assign this user to the order with an order id.
System.out.println("Your order is placed successfully");
}else if (choice == 3) {
} else if (choice == 4)
break;
else
System.out.println("Invalid choice, please try again.");
}
}
} else if (choice == 2) {
typeOfUser = "Seller";
Seller currentSeller = new Seller();
System.out.println("Enter your SellerId");
sc.nextLine();
currentSeller.setUserId(sc.nextLine());
System.out.println("What is your password?");
sc.nextLine();
currentSeller.setPassword(sc.nextLine());
if (currentSeller.verifyUser() == true)
System.out.println("Seller Verified");
while (true) {
System.out.println("Do you want to - 1.View Your Product 2.Add a product 3.Contact us");
choice = sc.nextInt();
if (choice == 1) {
Catalogue catalogueS = new Catalogue();
Product[] SellerProduct = catalogueS.getSellerProduct();
for (int i = 0; i < SellerProduct.length; i++) {
System.out.println(" " + SellerProduct[i].getProductId() + " "
+ SellerProduct[i].getProductName() + " " + SellerProduct[i].getCost());
}
} else if(choice==2) {
Product listOfAllProducts= new Product();
System.out.println("Enter Your ProductId? ");
sc.nextLine();
listOfAllProducts.setProductId(sc.nextLine());
System.out.println("Enter Your Product Cost?");
sc.nextLine();
listOfAllProducts.setCost(sc.nextLine());
System.out.println("Enter Your Product Name");
sc.nextLine();
listOfAllProducts.setProductName(sc.nextLine());
System.out.println("Add Product Successfully");
}
else if (choice == 3) {
} else
System.out.println("Invalid choice");
}
} else if(choice==3) {
typeOfUser="Admin";
Administrator admin =new Administrator();
System.out.println("What is your Admin Id?");
sc.nextLine();
admin.setUserId(sc.nextLine());
System.out.println("What is Your Password?");
sc.nextLine();
admin.setPassword(sc.nextLine());
if(admin.verifyUser()==true) {
System.out.println("Admin Verified");
while(true) {
System.out.println("Do You want to 1-View Product 2-Contact 3-Exit ");
choice=sc.nextInt();
if(choice==1) {
Catalogue catalogue2 = new Catalogue();
Product[] Show = catalogue2.getListofAllProducts();
System.out.println("Customer Product");
for (int i = 0; i < Show.length; i++) {
System.out.println(
"" + Show[i].getProductId() + " " + Show[i].getProductName() + " " + Show[i].getCost());
}
Product[] Show2 = catalogue2.getSellerProduct();
System.out.println("Seller Product");
for (int i = 0; i < Show2.length; i++) {
System.out.println("" + Show2[i].getProductId() + " " + Show2[i].getProductName() + " "
+ Show2[i].getCost());
}
}
else if(choice==2){
}
else if(choice==3)
break;
else
System.out.println("Invalid choice, Please try again");
}
}
}
else
System.out.println("Invaild input. Try again");
}
}