public class NiuRouMian {
private String theMark;
private int quantity;
private boolean haveSoup;
public NiuRouMian(String theMark, int quantity, boolean haveSoup) {
this.theMark = theMark;
this.quantity = quantity;
this.haveSoup = haveSoup;
}
public NiuRouMian(String theMark, int quantity) {
this.theMark = theMark;
this.quantity = quantity;
this.haveSoup = false;
}
public NiuRouMian() {
this.theMark = "酸辣";
this.quantity = 2;
this.haveSoup = true;
}
public void check() {
System.out.print("面码:" + this.theMark);
System.out.print("\t");
System.out.print("\t");
System.out.print("分量(两):" + this.quantity);
System.out.print("\t");
System.out.println("是否带汤:" + (this.haveSoup == true ? "是" : "否"));
}
public static void main(String[] args) {
NiuRouMian n1 = new NiuRouMian("土豆", 3, true);
NiuRouMian n2 = new NiuRouMian("土豆", 2);
NiuRouMian n3 = new NiuRouMian();
n1.check();
n2.check();
n3.check();
}
}
上面是我写的代码,下图是执行结果,麻烦看一下,是否能够满足要求。