private int balance;
private String accountName;
public int getBalance() {
return balance;
}
public String getAccountName() {
return accountName;
}
/**
* Construct a bank account with given initial balance and account name
* @param accName unique identifying string
* @param accBalance opening balance of account, assumed non-negative
*/
public BankAccount(String accName, int accBalance) {
//TODO add code to initialise fields here
}
/**
* Deposit amount by adding to balance
* @param amount must be non-negative
*/
public void deposit (int amount) {
//TODO add your code here
}
/**
* Withdraw amount by decreasing balance
* @param amount must be non-negative
*/
public void withdraw (int amount) {
//TODO add your code here
}
/**
* Is the account overdrawn with a negative balance ?
* @return boolean true if the acccount balance is strictly less than 0 and false otherwise
*/
public boolean isOverdrawn() {
//TODO add your code here
}
You can either submit now (for a pass grade) or go on to add some more advanced functionality to the BankAccount for a credit or distinction grade.
private int valueDeposits;
private int valueWithdrawals;
private int maximumBalance;
private int minimumBalance;
public int getValueDeposits() {
return valueDeposits;
}
public int getValueWithdrawals() {
return valueWithdrawals;
}
public int getMinimumBalance() {
return minimumBalance;
}
public int getMaximumBalance() {
return maximumBalance;
}
Run the BankAccountStandardTest. You will notice that some tests fail. Check the test cases to see what additional functionality is needed. You do not need to add any new methods for this part of the contract. But you do need to add more code to existing methods.
/**
* Calculate and update interest
* Interest should be credited if balance is positive and
* debited if the balance is negative
* @param rate must be double greater than 0
*/
public void applyInterest(double rate) {
//TODO add your code here
}
In this case, when you compile your code after adding the code for applying the interest to the balance, you may notice that the BlueJ will give you the error message at the bottom of the BlueJ window as "possibe loss of precision found: double required : int". This is because the parameter rate was given the type of double in the signature of the method applyInterest. However, the type of balance was int (you can see this at the beginning of the class). To make the task simple, you may need to use the cast operator. The cast operator is used to convert numeric values from one numeric type to another.In order to convert type double to integer. You can use the following code:
balance = (int)(balance * rate) + balance;
to casting the value with type of double to int.
Submit (only) a single file BankAccount.java to cssubmit by the due date (see the CITS1200 Laboratory work web page). You can submit as many times as you wish. Minimal validation checks will be run when you submit but you are responsible for ensuring that your program passes all the JUnit test cases for the grade you have chosen.
You can obtain feedback on your work at any time by asking a lab demonstrator, asking a lecturer, or using the feedback tools in the laboratory and help1200.