Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Name: Rob H
- //Date: 05/03/2011
- //Desc: FINAL
- /*
- CHECKLIST
- do these in order.
- [ ] Works!!
- [ ] Indentation.
- [ ] Documentation everywhere.
- [ ] Fiddle around with the security for the prefixes
- [lol] Innovation...?
- */
- import java.util.Date;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.*;
- import javax.swing.*;
- public class AtmHerman
- {
- /*
- CHECKLIST
- [x] array of objects
- [x] ask for account number (ask for "debit card") + convert to int.
- [x] compare ^ to CheckingAccountCustomer object's accountNo
- [x] ask for PIN
- [x] compare pin.
- [x] 3 chances then quit.
- [x] interface, date + time, d/w/c/q
- [ ] from this, call the appropriate CheckingAccountCustomer class
- [x] loop to let customer perform another action.
- [lol] innovation
- */
- public static void main(String[] args)
- {
- int cleared = 0;
- //Have to use two arrays for this.
- int[] acc = {0,11112222, 22223333, 33334444};
- int[] pin = {0,1111, 2222, 3333};
- //Ask user for account num "insert card"
- String input1 = JOptionPane.showInputDialog("Please insert card (8 numbers): ");
- int convert1 = Integer.parseInt(input1);
- //Now that we have a number, compare it to acc[]
- int match = 0;
- int position = 0;
- for (int i = 0; i < 4; i++)
- {
- if (convert1 == acc[i])
- {
- position = i;
- }
- else
- {
- //nothing
- }
- }
- //REMOVE ONCE CONFIRMED WORKING (the two lines below)
- System.out.println("position=" + position + " acc[position]=" + acc[position]);
- System.out.println("pin should be: " + pin[position]);
- //If position = 0, end program.
- if (position == 0)
- {
- System.out.println("Account number invalid. Please contact your bank.");
- System.exit(0);
- }
- //Ask for pin.
- String input2 = JOptionPane.showInputDialog("Please enter pin (4 numbers): ");
- int convert2 = Integer.parseInt(input2);
- //Loop. If it fails, close the program.
- int Three_Strikes = 0;
- for (int lol = 0; cleared < 1; lol++) //there's probably a better way to do this.
- {
- if (convert2 == pin[position])
- {
- cleared = 1;
- }
- else
- {
- Three_Strikes = Three_Strikes + 1;
- //REMOVE ONCE CONFIRMED WORKING (the one line below)
- System.out.println("Three_Strikes=" + Three_Strikes);
- if (Three_Strikes == 3)
- {
- System.exit(0);
- }
- input2=JOptionPane.showInputDialog("PIN does not match. Please try again.");
- convert2 = Integer.parseInt(input2);
- }
- }
- //REMOVE ONCE CONFIRMED WORKING (the one line below)
- System.out.println("cleared = " + cleared);
- //bogus information for every account
- String a = "Curly Brace";
- double b = 100.01;
- CheckingAccountCustomer cust = new CheckingAccountCustomer("Curly Brace", 2222, 100.01, 12341234);
- //interface
- String loop = "";
- while (loop != "Q")
- {
- loop = JOptionPane.showInputDialog(AtmHerman.getDateTime() + "\nWelcome " + cust.getName() + ".\n(D)eposit Money\n(W)ithdraw Money\n(C)heck Account Balance\n(Q)uit");
- loop = loop.toUpperCase();
- if (loop.equals("D"))
- {
- cust.deposit();
- }
- else if (loop.equals("W"))
- {
- cust.withdraw();
- }
- else if (loop.equals("C"))
- {
- cust.checkBalance();
- }
- else if (loop.equals("Q"))
- {
- System.out.println("Goodbye!");
- cust.quit();
- } //Exit the program.
- else
- System.out.println("Input Error");
- }
- }
- //Date and time.
- private static String getDateTime()
- {
- Calendar cal = Calendar.getInstance();
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
- return sdf.format(cal.getTime());
- }
- public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm";
- }
- abstract class Customer
- {
- /*
- CHECKLIST
- [x]data fields name pin balance
- [x]3 accessor methods (return) getName() returns <i>name</i>
- [x]1 constructor method, name pin balance
- [x]4 abstract (deposit ... ... exit)
- */
- //Declare variables.
- String name = "";
- int pin = 0;
- double balance = 0.0;
- //Constructor
- public Customer(String n, int p, double b)
- {
- name = n;
- pin = p;
- balance = b;
- }
- public Customer()
- {
- name = "";
- pin = 0;
- balance = 0.0;
- }
- //Accessors
- public String getName()
- {
- return name;
- }
- public int getPin()
- {
- return pin;
- }
- public double getBalance()
- {
- return balance;
- }
- //These don't do anything until they get inherited.
- //deposit(), withdraw(), checkBalance(), and quit().
- abstract public void deposit();
- abstract public void withdraw();
- abstract public void checkBalance();
- abstract public void quit();
- }
- class CheckingAccountCustomer extends Customer
- {
- /*
- CHECKLIST
- [x]Data field? accountNo
- [x]return getAccountNo method
- [x]constructor name pin balance accountNo
- [x]deposit: Prompt a customer to enter an amount of money to be deposited into his/her account. Add this amount to the balance and print the current balance as of the current date/time to the screen.
- [x]withdraw: Prompt a customer to enter an amount of money to withdraw from account. Deduct this amount to the balance and print the current balance as of the current date/time to the screen.
- [x]checkBalance: This method just prints the current balance as of the current date/time to the screen.
- [x]quit: duh. System.exit(0);
- */
- int accountNo = 0;
- //Constructor
- public CheckingAccountCustomer(String n, int p, double b, int a)
- {
- super(n, p, b);
- accountNo = a;
- }
- public void deposit()
- {
- String input3 = JOptionPane.showInputDialog("How much are you depositing? ");
- double convert3 = Double.parseDouble(input3);
- balance = balance + convert3;
- System.out.println("As of " + CheckingAccountCustomer.getDateTime() + " your balance is " + balance);
- }
- public void withdraw()
- {
- String input4 = JOptionPane.showInputDialog("How much are you withdrawing? ");
- double convert4 = Double.parseDouble(input4);
- balance = balance - convert4;
- if(balance < 0)
- {
- balance = balance + convert4;
- System.out.println("Insufficient funds.");
- }
- else
- {
- System.out.println("As of " + CheckingAccountCustomer.getDateTime() + " your balance is " + balance);
- }
- }
- public void checkBalance()
- {
- System.out.println("As of " + CheckingAccountCustomer.getDateTime() + " your balance is " + balance);
- }
- public void quit()
- {
- System.exit(0);
- }
- //Date and time.
- private static String getDateTime()
- {
- Calendar cal = Calendar.getInstance();
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
- return sdf.format(cal.getTime());
- }
- public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm";
- //Possible reference but probably all garbage
- /*
- boolean active = true;
- public SavingsAccount(double balance, double interest_rate) //constructor
- {
- super.BankAccount(balance, interest_rate);
- }
- public void withdraw(double withdrawal)
- {
- if (active == false) //Check if active. If not, its a no go.
- System.out.println("The account is inactive, because the balance is below $25.");
- else // If it is active, do the withdrawal through the superclass _
- // and check if its below 25 to make it inactive
- super.withdraw(withdrawal, num_wd);
- if (balance < 25)
- active = false;
- System.out.println("Your new balance is: " + balance);
- }
- *//*
- public void deposit(double deposit)
- {
- if (active == false)
- if (balance + deposit >= 25)
- active = true;
- super.deposit(deposit, num_wd);
- System.out.println("Your new balance is: " + balance);
- }
- *//*
- public void monthlyProcess()
- {
- if (num_wd > 4)
- service_charge = service_charge + num_wd - 4;
- super.monthlyProcess(num_dep, num_wd);
- if (balance < 25)
- active = false;
- System.out.println("Your new balance is: " + balance);
- }
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement