2014-04-17 88 views
-2

我的問題是我加入其工作正常一員,但我如何得到該成員添加別的東西,如添加然後成員有成員加入別人的財產以後

members.add(member); 
member.addCompetiton(raffles); 
StdOut.println(member.toString()); 

when i return my toString it is blank. 

toString==>> 
[bmi=4.0, height=4.0, raffles=[], name=e, address=e, dob=e, mempaid=4.0] 

這裏是類我試圖將它添加到底層,這是我嘗試去做的方法。

import java.util.ArrayList; 

public class ElitePlayer extends Member { 
    protected double bmi; 
    protected double height; 
    private ArrayList<Competition> raffles; 

    public ElitePlayer(String name, String address, String dob, double mempaid, 
      double bmi, double height) { 
     super(name, address, dob, mempaid); 
     this.bmi = bmi; 
     this.height = height; 
     raffles = new ArrayList<Competition>(); 
    } 

    public double getBmi() { 
     return bmi; 
    } 

    public void setBmi(double bmi) { 
     this.bmi = bmi; 
    } 

    public double getHeight() { 
     return height; 
    } 

    public void setHeight(double height) { 
     this.height = height; 
    } 

    public double getMempaid() { 

     if (this.mempaid > 10) 
      this.mempaid = 10; 
     return mempaid; 
    } 

    double calculateMembershipFeeOwed() { 
     double owed = 10; 
     return owed; 
    } 
    void addCompetiton(Competition raffles){ 

    } 

    void removeCompetiton(Competition raffles){ 
    } 

    @Override 
    public String toString() { 
     return "ElitePlayer [bmi=" + bmi + ", height=" + height + ", raffles=" 
       + raffles + ", name=" + name + ", address=" + address 
       + ", dob=" + dob + ", mempaid=" + mempaid + "]"; 
    } 


    } 



public void addElitePlayer(Member mem) { 
    StdOut.println("Please enter the Elite members's name: "); 
    System.out 
      .println("-------------------------------------------------------------------------------------------"); 
    StdIn.readLine(); 
    String name = StdIn.readLine(); 
    StdOut.println("Please enter the Elite members's address: "); 
    System.out 
      .println("-------------------------------------------------------------------------------------------"); 
    String address = StdIn.readLine(); 
    StdOut.println("Please enter the Elite members's DOB: "); 
    System.out 
      .println("-------------------------------------------------------------------------------------------"); 
    String dob = StdIn.readLine(); 
    StdOut.println("Please enter the the amount to Pay: "); 
    System.out 
      .println("-------------------------------------------------------------------------------------------"); 
    double mempaid = StdIn.readDouble(); 
    StdOut.println("Please enter the Elite members's BMI: "); 
    System.out 
      .println("-------------------------------------------------------------------------------------------"); 
    double bmi = StdIn.readDouble(); 
    StdOut.println("Please enter the Elite members's height: "); 
    System.out 
      .println("-------------------------------------------------------------------------------------------"); 
    double height = StdIn.readDouble(); 
    ElitePlayer member = new ElitePlayer(name, address, dob, mempaid, bmi, 
      height); 
    if (mempaid > 10) { 
     StdOut.print("You have overpaid, your change is "); 
     StdOut.println(mempaid -= 10); 
     System.out 
       .println("-------------------------------------------------------------------------------------------"); 
    } 
// Competition raffles = new Competition(); 

    members.add(member); 
    member.addCompetiton(raffles); 
    StdOut.println(member.toString()); 
+0

向我們展示您的會員類的來源。 – hexafraction

+1

這個問題沒有意義,請澄清。 –

回答

0

要麼

void addCompetiton(Competition raffles){ 
    this.raffles = raffles; 
} 

void addCompetiton(Competition competition){ 
    raffles = competition; 
} 

據我瞭解,你的問題是具有針對參數作爲字段的名稱相同。可以使用this.raffles作爲該字段。

+0

感謝Joop Eggen那種工作。 – user3136938