Advertisement
inferno719

Java doesn't like me.

May 3rd, 2011
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.00 KB | None | 0 0
  1. //Name: Rob H
  2. //Date: 05/03/2011
  3. //Desc: FINAL
  4. /*
  5. CHECKLIST
  6. do these in order.
  7. [ ] Works!!
  8. [ ] Indentation.
  9. [ ] Documentation everywhere.
  10. [ ] Fiddle around with the security for the prefixes
  11. [lol] Innovation...?
  12. */
  13. import java.util.Date;
  14. import java.text.DateFormat;
  15. import java.text.SimpleDateFormat;
  16. import java.util.*;
  17. import javax.swing.*;
  18.  
  19.  
  20. public class AtmHerman
  21. {
  22. /*
  23. CHECKLIST
  24. [x] array of objects
  25. [x] ask for account number (ask for "debit card") + convert to int.
  26. [x] compare ^ to CheckingAccountCustomer object's accountNo
  27. [x] ask for PIN
  28. [x] compare pin.
  29. [x] 3 chances then quit.   
  30. [x] interface, date + time, d/w/c/q
  31. [ ] from this, call the appropriate CheckingAccountCustomer class
  32. [x] loop to let customer perform another action.
  33. [lol] innovation
  34. */
  35.     public static void main(String[] args)
  36.     {
  37.         int cleared = 0;
  38.  
  39.         //Have to use two arrays for this.
  40.         int[] acc = {0,11112222, 22223333, 33334444};
  41.         int[] pin = {0,1111, 2222, 3333};
  42.         //Ask user for account num "insert card"
  43.         String input1 = JOptionPane.showInputDialog("Please insert card (8 numbers): ");
  44.         int convert1 = Integer.parseInt(input1);
  45.         //Now that we have a number, compare it to acc[]
  46.         int match = 0;
  47.         int position = 0;
  48.         for (int i = 0; i < 4; i++)
  49.         {
  50.             if (convert1 == acc[i])
  51.             {
  52.                 position = i;
  53.             }
  54.             else
  55.             {
  56.                 //nothing
  57.             }
  58.         }
  59.         //REMOVE ONCE CONFIRMED WORKING (the two lines below)
  60.         System.out.println("position=" + position + "  acc[position]=" + acc[position]);
  61.         System.out.println("pin should be: " + pin[position]);
  62.         //If position = 0, end program.
  63.         if (position == 0)
  64.         {
  65.             System.out.println("Account number invalid.  Please contact your bank.");
  66.             System.exit(0);
  67.         }
  68.         //Ask for pin.  
  69.         String input2 = JOptionPane.showInputDialog("Please enter pin (4 numbers): ");
  70.         int convert2 = Integer.parseInt(input2);
  71.         //Loop.  If it fails, close the program.  
  72.         int Three_Strikes = 0;
  73.         for (int lol = 0; cleared < 1; lol++) //there's probably a better way to do this.
  74.         {
  75.             if (convert2 == pin[position])
  76.             {
  77.                 cleared = 1;
  78.             }
  79.             else
  80.             {
  81.                 Three_Strikes = Three_Strikes + 1;
  82.                 //REMOVE ONCE CONFIRMED WORKING (the one line below)
  83.                 System.out.println("Three_Strikes=" + Three_Strikes);
  84.                 if (Three_Strikes == 3)
  85.                 {
  86.                     System.exit(0);
  87.                 }
  88.                 input2=JOptionPane.showInputDialog("PIN does not match.  Please try again.");
  89.                 convert2 = Integer.parseInt(input2);
  90.             }
  91.         }
  92.         //REMOVE ONCE CONFIRMED WORKING (the one line below)
  93.         System.out.println("cleared = " + cleared);
  94.        
  95.         //bogus information for every account
  96.         String a = "Curly Brace";
  97.         double b = 100.01;
  98.        
  99.        
  100.        
  101.        
  102.         CheckingAccountCustomer cust = new CheckingAccountCustomer("Curly Brace", 2222, 100.01, 12341234);
  103.  
  104.        
  105.        
  106.         //interface
  107.         String loop = "";
  108.         while (loop != "Q")
  109.         {
  110.             loop = JOptionPane.showInputDialog(AtmHerman.getDateTime() + "(D)eposit Money\n(W)ithdraw Money\n(C)heck Account Balance\n(Q)uit");
  111.             loop = loop.toUpperCase();
  112.             if (loop.equals("D"))
  113.                 functiondeposit();              //
  114.             else if (loop.equals("W"))
  115.                 functionwithdraw();             //
  116.             else if (loop.equals("C"))
  117.                 functioncheck();                    //
  118.             else if (loop.equals("Q"))
  119.                 quit();  //Exit the program.
  120.             else
  121.                 System.out.println("Input Error");     
  122.         }
  123.     }
  124.    
  125.    
  126.     public static void functiondeposit()
  127.     {
  128.         System.out.println("Function Deposit");
  129.         cust.deposit();
  130.     }
  131.    
  132.     public static void functionwithdraw()
  133.     {
  134.         System.out.println("Function Withdraw");
  135.         cust.withdraw();
  136.     }
  137.    
  138.     public static void functioncheck()
  139.     {
  140.         System.out.println("Function Check");
  141.         cust.checkBalance();
  142.     }
  143.     public static void quit()
  144.     {
  145.         System.out.println("Quit");
  146.         //REMOVE THIS ONCE OTHER FUNCTIONALITY TAKES OVER
  147.         System.exit(0);
  148.     }
  149.    
  150.     //Date and time.
  151.     private static String getDateTime()
  152.     {
  153.         Calendar cal = Calendar.getInstance();
  154.         SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
  155.         return sdf.format(cal.getTime());
  156.    }
  157.         public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm\n";
  158. }
  159.  
  160.  
  161.  
  162. abstract class Customer
  163. {
  164. /*
  165. CHECKLIST
  166. [x]data fields name pin balance
  167. [x]3 accessor methods (return) getName() returns <i>name</i>
  168. [x]1 constructor method, name pin balance
  169. [x]4 abstract (deposit ... ... exit)
  170. */
  171.     //Declare variables.
  172.     String name = "";
  173.     int pin = 0;
  174.     double balance = 0.0;
  175.     //Constructor
  176.     public Customer(String n, int p, double b)
  177.     {
  178.         name = n;
  179.         pin = p;
  180.         balance = b;
  181.     }
  182.    
  183.     public Customer()
  184.     {
  185.         name = "";
  186.         pin = 0;
  187.         balance = 0.0;
  188.     }
  189.    
  190.     //Accessors
  191.     public String getName()
  192.     {
  193.         return name;
  194.     }
  195.     public int getPin()
  196.     {
  197.         return pin;
  198.     }
  199.     public double getBalance()
  200.     {
  201.         return balance;
  202.     }
  203.    
  204.     //These don't do anything until they get inherited.  
  205.     //deposit(), withdraw(), checkBalance(), and quit().
  206.     abstract public void deposit();
  207.  
  208.     abstract public void withdraw();
  209.  
  210.     abstract public void checkBalance();
  211.  
  212.     abstract public void quit();
  213.  
  214. }
  215.  
  216. class CheckingAccountCustomer extends Customer
  217. {
  218. /*
  219. CHECKLIST
  220. [x]Data field?  accountNo
  221. [ ]return getAccountNo method
  222. [x]constructor name pin balance accountNo
  223. [ ]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.
  224. [ ]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.
  225. [ ]checkBalance: This method just prints the current balance as of the current date/time to the screen.
  226. [ ]quit: duh.  System.exit(0);
  227.     */
  228.     int accountNo = 0;
  229.    
  230.     //Constructor
  231.     public CheckingAccountCustomer(String n, int p, double b, int a)
  232.     {
  233.         super(n, p, b);
  234.         accountNo = a;
  235.     }
  236.    
  237.     public void deposit()
  238.     {
  239.         String input3 = JOptionPane.showInputDialog("How much are you depositing?  ");
  240.         double convert3 = Double.parseDouble(input3);
  241.         balance = balance + convert3;
  242.         System.out.println("As of " + CheckingAccountCustomer.getDateTime() + " your balance is " + balance);
  243.     }
  244.    
  245.     public void withdraw()
  246.     {
  247.         String input4 = JOptionPane.showInputDialog("How much are you withdrawing?  ");
  248.         double convert4 = Double.parseDouble(input4);
  249.         balance = balance - convert4;
  250.         System.out.println("As of " + CheckingAccountCustomer.getDateTime() + " your balance is " + balance);
  251.     }
  252.    
  253.     public void checkBalance()
  254.     {
  255.         System.out.println("As of " + CheckingAccountCustomer.getDateTime() + " your balance is " + balance);
  256.     }
  257.    
  258.     public void quit()
  259.     {
  260.         System.exit(0);
  261.     }
  262.    
  263.    
  264.    
  265.    
  266.         //Date and time.
  267.     private static String getDateTime()
  268.     {
  269.         Calendar cal = Calendar.getInstance();
  270.         SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
  271.         return sdf.format(cal.getTime());
  272.    }
  273.         public static final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm\n";
  274.    
  275. //Possible reference but probably all garbage
  276.     /*
  277.     boolean active = true;
  278.     public SavingsAccount(double balance, double interest_rate) //constructor
  279.     {
  280.         super.BankAccount(balance, interest_rate);
  281.     }
  282.     public void withdraw(double withdrawal)
  283.     {
  284.         if (active == false) //Check if active.  If not, its a no go.
  285.             System.out.println("The account is inactive, because the balance is below $25.");
  286.         else // If it is active, do the withdrawal through the superclass _
  287.               // and check if its below 25 to make it inactive
  288.             super.withdraw(withdrawal, num_wd);
  289.             if (balance < 25)
  290.                 active = false;
  291.         System.out.println("Your new balance is: " + balance);
  292.     }
  293.     *//*
  294.     public void deposit(double deposit)
  295.     {
  296.         if (active == false)
  297.             if (balance + deposit >= 25)
  298.                 active = true;
  299.         super.deposit(deposit, num_wd);
  300.         System.out.println("Your new balance is: " + balance);
  301.     }
  302.     *//*
  303.     public void monthlyProcess()
  304.     {
  305.         if (num_wd > 4)
  306.             service_charge = service_charge + num_wd - 4;
  307.         super.monthlyProcess(num_dep, num_wd);
  308.        
  309.         if (balance < 25)
  310.             active = false;
  311.         System.out.println("Your new balance is: " + balance);
  312.     }
  313.     */
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement