Untitled

 avatar
unknown
plain_text
2 years ago
4.8 kB
4
Indexable
import java.util.ArrayList;
import java.util.Scanner;



public class Main {

    private static ArrayList<Book> books = new ArrayList<>();
    private static ArrayList<User> users = new ArrayList<>();
    private static ArrayList<Cd> cds = new ArrayList<>();
    private static ArrayList<DVD> dvds = new ArrayList<>();
    public static User activeUser;
    private static double cart;
    
 public static void listBooks(){
     Book book = new Book("The Giver", "Lois Lowry", 12.00);
     Book book1 = new Book("Pale Fire", "Vladmir Nabokov", 15.00);
     Book book2 = new Book("In Cold Blood", "Truman Capote", 18.00);
     books.add(book);
     books.add(book1);
     books.add(book2);
     
 }
 
public static void listUsers(){
    User bai = new User("Bai","Premium","ILOVEBAI123");
    User kaylin = new User("Kaylin", "Regular", "YAYAYA!123");
    User bryan = new User("Bryan", "Regular", "NotARealFan123");
    users.add(bai);
    users.add(kaylin);
    users.add(bryan);
    
    
}

public static void listCds(){
    Cd Sativa = new Cd("Sativa", "Jhene", 20.00);
    Cd NoStylist = new Cd("NEVEREVER", "Destroy Lonley", 50.00);
    Cd Pride = new Cd("Pride.", "Kendrick Lamar", 30.00);
    cds.add(Sativa);
    cds.add(NoStylist);
    cds.add(Pride);
}

public static void listDVD(){

    DVD Thor = new DVD("Thor", "Action", 20.00);
    DVD Spiderman = new DVD("Spiderman", "Action", 30.00);
    DVD Hulk = new DVD("Hulk", "Action", 20.00);
    dvds.add(Thor);
    dvds.add(Spiderman);
    dvds.add(Hulk);
    
}



public static void login(){
    for (User User : users) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Username: ");
        String userName = scanner.next();
        System.out.println("Membership: ");
        String userMembership = scanner.next();
        System.out.println("Password: ");
        String passWord = scanner.next();
        if(User.getUserName().equals(userName) && User.getPassWord().equals(passWord)){
            System.out.println("You have been logged in!");
            activeUser = User;
        }
    }
        
        
    }

 public static void signup() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Username: ");
        String userName = scanner.next();
        System.out.println("Membership: ");
        String userMembership = scanner.next();
        System.out.println("Password: ");
        String password = scanner.next();

       
       User newUser = new User(userName, userMembership, password);
       activeUser = newUser;
       cart += 30;
       users.add(newUser);
       System.out.println("Registered successfully");
 }
    

    public static void addToCart(){
        cart = 0;
        Scanner scanner = new Scanner(System.in);
        double choice = 0;
        for(int i = 0; 1 < 15; i++) {
            System.out.println(i + "-" + books.get(i).getBookTitle());
        }
        
    

    }
    

    public static void pay(){
        System.out.println("Thank you " + activeUser.getUserName()+ "!!!" + "You have purchased " + cart + "$");
        cart = 0;
    }


    public static void main(String[] args){
    listUsers();
    listBooks();
    listCds();
    listDVD();
    Scanner scanner = new Scanner(System.in);
    
    while(true){
        int choice = 0;
        if(activeUser == null){
            
            System.out.println("Welcome to The Online Library.");
            System.out.println("Pick an option:");
            String options = "1. log in as an existing user\n"
            + "2. Buy as a customer\n"
            + "3. EXIT";
            
            System.out.println(options);
            choice = scanner.nextInt();
           if (choice == 1){
               login();
           } else if (choice == 2) {
               activeUser = new User ("temporaryID", "Regular", "temporaryPass");
               addToCart();
           } else {
               break;
           }
           
            
        } else {
            System.out.println("Purchase Book/s");
            if (cart != 0){
                System.out.println("Pay");
                System.out.println("Exit");
                
            }  else {
               System.out.println("SYSTEM DOWN");
            }
            choice = scanner.nextInt();
            if (choice == 1) {
                addToCart();
            } else if (cart != 0 && choice == 2 ){
                pay();
            } else {
                System.out.println("Thank you for shopping here!");
                break;
            }
        } 
                
    }
}
}
Editor is loading...