Answer:
public class BankAccounts
{
public String ownerName;
public String acctNbr;
private double debits;
private double credits;
public BankAccounts(String ownerNm, String acNum)
{
debits = 0;
credits = 0;
ownerName = ownerNm;
acctNbr = acNum;
}
public void addDebit(double debitAmt)
{
if(credits > (debits + debitAmt))
debits = debits + debitAmt;
else
System.out.println("Insufficient balance");
}
public void addCredit(double creditAmt)
{
credits = credits + creditAmt;
}
public double getBalance()
{
double balance = 0;
if((credits - debits) > 0) // return the value if there is actually some balance left.
balance = credits - debits;
return balance; //returns 0 if credits are lesser or equal to debits
}
}
Explanation:
Here class name is <em>BankAccounts </em>which can be used to create a new bank account whenever any user wants to open a bank account. This class will help to track any new account opening, debits and credits operations carried out on that account.
We have a constructor here, which accepts 2 arguments i.e. Bank account <em>Owner Name</em> and <em>Account Number</em>. The constructor also sets the values of <em>debits </em>and <em>credits</em> as 0.
The methods <em>addDebit()</em>, <em>addCredit()</em> and <em>getBalance()</em> help to perform Debit and Credit operations on the account.
NOTE: The method <em>getBalance()</em> returns a positive value only when credits are greater than debits.
The method <em>addDebits()</em> can add debits only as the condition that the credits are greater than the resultant debits.
The code for class <em>BankAccounts</em> is hereby attached.