English 中文(简体)
3. 回归和融合方法
原标题:Method Retrieval and Inheritance Confusion

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...

我必须设立一个银行账户方案,向一个账户持有人(有利率,没有透支设施)和一个支票账户(有100英镑的超额贷款和无利息)。

我没有执行透支草案,只是完成撤销和交存职能的一半办法,但我的问题符合我的利益,在我的上下流中,我确定了储蓄账户余额和支票账户余额,这样,我才能对储蓄账户类别表示兴趣,而我却不能提及储蓄平衡,因为我已将其私人化。 我试图利用这套装置。 姓名方法,但显然是错误的......。

任何人都可以帮助或提供建议,都会受到大笑和感谢。

监督员如下:

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

www.un.org/Depts/DGACM/index_spanish.htm 班级如下:

    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;


       }


       }
最佳回答

利用超级舱位代码getSaveBalance()方法获得平衡(这是可疑的,因为你有一个储蓄账户类别,但在其他地方保持平衡)。

(当然是getsavebalanceamount(),我改称与 Java公约保持一致。”


d 我建议使用CamelCase在命名您的接收器和设计器时使用一致的编号,例如getInterestAmount(),getSaveAccountNo()。

我建议不要评论简单的收听器/打字机,但如果是的话,则采用 Java教公约,例如:

/** Returns current savings account balance. */
public double getSaveBalance() { ... etc ... }

I also recommend avoid unnecessary parentheses, as currently in your getters, e.g.:

public double getSaveBalance() {
    return saveBalance; // No parens required.
}
问题回答

我建议你这样做。

interface Account{
  int getAccountNumber();
  float getBalance();
}

public class SavingAccount implements Account, Interest{
  int accountNumber;
  public int getAccountNumber(){
    return accountNumber;
  }
  float balance;
  public float getBalance(){
    return balance;
  }
  float savingInterestRate;
  public float getInterestRate(){
     return savingInterestRate;
  }
}

public class CheckingAccount implements Account, OverDraft{
  int accountNumber;
  public int getAccountNumber(){
  return accountNumber;
  }
  float balance;
  public float getBalance(){
    return balance;
  }
}

interface Interest{
  float getInterestRate();
}

interface OverDraft{
....
}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签