Note that there are some explanatory texts on larger screens.

plurals
  1. POMethod Retrieval and Inheritance Confusion
    text
    copied!<p>Ok,so I am getting a lot of trouble, I am still learning Java and my book has set me a task that I find common over the net, the part that I am stuck on is...</p> <p>I must create a bank account program, an account holder is given a savings account (which has an interest rate and no overdraft facility), and a checking account (which has an overfraft facility of £100 and no interest). </p> <p>I am not implementing the overdraft yet and am only half way to getting the withdraw and deposit function ready but my question is with the interest, I have defined in my superclass the savings account balance and the checking account balance so when working out my interest in the savings account class I cannot reference savebalance as I have made it private. I am trying to use the set.name method but i am clearly doing it wrong....</p> <p>A big smile and a thank you for any one who can help or give advice!</p> <p>Superclass is as follows:</p> <pre><code>public class BankDetails { private String customer; private String accountno; private double savebalance; private double checkbalance; //Constructor Methods public BankDetails(String customerIn, String accountnoIn, double savebalanceIn, double checkbalanceIn) { customer = customerIn; accountno = accountnoIn; savebalance = savebalanceIn; checkbalance = checkbalanceIn; } // Get name public String getcustomername() { return (customer); } // Get account number public String getaccountnumber() { return (accountno); } public double getcheckbalanceamount() { return (checkbalance); } public double getsavebalanceamount() { return (savebalance); } public void savewithdraw(double savewithdrawAmountIn) { savebalance = savebalance - savewithdrawAmountIn; } public void checkwithdraw(double checkwithdrawAmountIn) { checkbalance = checkbalance - checkwithdrawAmountIn; } public void savedeposit(double savedepositAmountIn) { savebalance = savebalance - savedepositAmountIn; } public void checkdeposit(double checkdepositAmountIn) { checkbalance = checkbalance - checkdepositAmountIn; } } // End Class BankDetails </code></pre> <p><strong>Sub Class is as follows:</strong></p> <pre><code> import java.util.*; public class Savings extends BankDetails { private String saveaccount; private double interest; public Savings(String customerIn, String accountnoIn, float interestIn, String saveaccountIn, double savebalanceIn) { super (customerIn, accountnoIn, savebalanceIn, interestIn); saveaccount = saveaccountIn; interest = interestIn; } public String getsaveaccountno() { return (saveaccount); } public double getinterestamount() { return (interest); } public void interestamount(String[] args) { BankDetails.getsavebalanceamount(savebalance); interest = (savebalance / 100) * 1.75; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload