Java没有显示我正在寻找的输出(初学者)

时间:2017-10-04 03:12:52

标签: java eclipse

大家好我是Java的新手,但我遇到了一个我似乎无法修复的问题,问题出在了洗衣机和洗衣机的问题上。分类它不显示' spinSpeed'详情,任何答案将不胜感激

这是我的代码:

enter code here

package test;

public class Client {
private String Name;
private String PhoneNo;

Client () {
    Name = null;
    PhoneNo= null;
}
Client (String N, String P){
    Name = N;
    PhoneNo = P;
}

public void setName(String N){
    Name = N;
}
public void setPhoneNo(String P) {
    PhoneNo = P;
}

public String getName(){
    return Name;
}
public String setPhoneNo() {
    return PhoneNo;
}

public String toString() {
    return "\nName: "+ Name + "\nPhoneNo:"+ PhoneNo.toString();
}

}

enter code here

包裹测试;

public class Machine {

private String Make;
private double Price;
private Client Cust;

public Machine(String make, double price, Client cust)
{
    Make = make;
    Price = price;
    Cust = cust;
}

@Override
public String toString() {
    return "\n" +"Make of machine: " + Make + "\n" + "Price: " + Price + "\n" + Cust.toString();
}

public String getMake() {
    return Make;
}

public double getprice() {
    return Price;
}

public Client getcust() {
    return Cust;
}

}

enter code here
package test;

public class WashingMachine extends Machine {
    private int spinSpeed;

    public WashingMachine (String make, double price, Client cust, int spinSpeed){
        super(make, price, cust);
        }

    @Override
    public String toString() {
        return "WashingMachine [spinSpeed=" + spinSpeed + ", spinSpeed()=" + spinSpeed()  + "]";
    }

    public int spinSpeed() {
        return spinSpeed;
    }



enter code here
package test;

    import java.util.ArrayList;

    public class MachinePurchaseTestVerC {
    public static void main(String [] args) {
    ArrayList<Machine> gadgets = new ArrayList<Machine> ();
    Client mCust2 = new Client("Paul", "0487654321");
    Client mCust3 = new Client("Chandra", "0487651234");
    Client wCust1 = new Client("Catherine", "0412345678");
    Client wCust4 = new Client("Mike", "0412348756");

    gadgets.add(new WashingMachine("Bosch", 549.50, wCust1, 3500));
    gadgets.add(new Machine("Samsung", 678.50, mCust2));
    gadgets.add(new Machine("Electrolux", 449.25, mCust3));
    gadgets.add(new WashingMachine("LG", 500.00, wCust4, 3200));

    for(int i = 0; i<gadgets.size(); i++){
        System.out.println(gadgets.get(i).toString());
        System.out.println("----------------------------------");
    }
}

}

1 个答案:

答案 0 :(得分:1)

在您的WashingMachine课程中,您忘记在构造函数中设置速度

public WashingMachine (String make, double price, Client cust, int spinSpeed){
    super(make, price, cust);
    this.spinSpeed = spinSpeed;
}

希望有所帮助:)