Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedList;
- import java.util.Scanner;
- public class ATM {
- static LinkedList<Customer> customerList = new LinkedList<Customer>();
- static Scanner sc = new Scanner(System.in);
- public static void main(String Args[]) {
- boolean cont = true;
- //Loop for login and creation
- while(cont){
- System.out.println(" ");
- System.out.println("Type Login to login or Create to create a new account");
- System.out.println(" ");
- String answer = sc.nextLine();
- if(answer.equalsIgnoreCase("create")) {
- customerCreation();
- } else if(answer.equalsIgnoreCase("login")){
- accountManipulation(login());
- }
- }
- sc.close();
- }
- public static Customer login() {
- System.out.println("Enter your name");
- String name = sc.nextLine();
- System.out.println("Enter your PIN");
- int PIN = sc.nextInt();
- for(int i = 0; i < customerList.size(); i++) {
- if(customerList.get(i).getName().equalsIgnoreCase(name) && customerList.get(i).getpIN() == PIN){
- System.out.println("Login Successful");
- return customerList.get(i);
- }
- }
- System.out.println("Login not found, try again");
- System.out.println();
- return null;
- }
- public static void customerCreation() {
- System.out.println("What is your name?");
- String nameX = sc.nextLine();
- int PIN = 0;
- boolean pin = true;
- while(pin) {
- System.out.println("Enter a 4 digit number to use as a pin:");
- PIN = sc.nextInt();
- if(PIN > 999 && PIN < 10000) {
- pin = false;
- } else {
- System.out.println("Entered PIN is not valid");
- }
- }
- Customer y = new Customer(nameX, PIN);
- customerList.add(y);
- accountCreation(y);
- }
- public static void accountCreation(Customer x) {
- boolean cont1 = true,cont2 = true,cont3 = true;
- int overdraft1 = 0, overdraft2 = 0, overdraft3 = 0;
- System.out.println("Enter starting amount for Checking account: ");
- int deposit1 = sc.nextInt();
- while(cont1) {
- System.out.println("Enter Overdraft Preference: ");
- System.out.println("1 - Deny withdraw if it is greater than balance");
- System.out.println("2 - Allow withdraw if it is greater than balance and fine 25$ to my account");
- overdraft1 = sc.nextInt();
- if(overdraft1 < 1 || overdraft1 > 2) {
- System.out.println("Invalid choice, try again");
- } else {
- cont1 = false;
- }
- }
- x.addAccount(new Checking(overdraft1));
- x.findAccount("Checking").deposit(deposit1);
- System.out.println("Enter starting amount for Savings account: ");
- int deposit2 = sc.nextInt();
- while(cont2) {
- System.out.println("Enter Overdraft Preference: ");
- System.out.println("1 - Deny withdraw if it is greater than balance");
- System.out.println("2 - Allow withdraw if it is greater than balance and fine 25$ to my account");
- overdraft2 = sc.nextInt();
- if(overdraft2 < 1 || overdraft2 > 2) {
- System.out.println("Invalid choice, try again");
- } else {
- cont2 = false;
- }
- }
- x.addAccount(new Savings(overdraft2));
- x.findAccount("Savings").deposit(deposit2);
- System.out.println("Enter starting amount for Business account: ");
- int deposit3 = sc.nextInt();
- while(cont3) {
- System.out.println("Enter Overdraft Preference: ");
- System.out.println("1 - Deny withdraw if it is greater than balance");
- System.out.println("2 - Allow withdraw if it is greater than balance and fine 25$ to my account");
- overdraft3 = sc.nextInt();
- if(overdraft3 < 1 || overdraft3 > 2) {
- System.out.println("Invalid choice, try again");
- } else {
- cont3 = false;
- }
- }
- x.addAccount(new Business(overdraft3));
- x.findAccount("Business").deposit(deposit3);
- }
- public static void accountManipulation(Customer x) {
- boolean cont = true;
- if(x == null) {
- cont = false;
- }
- while(cont) {
- System.out.println("Hello " + x.getName());
- System.out.println("Enter the number of the option you want.");
- System.out.println("1 - View all accounts");
- System.out.println("2 - Make a deposit");
- System.out.println("3 - Make a transfer");
- System.out.println("4 - Make a withdraw");
- System.out.println("5 - Change PIN");
- System.out.println("6 - View UID");
- System.out.println("7 - Logout");
- int choice = sc.nextInt();
- switch(choice) {
- case 1:
- x.showAccounts();
- break;
- case 2:
- System.out.println("How much do you want to deposit?");
- int deposit = sc.nextInt();
- System.out.println("What account do you want to deposit to?");
- System.out.println("1 - Savings");
- System.out.println("2 - Checking");
- System.out.println("3 - Business");
- int choice2 = sc.nextInt();
- switch(choice2) {
- case 1:
- if(x.findAccount("Savings") == null) {
- System.out.println("Account not found, try again");
- break;
- }
- x.findAccount("Savings").deposit(deposit);
- break;
- case 2:
- if(x.findAccount("Checking") == null) {
- System.out.println("Account not found, try again");
- break;
- }
- x.findAccount("Checking").deposit(deposit);
- break;
- case 3:
- if(x.findAccount("Business") == null) {
- System.out.println("Account not found, try again");
- break;
- }
- x.findAccount("Business").deposit(deposit);
- break;
- }
- break;
- case 3:
- System.out.println("How much do you want to transfer?");
- double transfer = sc.nextDouble();
- System.out.println("Enter the UID of the person you want to transfer to.");
- int uid = sc.nextInt();
- int person = 0;
- for(int i = 0; i < customerList.size(); i++) {
- if(customerList.get(i).getuID() == uid) {
- person = i;
- }
- }
- String from;
- System.out.println("What account do you want to transfer from?");
- System.out.println("1 - Savings");
- System.out.println("2 - Checking");
- System.out.println("3 - Business");
- int choice1 = sc.nextInt();
- if(choice1 == 1) {
- from = "Savings";
- } else if(choice == 2) {
- from = "Checking";
- } else if(choice == 3) {
- from = "Business";
- } else {
- from = "Checking";
- }
- System.out.println("What account do you want to transfer to?");
- System.out.println("1 - Savings");
- System.out.println("2 - Checking");
- System.out.println("3 - Business");
- int choice3 = sc.nextInt();
- switch(choice3) {
- case 1:
- if(!x.findAccount(from).transfer(transfer, customerList.get(person).findAccount("Savings"))) {
- System.out.println("Transfer Failed");
- }
- break;
- case 2:
- if(!x.findAccount(from).transfer(transfer, customerList.get(person).findAccount("Checking"))) {
- System.out.println("Transfer Failed");
- }
- break;
- case 3:
- if(!x.findAccount(from).transfer(transfer, customerList.get(person).findAccount("Business"))) {
- System.out.println("Transfer Failed");
- }
- break;
- }
- break;
- case 4:
- System.out.println("How much do you want to withdraw?");
- int withdraw = sc.nextInt();
- System.out.println("What account do you want to withdraw from?");
- System.out.println("1 - Savings");
- System.out.println("2 - Checking");
- System.out.println("3 - Business");
- int choice4 = sc.nextInt();
- switch(choice4) {
- case 1:
- x.findAccount("Savings").withdraw(withdraw);
- break;
- case 2:
- x.findAccount("Checking").withdraw(withdraw);
- break;
- case 3:
- x.findAccount("Business").withdraw(withdraw);
- break;
- }
- break;
- case 5:
- int newPIN = 0;
- int oldPIN = 0;
- System.out.println("Enter your current PIN");
- oldPIN = sc.nextInt();
- System.out.println("Enter new PIN");
- newPIN = sc.nextInt();
- if(x.changePIN(newPIN, oldPIN) == false) {
- System.out.println("Incorrect PIN entered.");
- } else {
- System.out.println("Pin changed");
- }
- break;
- case 6:
- System.out.println("Your UID is: " + x.getuID());
- break;
- case 7:
- System.out.println("You have logged out.");
- cont = false;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement