Пример #1
0
 /**
  * Tests the methods of the BankAccount class.
  *
  * @param args not used
  */
 public static void main(String[] args) {
   Address address = new Address("100 Main St", "", "Binghamton", "NY 13905", "USA");
   BankAccount harrysChecking = new BankAccount("Jane Doe", address, 10001);
   harrysChecking.deposit(2000);
   harrysChecking.withdraw(500);
   System.out.println(harrysChecking.getBalance());
   System.out.println("Expected: 1500");
 }
Пример #2
0
 /**
  * @param client
  * @param amount
  */
 @Override
 public void withdraw(Client client, float amount) throws UnsupportedOperationException {
   super.authorize(client);
   if (this.getBalance(client) > amount) {
     super.withdraw(client, amount);
   } else {
     throw new UnsupportedOperationException("insufficient balance");
   }
 }
Пример #3
0
 @Test
 public void testBankAccounts() throws HTTPError {
   Customer customer = createPersonCustomer();
   BankAccount ba = createBankAccount();
   assertNotNull(ba);
   assertNotNull(ba.href);
   ba.associateToCustomer(customer);
   assertEquals(ba.href, customer.bank_accounts.iterator().next().href);
 }
Пример #4
0
  public static void main(String[] args) {
    BankAccount banco = new BankAccount();
    DepositThread deposito = new DepositThread(banco, 100);
    WithdrawThread saque = new WithdrawThread(banco, 100);

    deposito.start();
    saque.start();

    System.out.println("Saldo final: " + banco.getBalance());
  }
Пример #5
0
 @Programmatic
 public BankAccount newBankAccount(
     final @ParameterLayout(named = "Owner") Party owner,
     final @ParameterLayout(named = "Reference") @Parameter(
             regexPattern = RegexValidation.REFERENCE) String reference,
     final @ParameterLayout(named = "Name") String name) {
   final BankAccount bankAccount = newTransientInstance(BankAccount.class);
   bankAccount.setReference(reference);
   bankAccount.setName(name);
   persistIfNotAlready(bankAccount);
   bankAccount.setOwner(owner);
   return bankAccount;
 }
Пример #6
0
 /**
  * Debits the inhabitant's bank account with amount
  *
  * @param amount
  */
 public void debit(int amount) {
   bankAccount.debit(amount);
   Displayer.getDisplayer()
       .display(
           " -"
               + amount
               + " euro"
               + ((amount > 1) ? "s are" : " is")
               + " debited from "
               + name
               + " whose "
               + bankAccount.balanceToString()
               + "\n");
 }
Пример #7
0
 /**
  * Credits the inhabitant's bank account with amount
  *
  * @param amount
  */
 public void credit(int amount) {
   bankAccount.credit(amount);
   Displayer.getDisplayer()
       .display(
           " +"
               + name
               + " account is credited with "
               + amount
               + " euro"
               + ((amount > 1) ? "s" : "")
               + ", its "
               + bankAccount.balanceToString()
               + "\n");
 }
Пример #8
0
  @Test
  public void defaultBankAccountNumber() {

    String accountNumber = fake.getAccountNumber();

    assertThat(accountNumber, is(""));
  }
 //  to demonstrate the "overdrawn" error remove the "synchronized" modifier
 private synchronized void makeWithdrawal(int amount) {
   if (account.getBalance() >= amount) {
     System.out.println(Thread.currentThread().getName() + " is about to withdrawal");
     try {
       System.out.println(Thread.currentThread().getName() + " is going to sleep");
       Thread.sleep(500);
     } catch (InterruptedException ex) {
       ex.printStackTrace();
     }
     System.out.println(Thread.currentThread().getName() + " woke up");
     account.withdraw(amount);
     System.out.println(Thread.currentThread().getName() + " completes the withdrawal");
   } else {
     System.out.println("Sorry, not enough for " + Thread.currentThread().getName());
   }
 }
Пример #10
0
 public void withdraw(double amount) {
   super.withdraw(amount);
   double balance = getBalance();
   if (balance < minBalance) {
     minBalance = balance;
   }
 }
