Project 1
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.
ANSWER
package challecommtwo;
public abstract class Userone {
String userId="";
String password="";
String loginStatus="";
public abstract Boolean verifyUserOne();
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getLoginStatus() {
return loginStatus;
}
public void setLoginStatus(String loginStatus) {
this.loginStatus = loginStatus;
}
}
----------------------------------------------------------------------------------------------------------------------------
package challecommone;
import challecommtwo.Userone;
public class Customerone extends Userone{
private Cartone cartone;
public Cartone getCart() {
return cartone;
}
public void setCart(Cartone cartone) {
this.cartone = cartone;
}
public Boolean verifyUserOne() {
return true;
}
}
----------------------------------------------------------------------------------------------------------------------------
package challecommtwo;
public class Productone {
private int e;
private String productId;
private String cost;
private String productName;
private String subCategories;
private Sellerone sellerone;
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getCost() {
return cost;
}
public void setCost(String cost) {
this.cost = cost;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public Sellerone getSeller() {
return sellerone;
}
public void setSeller(Sellerone seller) {
this.sellerone = seller;
}
private String categories;
public String getCategories() {
return categories;
}
public void setCategories(String categories) {
this.categories = categories;
}
public String getSubCategories() {
return subCategories;
}
public void setSubCategories(String subCategories) {
this.subCategories = subCategories;
}
}
-----------------------------------------------------------------------------------------------------------------------------------
package challecommone;
import challecommtwo.Productone;
public class Cartone {
private String cartId;
public String getCartId() {
return cartId;
}
public void setCartId(String cartId) {
this.cartId = cartId;
}
private Productone [] listofProducts;
public Productone[] getListofProducts() {
return listofProducts;
}
public void setListofProducts(Productone[] listofProducts) {
this.listofProducts = listofProducts;
}
public Boolean checkOut() {
return true;
}
}
-------------------------------------------------------------------------------------------------------------------------------------
package challecommtwo;
public class Catalogone {
private Productone [] listOfAllProducts;
private Productone [] listOfProducts;
public Productone[] getListOfProducts() {
return listOfProducts;
}
public void setListOfProducts(Productone[] listOfProducts) {
this.listOfProducts = listOfProducts;
}
public Productone[] getListOfAllProducts() {
Productone p1=new Productone();
p1.setProductId("1");
p1.setProductName("TV");
p1.setCategories("LED");
p1.setCategories("LCD");
p1.setSubCategories("SONY");
p1.setSubCategories("LG");
//p1.setCost("25000");
p1.setCost("15000 To 25000");
Productone p2=new Productone();
p2.setProductId("2");
p2.setProductName("LAPTOPS");
p2.setCategories("HIGH COST LAPTOPS");
p2.setCategories("LOW COST LAPTOPS");
p2.setSubCategories("APPLE LAPTOPS");
p2.setSubCategories("NORMAL LAPTOPS");
//p2.setCost("100000");
p2.setCost("50000 To 100000");
listOfAllProducts=new Productone[2];
listOfAllProducts[0]=p1;
listOfAllProducts[1]=p2;
Productone p3=new Productone();
p3.setProductId("3");
p3.setProductName("TABLETS");
p3.setCategories("LED");
p3.setCategories("LCD");
p3.setSubCategories("DELL");
p3.setSubCategories("LENOVA");
p3.setCost("12000 To 18000");
return listOfAllProducts;
}
public void setListOfAllProducts(Productone[] listOfAllProducts) {
this.listOfAllProducts = listOfAllProducts;
}
}
----------------------------------------------------------------------------------------------------------------------------
package challecommone;
public class Storeone {
private String orderId;
private Customerone user;
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
public Customerone getUser() {
return user;
}
public void setUser(Customerone user) {
this.user = user;
}
}
------------------------------------------------------------------------------------------------------------------------------
package challecommtwo;
public class Sellerone {
String sellerId="";
String sellerpassword="";
String loginStatus="";
public String getSellerId() {
return sellerId;
}
public void setSellerId(String userId) {
this.sellerId = sellerId;
}
public String getLoginStatus() {
return loginStatus;
}
public void setLoginStatus(String loginStatus) {
this.loginStatus = loginStatus;
}
public String getsellerPassword() {
return sellerpassword;
}
private Productone [] listOfProducts;
public Productone[] getListOfProducts() {
return listOfProducts;
}
public void setListOfProducts(Productone[] listOfProducts) {
this.listOfProducts = listOfProducts;
}
public Boolean verifySellerOne() {
return true;
}
public void setsellerPassword(String nextLine) {
// TODO Auto-generated method stub
this.sellerpassword=sellerpassword;
}
public void setListOfAllProducts(Productone[] catalogueProducts) {
// TODO Auto-generated method stub
}
}
----------------------------------------------------------------------------------------------------------------------------------
package challecommone;
import java.util.Scanner;
import challecommtwo.Catalogone;
import challecommtwo.Productone;
import challecommtwo.Sellerone;
//import challecommtwo.Productone;
import ecomm.Cart;
public class Administration {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("WELCOME TO THE E-COMMERCE WORLD");
System.out.println("Which people you are? 1.User 2.Admin 3.Seller");
Scanner sc=new Scanner(System.in);
int choice;
choice=sc.nextInt();
String typeOfPeople;
if(choice==1) {
typeOfPeople="User";
Customerone currentone=new Customerone();
System.out.println("What is your Userid?");
sc.nextLine();
currentone.setUserId(sc.nextLine());
System.out.println("What is your Password?");
sc.nextLine();
currentone.setPassword(sc.nextLine());
if(currentone.verifyUserOne()==true) {
System.out.println("User verified");
while(true) {
System.out.println("Do you want to-1.View products based on categories 2.View cart 3.Exit");
choice=sc.nextInt();
if(choice==1) {
Catalogone catalogone=new Catalogone();
Productone[] allProducts=catalogone.getListOfAllProducts();
for(int i=0;i<allProducts.length;i++) {
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();
Productone[] cartProducts=new Productone[1];
for(int i=0;i<cartProducts.length;i++) {
if(allProducts[i].getProductId().equals(productId)) {
cartProducts[0]=allProducts[i];
}
Cartone cartone=new Cartone();
cartone.setCartId("1");
cartone.setListofProducts(cartProducts);
currentone.setCart(cartone);
System.out.println("The product is successfully added to the cart");
}
}
}
}
}
}
else if(choice==3) {
Catalogone catalogone=new Catalogone();
Productone[] allProducts = catalogone.getListOfAllProducts();
typeOfPeople="Seller";
Sellerone sellerone=new Sellerone();
//Productone allProducts []=catalogone.setLis
//Productone[] allProducts=sellerone.setListOfAllProducts();
System.out.println("What is your Password?");
sc.nextLine();
sellerone.setsellerPassword(sc.nextLine());
if(sellerone.verifySellerOne()==true) {
System.out.println("Seller verified");
while(true) {
System.out.println("Do you want to add an any product to the catalogue? Y/N");
//sc.nextLine();
String addToCatalogue=sc.nextLine();
if(addToCatalogue.equals("Y")) {
System.out.println("Input the product id of the product which you want to add to catalogue.");
//String productId=sc.nextLine();
String Addedproductid=sc.nextLine();
Productone[] catalogueProducts=new Productone[3];
for(int i=0;i<catalogueProducts.length;i++) {
if(allProducts[i].getProductId().equals(Addedproductid)) {
catalogueProducts[i]=(Productone) allProducts[i];
}
Catalogone cone=new Catalogone();
sellerone.setListOfAllProducts(catalogueProducts);
}
Catalogone cone=new Catalogone();
Productone[] allProducts1=catalogone.getListOfAllProducts();
for(int i1=0;i1<allProducts1.length;i1++) {
System.out.println(allProducts1[i1].getProductId()+" "+allProducts1[i1].getProductName()+" "+
allProducts1[i1].getCost());
}
System.out.println("The product is successfully added to the catalogue");
}
}
}
}
}
}
-----------------------------------------------------------------------------------------------------------------------------------
OUTPUT 1
WELCOME TO THE E-COMMERCE WORLD
Which people you are? 1.User 2.Admin 3.Seller
1
What is your Userid?
2
What is your Password?
e
e
User verified
Do you want to-1.View products based on categories 2.View cart 3.Exit
1
1 TV 15000 To 25000
2 LAPTOPS 50000 To 100000
Do you want to add any product to the cart? Y/N
Y
Input the product id of the product which you want to add to cart.
2
The product is successfully added to the cart
Do you want to-1.View products based on categories 2.View cart 3.Exit
------------------------------------------------------------------------------------------------------------------------------------
OUTPUT 2
WELCOME TO THE E-COMMERCE WORLD
Which people you are? 1.User 2.Admin 3.Seller
3
What is your Password?
E
Seller verified
Do you want to add an any product to the catalogue? Y/N
Y
Input the product id of the product which you want to add to catalogue.
3
Error occur sir
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
at Ecommerce/challecommone.Administration.main(Administration.java:89)
------------------------------------------------------------------------------------------------------------------------------
===================================================================
-----------------------------------------------------------------------------------------------------------------------------