Project 1
package store;
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
import subproducts.Subproducts;
public class Store {
public static void shoppingProcess(Subproducts subproduct, Customer current){
Product [] allProducts = subproduct.getListOfProducts();
showProducts(allProducts);
addToCart(allProducts, current);
}
public static void showProducts(Product [] allProducts){
for(int i = 0; i < allProducts.length; i++){
System.out.println(allProducts[i].getProductId()+" "+allProducts[i].getProductName()+" "+allProducts[i].getCost());
}
}
public static Product [] addToCart(Product [] allProducts, Customer current){
Product [] cartProducts = new Product[1];
boolean isValid = true;
while(isValid){
System.out.println("Do you want to add any product to the cart? Enter 'Y' for YES and 'N' for NO");
Scanner sc = new Scanner(System.in);
String addToCart = sc.nextLine();
if(addToCart.equals("Y")){
System.out.println("Input the product id of product you wish to add to cart");
String productId = sc.nextLine();
for(int i = 0; i < allProducts.length; i++){
if(allProducts[i].getProductId().equals(productId)){
cartProducts[0] = allProducts[i];
}
}
Cart cart = new Cart();
cart.setListOfProducts(cartProducts);
current.setCart(cart);
System.out.println("The product is successfully added to cart!");
isValid = false;
}
else if(addToCart.equals("N")){
System.out.println("Okay! Going back to main menu");
isValid = false;
}
else{
System.out.println("Invalid input! Please enter 'Y' for YES and 'N' for NO");
continue;
}
}
return cart
Products;
}
public static void checkOut(Customer current){
boolean isValid = true;
while(isValid){
System.out.println("Do you want to checkout? Enter Y/N");
Scanner sc = new Scanner(System.in);
String checkout = sc.nextLine();
if(checkout.equals("Y")){
if(((Object) current.getCart()).checkOut()){
Order order = new Order();
order.setUser(current);
Customer orderCustomer = order.getUser();
order.setOrderId(current.getUserId());
String orderIdOfUser = order.getOrderId();
try{
Product [] cartProducts = ((Subproducts) current.getCart()).getListOfProducts();
for(int i = 0; i < cartProducts.length; i++){
File f1 = new File(orderIdOfUser+".txt");
f1.createNewFile();
FileWriter f1Writer = new FileWriter(orderIdOfUser+".txt");
f1Writer.write("Dear "+orderIdOfUser+", Your order "+orderCustomer+ " containing " +cartProducts[i].getProductName()+ " of total cost " + cartProducts[i].getCost()+ " is placed successfully!");
f1Writer.close();
System.out.println("Successfully generated order!");
System.out.println("Going back to main menu");
isValid = false;
}
}
catch(Exception e){
System.out.println("An error occurred.");
e.printStackTrace();
}
}
}
else if(checkout.equals("N")){
System.out.println("Okay! Going back to main menu");
isValid = false;
}
else{
System.out.println("Invalid input! Please enter 'Y' for YES and 'N' for NO");
continue;
}
}
}
public static void addSellerProducts(){
System.out.println("Enter the id of the new product");
Scanner sc = new Scanner(System.in);
String newProductId = sc.nextLine();
System.out.println("Enter the name of the new product");
String newProductName = sc.nextLine();
System.out.println("Enter the cost of the new product");
String newProductCost = sc.nextLine();
Product newProduct = new Product();
newProduct.setProductId(newProductId);
newProduct.setProductName(newProductName);
newProduct.setCost(newProductCost);
System.out.println("Your new added product is "+ newProduct.getProductId()+" "+newProduct.getProductName()+" "+newProduct.getCost());
}
public static Customer createCustomer(){
String typeOfUser;
typeOfUser = "Customer";
Scanner sc = new Scanner(System.in);
Customer current = new Customer();
System.out.println("What is your userId?");
current.setUserId(sc.nextLine());
System.out.println("What is your password?");
current.setPassword(sc.nextLine());
if(current.verifyUser() == true){
System.out.println("User verified!");
}
return current;
}
public static void createSeller(){
String typeOfUser;
typeOfUser = "Seller";
Scanner sc = new Scanner(System.in);
Seller this_seller = new Seller();
System.out.println("What is your sellerId?");
this_seller.setUserId(sc.nextLine());
System.out.println("What is your password?");
this_seller.setPassword(sc.nextLine());
if(this_seller.verifyUser() == true){
System.out.println("Seller verified!");
}
} public static void createAdmin(){
String typeOfUser;
typeOfUser = "Admin";
Admin this_admin = new Admin();
Scanner sc = new Scanner(System.in);
System.out.println("What is your adminId?");
this_admin.setUserId(sc.nextLine());
System.out.println("What is your password?");
this_admin.setPassword(sc.nextLine());
if(this_admin.verifyUser() == true){
System.out.println("Admin verified!");
}
}
public static void main(String[] args) {
System.out.println("Welcome to Store!");
System.out.println("Which type of user are you? 1. Customer 2. Seller 3. Admin");
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();
if(choice==1){
Customer current = createCustomer();
while(true){
System.out.println("Do you want to : 1. View Products 2. View Cart 3. Contact Us 4. Exit");
int userChoice = sc.nextInt();
if(userChoice==1){
System.out.println("Choose category of products : 1. Clothing 2. Electronics 3. Books ");
int userCategoryChoice = sc.nextInt();
if(userCategoryChoice == 1){
System.out.println("Explore clothing section : 1. Men 2. Women 3. Kids ");
int userSubCategoryChoice = sc.nextInt();
if(userSubCategoryChoice == 1){
Men men = new Men();
shoppingProcess(men, current);
}
else if(userSubCategoryChoice == 2){
Women women = new Women();
shoppingProcess(women, current);
}
else if(userSubCategoryChoice == 3){
Kids kids = new Kids();
shoppingProcess(kids, current);
}
else{
System.out.println("Invalid input! Try again");
}
}
else if(userCategoryChoice == 2){
System.out.println("Explore electronics section : 1. Mobiles 2. Laptops 3. TVs ");
int userSubCategoryChoice = sc.nextInt();
if(userSubCategoryChoice == 1){
Mobile mobile = new Mobile();
shoppingProcess(mobile, current);
}
else if(userSubCategoryChoice == 2){
Laptop laptop = new Laptop();
shoppingProcess(laptop, current);
}
else if(userSubCategoryChoice == 3){
TV tv = new TV();
shoppingProcess(tv, current);
}
else{
System.out.println("Invalid input! Try again");
}
}
else if(userCategoryChoice == 3){
System.out.println("Explore books section : 1. Adventure 2. Mythology 3. Fiction ");
int userSubCategoryChoice = sc.nextInt();
if(userSubCategoryChoice == 1){
Adventure adventure = new Adventure();
shoppingProcess(adventure, current);
}
else if(userSubCategoryChoice == 2){
Mythology mythology = new Mythology();
shoppingProcess(mythology, current);
}
else if(userSubCategoryChoice == 3){
Fiction fiction = new Fiction();
shoppingProcess(fiction, current);
}
else{
System.out.println("Invalid input! Try again");
}
}
}
else if(userChoice==2){
try{
Product [] cartProducts = ((Subproducts) current.getCart()).getListOfProducts();
for(int i = 0; i < cartProducts.length; i++){
System.out.println(cartProducts[i].getProductId()+" "+cartProducts[i].getProductName()+" "+cartProducts[i].getCost());
}
checkOut(current);
}
catch (Exception e){
System.out.println("No items in cart. Please add items to view the cart!");
}
}
else if(userChoice==3){
System.out.println("Please email us on store.ecomm.com");
}
else if(userChoice==4){
break;
}
else {
System.out.println("Invalid input! Please try again");
}
}
}
else if(choice==2){
createSeller();
while(true){
System.out.println("Do you want to : 1. Add Products 2. Contact company 3. Exit");
int sellerChoice = sc.nextInt();
if(sellerChoice==1){
System.out.println("Choose category you want to add product to : 1. Clothing 2. Electronics 3. Books");
int sellerCatgChoice = sc.nextInt();
if(sellerCatgChoice==1){
System.out.println("Choose sub-category you want to add product to : 1. Men 2. Women 3. Kids");
int sellerSubCatgChoice = sc.nextInt();
if((sellerSubCatgChoice==1) || (sellerSubCatgChoice==2) || (sellerSubCatgChoice==3)){
addSellerProducts();
}
}
else if(sellerCatgChoice==2){
System.out.println("Choose sub-category you want to add product to : 1. Mobiles 2. Laptops 3. TVs");
int sellerSubCatgChoice = sc.nextInt();
if((sellerSubCatgChoice==1) || (sellerSubCatgChoice==2) || (sellerSubCatgChoice==3)){
addSellerProducts();
}
}
else if(sellerCatgChoice==3){
System.out.println("Choose sub-category you want to add product to : 1. Adventure 2. Mythology 3. Fiction");
int sellerSubCatgChoice = sc.nextInt();
if((sellerSubCatgChoice==1) || (sellerSubCatgChoice==2) || (sellerSubCatgChoice==3)){
addSellerProducts();
}
}
else{
System.out.println("Invalid input! Please try again!");
}
}
else if(sellerChoice==2){
System.out.println("Please contact us by mail for any seller related queries : [email protected]");
}
else if(sellerChoice==3){
break;
}
else{
System.out.println("Invalid input! Please try again");
}
}
}
else if(choice==3){
createAdmin();
while(true){
System.out.println("Do you want to : 1. View Customer Products 2. View Seller Products 3. Contact customer 4. Contact Seller 5. Exit");
int adminChoice = sc.nextInt();
if(adminChoice==1){
Catalogue customerCatalogue = new Catalogue();
Product [] customerProducts = customerCatalogue.getListOfAllProducts();
showProducts(customerProducts);
}
else if(adminChoice==2){
Seller seller = new Seller();
Product [] sellerProducts = seller.getProductsListed();
showProducts(sellerProducts);
}
else if(adminChoice==3){
Admin a = new Admin();
String customerContact = a.getCustomerContact();
System.out.println("The customer can be contacted at " + customerContact);
}
else if(adminChoice==4){
Admin a1 = new Admin();
String sellerContact = a1.getSellerContact();
System.out.println("The seller can be contacted at " + sellerContact);
}
else if(adminChoice==5){
break;
}
else{
System.out.println("Invalid input! Please try again!");
}
}
}
else {
System.out.println("Invalid input! Please try again!");
}
sc.close();
}
package ecommerce;
public class Cart {
int cartNum;
String productName;
float total;
public Cart(int cartNum, String productName, float total) {
super();
this.cartNum = cartNum;
this.productName = productName;
this.total = total;
}
public Cart() {
super();
// TODO Auto-generated constructor stub
}
public int getCartNum() {
return cartNum;
}
public void setCartNum(int cartNum) {
this.cartNum = cartNum;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public float getTotal() {
return total;
}
public void setTotal(float total) {
this.total = total;
}
}
package ecommerce;
public class Customer {
int customerId;
String customerName;
int age;
public Customer(int customerId, String customerName, int age) {
super();
this.customerId = customerId;
this.customerName = customerName;
this.age = age;
}
public Customer() {
super();
// TODO Auto-generated constructor stub
}
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package ecommerce;
public class User {
User authentication() {
return null;
}
}
package ecommerce;
public class Catalog {
public static void main(String[] args)
{
String[] arr = { "Laptop", "Mobile", "Headset", "Speaker", "Television", "Airpodes" };
for (String i : arr) {
System.out.print(i + " ");
}
System.out.println();
}
}
package ecommerce;
import java.util.Scanner;
public class Administration {
public void checkadminoruser() {
System.out.println("Enter 1 for admin and 2 for normal user");
Scanner answer = new Scanner(System.in);
int option = answer.nextInt();
if (option == 1) {
System.out.println("Welcome Admin");
modifycatlog();
} else {
System.out.println("Welcome User");
}
}
private void modifycatlog() {
System.out.println("hai admin");
}
}