Пример #11
0
 public static void main(String[] args) {
   BankAccount bank = new BankAccount();
   Scanner scan = new Scanner(System.in);
   System.out.println("Type in your name.");
   bank.name = scan.nextLine();
   System.out.println("Type in your email address.");
   bank.email = scan.nextLine();
   System.out.println("Type in a pin number.");
   bank.pin = scan.nextInt();
   UUID id = UUID.randomUUID();
   bank.account = id.toString();
   try {
     shipObject(bank);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
 public void run() {
   for (int x = 0; x < 10; x++) {
     makeWithdrawal(10);
     if (account.getBalance() < 0) {
       System.out.println("Overdrawn!");
     }
   }
 }
  public static void testDriver(int length) {
    BankAccount b = new BankAccount(0);
    for (int i = 0; i < length; i++) {
      Verify.beginAtomic();

      // switch (Verify.random(1)){
      switch (flag(true)) {
        case 0:
          b.deposit(10);
          break;
        case 1:
          b.withdraw(1);
          break;
      }
      Verify.endAtomic();
    }
  }
Пример #14
0
 public static void shipObject(BankAccount account) throws IOException {
   account.creatAccount();
   String fileExtension = "/" + account.name + ".ser";
   FileOutputStream output = new FileOutputStream(fileExtension);
   ObjectOutputStream objOutput = new ObjectOutputStream(output);
   objOutput.writeObject(account);
   objOutput.flush();
   objOutput.close();
   System.out.println("The object is in: " + account.name + ".ser");
 }
  /** Test method for {@link edu.cecs274.BankCustomer#getTotalBalance()}. */
  @Test
  public void testGetTotalBalance() {
    BankAccount oneAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER, INITIAL_BALANCE);
    BankAccount twoAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER + 1);
    BankAccount threeAccount = new BankAccount(aCustomer, INITIAL_ACCOUNT_NUMBER + 2);
    aCustomer.addAccount(oneAccount);
    aCustomer.addAccount(twoAccount);
    aCustomer.addAccount(threeAccount);

    double expected = INITIAL_BALANCE;
    double totalBalance = aCustomer.getTotalBalance();
    assertEquals(expected, totalBalance, DELTA);

    // Adds more money to twoAccount, the change should be reflected in aCustomers totalBalance
    twoAccount.deposit(INITIAL_BALANCE);
    expected = INITIAL_BALANCE * 2;
    totalBalance = aCustomer.getTotalBalance();
    assertEquals(expected, totalBalance, DELTA);
  }
  @Test
  public void testPropertyRefToJoinedSubclass() {
    Session session = openSession();
    Transaction tx = session.beginTransaction();
    Person p = new Person();
    p.setName("Gavin King");
    BankAccount acc = new BankAccount();
    acc.setBsb("0634");
    acc.setType('B');
    acc.setAccountNumber("xxx-123-abc");
    p.setBankAccount(acc);
    session.persist(p);
    tx.commit();
    session.close();

    session = openSession();
    tx = session.beginTransaction();
    p = (Person) session.get(Person.class, p.getId());
    assertNotNull(p.getBankAccount());
    assertTrue(Hibernate.isInitialized(p.getBankAccount()));
    tx.commit();
    session.close();

    session = openSession();
    tx = session.beginTransaction();
    p =
        (Person)
            session
                .createCriteria(Person.class)
                .setFetchMode("bankAccount", FetchMode.JOIN)
                .uniqueResult();
    assertNotNull(p.getBankAccount());
    assertTrue(Hibernate.isInitialized(p.getBankAccount()));
    tx.commit();
    session.close();

    session = openSession();
    tx = session.beginTransaction();
    session.delete(p);
    tx.commit();
    session.close();
  }
Пример #17
0
  public static void main(String[] args) {
    BankAccount ba1 = new ChequeAccount("Jack Black", "Hockey");
    ChequeAccount ca1 = new ChequeAccount("Chris Weidman", "Bunnies");
    ChequeAccount ca2 = new ChequeAccount("Ross Geller", "Dinosaurs");

    ba1.deposit(100);
    ((ChequeAccount) ba1).writeCheque(23);

    SavingsAccount sa1 = new SavingsAccount("David Letterman");
    SavingsAccount sa2 = new SavingsAccount("Jimmy Fallon");
    sa1.deposit(25);
    System.out.println("" + ba1 + ca1 + ca2 + sa1 + sa2);

    BalancePrinter bp = new BalancePrinter();
    bp.reportPrinter(ba1);
    bp.reportPrinter(ca1);
    bp.reportPrinter(ca2);
    bp.reportPrinter(sa1);
    bp.reportPrinter(sa2);
  } // main
Пример #18
0
  @Override
  public int compareTo(Object o) {
    BankAccount a = this;
    BankAccount b = (BankAccount) o;

    if (a.getBalance() < b.getBalance()) return +1;
    else if (a.getBalance() > b.getBalance()) return -1;
    else return 0;
  }
Пример #19
0
  public void run() {
    synchronized (receiver) {
      synchronized (giver) {
        int stopCondition = 0;
        Log.i("bank", name + " is $" + receiver.getBalance() + ".");
        // Take money
        while (stopCondition < maxWithdraw) {
          // Withdraw
          int withdrawNum = giver.withdraw(ammountPerWithdraw);
          // Deposite
          receiver.deposite(withdrawNum);
          // Stop counter
          stopCondition += withdrawNum;

          // Sleep for a bit
          try {
            Thread.sleep(sleepDelay);
          } catch (InterruptedException e) {
          }

          // Display GUI changes
          activity
              .getHandler()
              .post(
                  new Runnable() {
                    public void run() {
                      activity.getField1().setText("" + giver.getBalance());
                      activity.getField2().setText("" + receiver.getBalance());
                    }
                  });
        }

        Log.i("bank", name + "has stopped receiving.");
      }
    }
  }
Пример #20
0
 @Action(semantics = SemanticsOf.NON_IDEMPOTENT)
 @ActionLayout(contributed = Contributed.AS_NEITHER)
 public BankAccount newBankAccount(
     final @ParameterLayout(named = "Owner") Party owner,
     final @ParameterLayout(named = "IBAN", typicalLength = JdoColumnLength.BankAccount.IBAN)
         String iban) {
   final BankAccount bankAccount = newTransientInstance(BankAccount.class);
   bankAccount.setReference(iban);
   bankAccount.setName(iban);
   bankAccount.setIban(iban);
   bankAccount.refresh();
   persistIfNotAlready(bankAccount);
   bankAccount.setOwner(owner);
   return bankAccount;
 }
Пример #21
0
 public void transfer(BankAccount account, double amount) {
   if (amount > 0 && account != null) {
     account.balance -= amount;
     if (numberOfOperations > 4) {
       for (int i = 0; i < history.length - 1; i++) {
         history[i] = history[i + 1];
       }
       history[5] = "Withdraw amount: " + amount;
     } else {
       for (int i = 0; i < history.length - 1; i++) {
         if (history[i] == null) {
           history[i] = "Withdraw amount: " + amount;
           break;
         }
       }
     }
     numberOfOperations++;
   } else {
     throw new IllegalArgumentException("sowy");
   }
 }
Пример #22
0
  @Test
  public void initiliazationOfTheIdOfAFakeBankAccount() {

    assertThat(fake.getId(), is(equalTo(Long.MIN_VALUE)));
  }
Пример #23
0
  @Test
  public void overridesToString() {

    assertThat(fake.toString(), is("FakeBankAccount"));
  }
Пример #24
0
 /**
  * @param client
  * @return
  */
 public BasicAccountType getType(Client client) throws UnsupportedOperationException {
   super.authorize(client);
   return this.type;
 }
Пример #25
0
 public void takeMoneyFrom(BankAccount other, double amt) {
   if (other.balance >= amt) {
     other.withdraw(amt);
     this.deposit(amt);
   }
 }
