# Project II: Bank Account

Your team will create an `Account` class, which models a bank account.&#x20;

The Account class allows deposits and withdrawals. Instead of warning about a balance that's too low, however, it merely disallows a withdrawal request for more money than the account contains.

The following table contains a sample code execution sequence and the corresponding results:

<table><thead><tr><th>Statement of Expression</th><th width="152.66666666666669">Value returned(blank if no value returned)</th><th>Comment</th></tr></thead><tbody><tr><td>Account a1 = new Account(100);</td><td></td><td>Create a new account with initial balance as ¥100.</td></tr><tr><td>a1.deposit(50);</td><td></td><td>Add ¥50 to the account a1.</td></tr><tr><td>a1.getBalance();</td><td>150</td><td>Return the number of money in the account a1, which is 150.</td></tr><tr><td>a1.deposit(150);</td><td></td><td>Add ¥150 to the account a1.</td></tr><tr><td>a1.getBalance();</td><td>300</td><td>Return the number of money in the account a1, which is ¥300.</td></tr><tr><td>a1.withdraw(50);</td><td>true</td><td>Since a1 contains more money than the amount of withdrawal, the withdrawal succeeds. </td></tr><tr><td>a1.getBalance();</td><td>250</td><td>Return the number of money in the a1, which is ¥250.</td></tr><tr><td>a1.withdraw(300);</td><td>false</td><td>Since a1 contains less money than the amount of withdrawal, the withdrawal fails.</td></tr><tr><td>a1.getBalance();</td><td>250</td><td>Return the number of money in the a1, which is still ¥250.</td></tr><tr><td>Account a2 = new Account(500);</td><td></td><td>Create a new account a2with initial balance as ¥500.</td></tr><tr><td>a1.getBalance();</td><td>250</td><td>Return the number of money in the a1, which is still ¥250.</td></tr></tbody></table>

Besides, Account class also has a variable called **`noAccount`** to keep record of how many accounts haven been opened so far. So if there are two accounts created, then noAccount should be 2:

```
System.out.println(Account.noAccount); //will print 2
```

### Bonus Point: transferTo()

**The account can also transfer money to another account, as long as it contains enough money.** You can implement a method called `transferTo()`, which return true if the tranfer succeeds, otherwise return false.&#x20;

The following table contains the sample execution **following the previous table**:&#x20;

| Statement of Expression | Value returned(blank if no value returned) | Comment                                                                               |
| ----------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------- |
| a1.transferTo(a2, 100)  | true                                       | a1 transfer ¥100 to a2, which succeeds since a1 contains enough money.                |
| a1.getBalance();        | 150                                        | Return the number of money in the a1, which is ¥150.                                  |
| a2.getBalance();        | 600                                        | Return the number of money in the a2, which is ¥600.                                  |
| a2.transferTo(a1, 800)  | false                                      | a2 intends to transfer ¥800 to a1, which fails since a2 doesn't contain enough money. |
| a1.getBalance();        | 150                                        | Return the number of money in the a1, which is ¥50.                                   |
| a2.getBalance();        | 600                                        | Return the number of money in the a2, which is ¥600.                                  |

### Your task

Write the complete Account class, including the constructor and any required instance variables and methods. Your implementation must meet all specifications and conform to the example.&#x20;

Your code should also include a main() method to test all methods in Account class. I recommend you put your main() method in another class other than Account.&#x20;

In your code, you should follow "data encapsulation" standard: Keep All Instance Variables Private. Violate this standard would cause you lose points.

{% hint style="info" %}
Friendly Note: System.out.println() is for testing the method in Account class, so it should only be in your testing class, more specifically, your main() method.
{% endhint %}
