Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class CheckingAccount {
- private String accountNumber, accountHolder;
- private int balance = 0, useCount = 0;
- CheckingAccount( String accNumber, String holder, String password, int start ) {
- accountNumber = accNumber ;
- accountHolder = holder ;
- balance = start ;
- }
- int getBalance() {
- return balance;
- }
- void processDeposit( int amount ) {
- if (((balance + amount) < 2000000000) && amount < 2000000000) {
- balance += amount;
- System.out.println("Deposited " + amount + " into account.");
- System.out.println("Balance is now " + balance);
- skipLine(2);
- } else {
- System.out.println("Overflow - deposit is too high.");
- }
- }
- void processDeposit (int amount, int charge) {
- balance += (amount-charge);
- System.out.println("Deposited " + amount + " into account with a " + charge + " cent fee.");
- System.out.println("Balance is now " + balance);
- skipLine(2);
- }
- void processCheck( int amount ) {
- int charge;
- if ( balance < 100000 ) {
- charge = 15;
- } else {
- charge = 0;
- }
- balance -= (amount + charge) ;
- System.out.println("Withdrew " + amount + " from account with a " + charge + " cent fee.");
- System.out.println("Balance is now " + balance);
- skipLine(2);
- }
- void display() {
- System.out.println("Account number: " + accountNumber + " || Owner: " + accountHolder + " || Current Balance: " + getBalance());
- skipLine(2);
- }
- void skipLine(int c) {
- for (int i = 0; i < c; i++) {
- System.out.println("");
- }
- }
- void payOther(int amount, CheckingAccount c) {
- processCheck(amount);
- c.processDeposit(amount);
- System.out.println(
- "Paid " + amount + " to another account, current balance is now " + balance +
- ". Other person's balance is now " + c.getBalance() + "."
- );
- skipLine(2);
- }
- }
- class methods {
- int i = 0, status = 0, j = 0, response = 0;
- String input = "";
- Scanner scan = new Scanner( System.in );
- CheckingAccount David = new CheckingAccount( "92a-44-35", "David", "123123", 10000000 );
- CheckingAccount Mei = new CheckingAccount( "92a-44-33", "Mei", "123123a", 0 );
- CheckingAccount Feng = new CheckingAccount( "92a-44-34", "Feng", "123123a", 50000);
- CheckingAccount currentAccount = null;
- CheckingAccount destinedAccount = null;
- String[] userNames = {"David", "Mei", "Feng"};
- String[] passKeys = {"123123", "123123a", "123123a"};
- String thisUser = "", menuResponse = "";
- public void login() {
- System.out.println("Please enter your account name:");
- String username = scan.next();
- for (i = 0; i<userNames.length; i++) {
- if (username.equalsIgnoreCase(userNames[i])) {
- thisUser = userNames[i];
- j = i;
- status = 2;
- }
- }
- if (thisUser == "") {
- System.out.println("Invalid user.");
- }
- }
- public void welcome() {
- System.out.println(
- "What would you like to access today? " +
- "\r\n1: account"
- );
- input = scan.next();
- if (input.equalsIgnoreCase("account")) {
- status = 1;
- } else {
- System.out.println("Invalid.");
- }
- }
- public void checkPassword() {
- String passKey = scan.next();
- if (passKey.equalsIgnoreCase(passKeys[j])) {
- System.out.println("Account confirmed.");
- status = 3;
- } else {
- System.out.println("Wrong password.");
- }
- }
- public int getStatus() {
- return status;
- }
- public void mainMenu() {
- System.out.println("Main menu:\r\n1. Deposit\r\n2. Withdraw\r\n3. Transfer Funds (xfer)\r\n4. Check balance\r\n5. Logout");
- menuResponse = scan.next();
- postMenu();
- }
- public void postMenu() {
- if (menuResponse.equalsIgnoreCase("deposit")) {
- response = 1;
- status = 4;
- } else if (menuResponse.equalsIgnoreCase("withdraw")) {
- response = 2;
- status = 4;
- } else if (menuResponse.equalsIgnoreCase("xfer")) {
- response = 3;
- status = 4;
- } else if (menuResponse.equalsIgnoreCase("balance")) {
- response = 4;
- status = 4;
- } else if (menuResponse.equalsIgnoreCase("logout")) {
- response = 5;
- status = 4;
- } else {
- System.out.println("Invalid, please try another option.");
- mainMenu();
- }
- }
- public void accessAccount() {
- if (thisUser.equalsIgnoreCase("David")) {
- System.out.println("Confirmed. Please enter your password:");
- currentAccount = David;
- } else if (thisUser.equalsIgnoreCase("Mei")) {
- System.out.println("Confirmed. Please enter your password:");
- currentAccount = Mei;
- } else if (thisUser.equalsIgnoreCase("Feng")) {
- System.out.println("Confirmed. Please enter your password:");
- currentAccount = Feng;
- }
- }
- public void redirection() {
- if (response == 1) {
- deposit();
- } else if (response == 2) {
- withdraw();
- } else if (response == 3) {
- xfer();
- } else if (response == 4) {
- checkThisBalance();
- } else if (response == 5) {
- logout();
- }
- }
- public void deposit() {
- System.out.println("How much would you like to deposit?");
- String amount = scan.next();
- int thisAmount = Integer.parseInt(amount);
- currentAccount.processDeposit(thisAmount);
- status = 3;
- mainMenu();
- }
- public void withdraw() {
- System.out.println("How much would you like to withdraw?");
- String amount = scan.next();
- int thisAmount = Integer.parseInt(amount);
- currentAccount.processCheck(thisAmount);
- status = 3;
- mainMenu();
- }
- public void xfer() {
- System.out.println("Who do you want to wire your money to?");
- String userInput = scan.next();
- if (userInput.equalsIgnoreCase("David")) {
- destinedAccount = David;
- } else if (userInput.equalsIgnoreCase("Mei")) {
- destinedAccount = Mei;
- } else if (userInput.equalsIgnoreCase("Feng")) {
- destinedAccount = Feng;
- } else {
- destinedAccount = currentAccount;
- }
- System.out.println("Please enter the amount you want to wire over:");
- String amountString = scan.next();
- int thisAmount = Integer.parseInt(amountString);
- currentAccount.payOther(thisAmount, destinedAccount);
- status = 3;
- mainMenu();
- }
- public void checkThisBalance() {
- currentAccount.display();
- status = 3;
- mainMenu();
- }
- public void logout() {
- currentAccount = null;
- System.out.println("Logged off! Goodbye.");
- status = 0;
- }
- }
- class CheckingAccountTester {
- public static void main( String[] args ) {
- methods m = new methods();
- int omg = 0;
- while (omg == 0) {
- if (m.getStatus() == 0) {
- m.welcome();
- }
- if (m.getStatus() == 1) {
- m.login();
- m.accessAccount();
- }
- if (m.getStatus() == 2) {
- m.checkPassword();
- }
- if (m.getStatus() == 3) {
- m.mainMenu();
- }
- if (m.getStatus() == 4) {
- m.redirection();
- } else {
- m.redirection();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment