Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab_class_04_Feb_ex5_q3;
- import java.util.*;
- public class Devansh20BCE0410 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner ReadInput = new Scanner(System.in);
- ArrayList<customer> Customers = new ArrayList<customer>();
- int choice;
- boolean flag = true;
- while(flag) {
- // Menu
- System.out.println("\n\t Welcome to Example Bank!\n\tBy Devansh Sehgal 20BCE0410\n");
- System.out.println("1. Open an account");
- System.out.println("2. Deposit money");
- System.out.println("3. See account details");
- System.out.println("4. Change address");
- System.out.println("5. Change phone number");
- System.out.println("6. Change email ID");
- System.out.println("7. View all costumers (requires admin accesss)");
- System.out.println("8. Generate list (requires admin accesss)");
- System.out.println("9. Exit");
- System.out.print(">> ");
- choice = ReadInput.nextInt();
- int index;
- // switch
- switch(choice) {
- case 1:
- // Create account
- Customers.add(new customer());
- break;
- case 2:
- // Deposit
- index = login(Customers);
- if (index >= 0) {
- Customers.get(index).deposit();
- }
- break;
- case 3:
- // Show Account details
- index = login(Customers);
- if (index >= 0) {
- Customers.get(index).showCustomer();
- }
- break;
- case 4:
- // Change Address
- index = login(Customers);
- if (index >= 0) {
- Customers.get(index).changeAddress();
- }
- break;
- case 5:
- // Change phone number
- index = login(Customers);
- if (index >= 0) {
- Customers.get(index).changePhone();
- }
- break;
- case 6:
- // Change email
- index = login(Customers);
- if (index >= 0) {
- Customers.get(index).changeEmail();
- }
- break;
- case 7:
- // view all customers
- if (customer.adminLogin()) {
- for (customer c : Customers) {
- System.out.println();
- c.showCustomer();
- }
- }
- break;
- case 8:
- // Generate list
- if (customer.adminLogin()) {
- System.out.println("Input max balance:");
- float maxBalance = ReadInput.nextFloat();
- for (customer c : Customers) {
- if (c.getBalance() <= maxBalance) {
- System.out.println();
- c.showCustomer();
- }
- }
- }
- break;
- case 9:
- flag = false;
- break;
- default:
- System.out.println("Invalid choice, try again!");
- break;
- }
- }
- System.out.println();
- System.out.println("\tThank you for using our service!");
- ReadInput.close();
- }
- static int login(ArrayList<customer> Customers) {
- Scanner login_sc = new Scanner(System.in);
- System.out.println("\nInput ID:");
- String id = login_sc.nextLine();
- System.out.println("\nInput PIN:");
- String pin = login_sc.nextLine();
- for(customer c : Customers) {
- if (id.equals(c.getID())) {
- if (c.checkPIN(pin)) {
- return Customers.indexOf(c);
- }
- else {
- System.out.println("Wrong PIN!");
- return -1;
- }
- }
- }
- System.out.println("Customer not found!");
- return -1;
- }
- }
- class customer{
- private static String adminID = "Admin";
- private static String adminPass = "1234";
- protected String ID;
- protected String email;
- private String pin;
- protected float balance;
- protected String address;
- protected String phone;
- public customer() {
- Scanner openacc_sc = new Scanner(System.in);
- System.out.println();
- System.out.println("Input ID:");
- this.ID = openacc_sc.nextLine();
- System.out.println("Input PIN:");
- this.pin = openacc_sc.nextLine();
- System.out.println("Input email:");
- this.email = openacc_sc.nextLine();
- System.out.println("Input Address:");
- this.address = openacc_sc.nextLine();
- System.out.println("Input phone number:");
- this.phone = openacc_sc.nextLine();
- System.out.println("Input initial balance:");
- this.balance = openacc_sc.nextFloat();
- System.out.println("\nAccount Created!");
- }
- public String getID() {
- return this.ID;
- }
- public float getBalance() {
- return this.balance;
- }
- public boolean checkPIN(String pin) {
- return this.pin.equals(pin);
- }
- public void deposit() {
- Scanner deposit_sc = new Scanner(System.in);
- System.out.println();
- System.out.println("Current Balance: " + this.balance);
- System.out.println("\nInput deposit amount: ");
- this.balance += deposit_sc.nextFloat();
- System.out.println("\nAmount Deposited!\nNew Balance: " + this.balance);
- }
- public void changeAddress() {
- Scanner chAdd_sc = new Scanner(System.in);
- System.out.println();
- System.out.println("Old Address:");
- System.out.println(this.address);
- System.out.println("\nInput new address:");
- this.address = chAdd_sc.nextLine();
- System.out.println("\nAddress changed!");
- }
- public void changePhone() {
- Scanner chPh_sc = new Scanner(System.in);
- System.out.println();
- System.out.println("Old phone number:");
- System.out.println(this.phone);
- System.out.println("\nInput new phone number:");
- this.phone = chPh_sc.nextLine();
- System.out.println("\nPhone number changed!");
- }
- public void changeEmail() {
- Scanner chEm_sc = new Scanner(System.in);
- System.out.println();
- System.out.println("Old email:");
- System.out.println(this.email);
- System.out.println("\nInput new email:");
- this.email = chEm_sc.nextLine();
- System.out.println("\nEmail changed!");
- }
- public void showCustomer() {
- System.out.println();
- System.out.println("ID: " + this.ID);
- System.out.println("Email: " + this.email);
- System.out.println("Phone: " + this.phone);
- System.out.println("Address: " + this.address);
- System.out.println("Balance: " + this.balance);
- }
- public static boolean adminLogin() {
- Scanner adminLogin_sc = new Scanner(System.in);
- System.out.println();
- System.out.println("Input Admin ID:");
- String inp_id = adminLogin_sc.nextLine();
- System.out.println("Input Admin password:");
- String inp_pin = adminLogin_sc.nextLine();
- if (adminID.equals(inp_id) && adminPass.equals(inp_pin)) {
- return true;
- }
- else {
- System.out.println("Admin Login Failed!");
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement