Challenge

Project 1

/*
* Ask which type of user are you? Customer , seller, Administrator
* User- Customer, Seller, Administrator
* Customer- View Product, View Cart, Contact Us
* View Product- Add the product, Add a product, View cart- checkout.
* Seller- View your product, Add a product, Contact Us
* View your products - delete this product. Add a product- Submit details of the product
* Administrator-....
* Products-
* Categories of product
* Cart
* Order
*
* */
import java.util.*;
public class Store {
public static void main(String[] args) {
System.out.println("Welcome to my store!!");
int choice;
String typeOfUser;
do {
System.out.println("Which user are you? 1. Coustomer 2. Seller 3.Admin: ");
Scanner sc = new Scanner(System.in);
choice = sc.nextInt();
switch (choice) {
case 1: {
typeOfUser = "Customer";
Customer current = new Customer();
System.out.println("What is your userId ?");
current.setUserId(sc.next());
System.out.println("What is your password ?");
current.setPassword(sc.next());
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. To 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();
// String anotherName = addToCart;
Cart cart = new Cart();
cart.setCardId("1");
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[50];
for (int i = 0; i < allProducts.length; i++) {
if (allProducts[i].getProductId().equals(productId))
cartProducts[0] = allProducts[i];
}
// Cart cart = new Cart();
// cart.setCardId("1");
cart.setListOfProducts(cartProducts);
current.setCart(cart);
System.out.println("The product is successfully added to the cart.");
}else
break;
} else if (choice == 2) {
Product[] cartProducts = current.getCart().getListOfProducts();
System.out.println(current.getCart().getCardId());
for (int i = 0; i < cartProducts.length; 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.");
}
}
}
break;
}
case 2: {
typeOfUser = "Seller";
break;
}
case 3: {
typeOfUser = "Admin";
break;
}
default:
System.out.println("Invalid user, Try Again!");
}
} while (choice >= 4);
}
}
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.