Challenge

Project 1

public class Cart {
private String cartId;

public String getCartId() {
return cartId;
}

public void setCartId(String cartId) {
this.cartId = cartId;
}

private Product[] listOfProducts;

public Product[] getListOfProducts() {
return listOfProducts;
}

public void setListOfProducts(Product[] listOfProducts) {
this.listOfProducts = listOfProducts;
}

public Boolean checkOut() {
return true;
}
}

console-

Enter the first number

Enter the second number

Sum of the number:

do you want continue y/n ?

public class Catalogue {
private Product [] listofAllProducts;

public Product[] getListofAllProducts() {

Product product1= new Product();
product1.setProductId("1");
product1.setProductName("Product 1");
product1.setCost("100");

Product product2= new Product();
product2.setProductId("2");
product2.setProductName("Product 2");
product2.setCost("200");

listofAllProducts = new Product[2];


listofAllProducts[0]=product1;
listofAllProducts[1]=product2;

return listofAllProducts;
}

public void setListofAllProducts(Product[] listofAllProducts) {
this.listofAllProducts = listofAllProducts;
}

}

public class Category {
private String categoryName;
private Category[] subCategories;

public String getCategoryName() {
return categoryName;
}

public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}

public Category[] getSubCategories() {
return subCategories;
}

public void setSubCategories(Category[] subCategories) {
this.subCategories = subCategories;
}

}

public class Customer extends User {
private Cart cart;
public Cart getCart() {
return cart;
}
public void setCart(Cart cart) {
this.cart = cart;
}
@Override
public Boolean verifyUser() {
// TODO Auto-generated method stub
return true;
}

}

public class Order {
private String orderId;
private Customer user;

public String getOrderId() {
return orderId;
}

public void setOrderId(String orderId) {
this.orderId = orderId;
}

public Customer getUser() {
return user;
}

public void setUser(Customer user) {
this.user = user;
}

}

public class Product {
private String productId;
private String cost;
private String productName;

private Seller seller;

public Seller getSeller() {
return seller;
}

public void setSeller(Seller seller) {
this.seller = seller;
}

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 class Seller extends User{
private Product [] productsListed;
@Override
public Boolean verifyUser() {
// TODO Auto-generated method stub
return null;
}
public Product[] getProductsListed() {
return productsListed;
}
public void setProductsListed(Product[] productsListed) {
this.productsListed = productsListed;
}

}

import java.util.Scanner;

/*
* 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 products to the Cart, View Cart- Checkout.
*Seller- View your product, Add a product, Contact Us.
*View your product- delete this product. Add a product- Submit detail of the product.
*Administrator-...
*Product
*Category
*Cart
*Order
*/

public class Store {

public static void main(String[] args) {
// TODO Auto-generated method stub

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 product 2. View Cart 3. Contact Us 4. Exit");
choice = sc.nextInt();
if (choice == 1) {
Catalogue catalogue = new Catalogue();
Product[] allProducts = catalogue.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 Products 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);
// System.out.println(cartProducts[0].getProductName());
current.setCart(cart);
System.out.println("The Product is successfully added to the cart");
}
}
else if(choice==2) {
Product [] cartProducts= current.getCart().getListOfProducts();
System.out.println(current.getCart().getCartId());
for (int i=0; i<cartProducts.length; i++) {
System.out.println(i);
System.out.println(cartProducts[i].getProductId() + " " + cartProducts[i].getProductName() + " "
+ cartProducts[i].getCost());

}

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) {
System.out.println("To contact us, Please email on [email protected]");
}

else if(choice==4)
break;

else
System.out.println("Invalid choice, please try again.");
}
}

}

else if (choice == 2)
typeOfUser = "Seller";
else if (choice == 3)
typeOfUser = "Admin";
else
System.out.println("Invalid input. Try again");

}

}

public abstract class User {
String userId = " ";
String password = " ";
String loginStatus = " ";

abstract Boolean verifyUser();

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;
}

}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.