添加一个成员然后让该成员添加其他内容

时间:2014-04-17 22:20:16

标签: java

我的问题是我正在添加一个正常工作的成员,但我如何让该成员添加其他内容,例如

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());

1 个答案:

答案 0 :(得分:0)

无论

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

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

我认为您的问题与参数的名称相同。可以使用this.raffles作为该字段。