Пример #26
0
 public void giveMoneyTo(BankAccount other, double amt) {
   if (balance >= amt) {
     balance = balance - amt;
     other.balance = other.balance + amt;
   }
 }
  public static void main(String[] args) {

    ArrayList<BankAccount> bankAccounts = new ArrayList<>();
    ArrayList<BankAccount> closedBankAccounts = new ArrayList<>();

    boolean done = false;

    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    Date date = new Date();

    while (!done) {
      int menu =
          GetData.getInt(
              "\tUnited Bank of Java\n"
                  + "\nPlease Choose From the Following"
                  + "\n1. Create New Account"
                  + "\n2. Update Existing Account"
                  + "\n3. Close an Account"
                  + "\n4. View Account Information"
                  + "\n5. Exit");

      switch (menu) {
        case 1: // Create bank account obj and store in database
          String first = JOptionPane.showInputDialog(null, "What is your first name?");
          String last = JOptionPane.showInputDialog(null, "What is your last name?");
          Name customerName = new Name(first, last);
          JOptionPane.showMessageDialog(null, "Customer name is " + customerName.getName());
          String street = JOptionPane.showInputDialog(null, "What's your street address?");
          String city = JOptionPane.showInputDialog(null, "What city do you live in?");
          String state = JOptionPane.showInputDialog(null, "What state do you live in?");
          String zip = JOptionPane.showInputDialog(null, "What is your ZIP code?");
          Address customerAddress = new Address(street, city, state, zip);
          JOptionPane.showMessageDialog(
              null, "Customer's address is: \n" + customerAddress.getAddress());
          String accountNum =
              JOptionPane.showInputDialog(null, "What do you want your account number to be?");
          Customer c = new Customer(customerName, customerAddress, accountNum);
          JOptionPane.showMessageDialog(
              null,
              "Welcome!\nHere's your info.\nName: "
                  + c.getName()
                  + "\nAddress: "
                  + c.getAddress()
                  + "\nAccount #: "
                  + c.getAccountNum());
          String balance = JOptionPane.showInputDialog(null, "What will be your initial balance?");
          double bal = Double.parseDouble(balance);
          BankAccount bankacc = new BankAccount(c, bal);
          JOptionPane.showMessageDialog(null, "Your balance is: \n" + bankacc.getBalance());
          bankAccounts.add(bankacc);
          System.out.print(bankAccounts.indexOf(bankacc) + " " + bankAccounts.size());

          break;

        case 2: // Update Account
          int money =
              GetData.getInt(
                  "What would you like to do?"
                      + "\n1. Make a deposit."
                      + "\n2. Make a withdrawal."
                      + "\n");

          switch (money) {
            case 1: // Make a deposit
              String accNum = JOptionPane.showInputDialog(null, "What is your account number?");
              if (BankAccount.findAccNum(bankAccounts, accNum)) {
                JOptionPane.showMessageDialog(null, "Account found!");
                int i = BankAccount.findIndex(bankAccounts, accNum);
                JOptionPane.showMessageDialog(
                    null, "Account balance is currently: $" + bankAccounts.get(i).getBalance());
                String x = JOptionPane.showInputDialog(null, "How much would you like to deposit?");
                double y = Double.parseDouble(x);
                bankAccounts.get(i).deposit(y);
                JOptionPane.showMessageDialog(
                    null, "Your new balance is: $" + bankAccounts.get(i).getBalance());
              } else {
                JOptionPane.showMessageDialog(null, "Account not in database.");
              }
              break;

            case 2: // Make a withdrawal
              String accNum1 = JOptionPane.showInputDialog(null, "What is your account number?");
              if (BankAccount.findAccNum(bankAccounts, accNum1)) {
                JOptionPane.showMessageDialog(null, "Account found!");
                int i = BankAccount.findIndex(bankAccounts, accNum1);
                JOptionPane.showMessageDialog(
                    null, "Account balance is currently: $" + bankAccounts.get(i).getBalance());
                String x =
                    JOptionPane.showInputDialog(null, "How much would you like to withdraw?");
                double y = Double.parseDouble(x);

                if (y < bankAccounts.get(i).getBalance()) {
                  bankAccounts.get(i).withdraw(y);
                  JOptionPane.showMessageDialog(
                      null, "Your new balance is: $" + bankAccounts.get(i).getBalance());
                } else {
                  JOptionPane.showMessageDialog(null, "Insufficient funds.");
                }
              } else {
                JOptionPane.showMessageDialog(null, "Account not in database.");
              }
              break;

            default:
              JOptionPane.showMessageDialog(null, "Invalid option.");
              break;
          }

          break;

        case 3: // close account
          String accNum = JOptionPane.showInputDialog(null, "What is the account number?");
          if (BankAccount.findAccNum(bankAccounts, accNum)) {
            JOptionPane.showMessageDialog(null, "Account found!");
            int i = BankAccount.findIndex(bankAccounts, accNum);
            BankAccount clone = bankAccounts.get(i);
            bankAccounts.get(i).deactivate();
            JOptionPane.showMessageDialog(
                null, "Account is located in the ArrayList at index: " + i);
            closedBankAccounts.add(clone);
            bankAccounts.remove(i);
          } else {
            JOptionPane.showMessageDialog(null, "Account not found!");
          }

          break;

        case 4: // view account info
          int view =
              GetData.getInt(
                  "What information would you like to view?"
                      + "\n1. Single Account"
                      + "\n2. All active accounts"
                      + "\n3. All inactive accounts"
                      + "\n");

          switch (view) {
            case 1: // view single account
              String accNum2 =
                  JOptionPane.showInputDialog(
                      null, "Please enter account number to view information on it.");

              if (BankAccount.findAccNum(bankAccounts, accNum2)) {
                JOptionPane.showMessageDialog(null, "Account found!");

                int i = BankAccount.findIndex(bankAccounts, accNum2);
                JOptionPane.showMessageDialog(
                    null,
                    "Name: "
                        + bankAccounts.get(i).getName()
                        + "\nAccount Number: "
                        + bankAccounts.get(i).getAccountNum()
                        + "\nBalance: $"
                        + bankAccounts.get(i).getBalance());
              } else {
                JOptionPane.showMessageDialog(null, "Account not in database.");
              }

              break;

            case 2: // view all account

              /*JTextArea textArea = new JTextArea("Date: " + dateFormat.format(date) +
                          BankAccount.printAllCustomers(bankAccounts));
                  JScrollPane scrollPane = new JScrollPane(textArea);
                  textArea.setLineWrap(true);
                  textArea.setWrapStyleWord(true);
                  scrollPane.setPreferredSize( new Dimension( 300, 400 ) );
                  JOptionPane.showMessageDialog(null, scrollPane, "Current Customers",
                         JOptionPane.YES_NO_OPTION);

              */
              break;

            case 3: // view all closed accounts
              break;

            default:
              JOptionPane.showMessageDialog(null, "Invalid Option.");
              break;
          } // end view
          break;

        case 5: // exit
          done = true;
          break;

        default:
          JOptionPane.showMessageDialog(null, "Account not found.");
          break;
      }
    }
  }
 public static void main(String[] args) {
   BankAccount myMoney = new BankAccount(1000);
   myMoney.addInterest(10);
   System.out.println("Expected: 1100 Actual: " + myMoney.getBalance());
 }
Пример #29
0
 /**
  * Transfers money from the bank account to another account
  *
  * @param amount the amount to transfer
  * @param other the other account
  * @throws InsufficientFundsException if the account cannot cover the withdrawal of this amount
  */
 public void transfer(double amount, BankAccount other) throws InsufficientFundsException {
   withdraw(amount);
   other.deposit(amount);
 }
Пример #30
0
 /**
  * Transfers money from the bank account to another account
  *
  * @param other the other account
  * @param amount the amount to transfer
  */
 public void transfer(BankAccount other, double amount) {
   withdraw(amount);
   other.deposit(amount);
 }