java面向对象编程习题,急求答案,用MyEclipse编写 为“无名的粉”写一个类:class

java面向对象编程习题,急求答案,用MyEclipse编写为“无名的粉”写一个类:classWuMingFen要求:1.有三个属性:面码:StringtheMa粉的分量... java面向对象编程习题,急求答案,用MyEclipse编写

为“无名的粉”写一个类:class WuMingFen 要求:

1.有三个属性:面码:String theMa 粉的分量(两):int
quantity

是否带汤:boolean likeSoup

2.写一个构造方法,以便于简化初始化过程,如:

WuMingFen f1 = new WuMingFen("牛肉",3,true);

3.重载构造方法,使得初始化过程可以多样化:

WuMingFen f2 = new WuMingFen("牛肉",2);

4.如何使得下列语句构造出来的粉对象是酸辣面码、2两、带汤的?

WuMingFen f3 = new WuMingFen();

5.写一个普通方法:check(),用于查看粉是否符合要求。即:将对象的三个属性打印在控制台上。
展开
 我来答
yiliuking
2013-11-01 · TA获得超过195个赞
知道小有建树答主
回答量:183
采纳率:100%
帮助的人:95.2万
展开全部
public class WuMingFen {

private String theMa; //面码

private int quantity;//粉的分量(两)

private boolean likeSoup;//是否带汤

public WuMingFen(){
this.theMa = "酸辣";
this.quantity = 2;
this.likeSoup = true;
}

public WuMingFen(String theMa,int quantity){
this.theMa = theMa;
this.quantity = quantity;
}

public WuMingFen(String theMa,int quantity,boolean likeSoup){
this.theMa = theMa;
this.quantity = quantity;
this.likeSoup = likeSoup;
}

public void check(){
System.out.println("面码:"+this.theMa);
System.out.println("粉的分量(两):"+this.quantity);
System.out.println("是否带汤:"+this.likeSoup);
}

//验证
public static void main(String[] args){
WuMingFen f1 = new WuMingFen("牛肉",3,true);
WuMingFen f2 = new WuMingFen("牛肉",2);
WuMingFen f3 = new WuMingFen();
f1.check();
f2.check();
f3.check();
}

}
miniappdco63zldswgge
2013-11-01
知道答主
回答量:67
采纳率:0%
帮助的人:17.2万
展开全部
public class WuMingFen {

private String theMa ;
private int quantity ;
private boolean likeSoup ;

public static void main(String[] args) {
WuMingFen f3 = new WuMingFen();
f3.setLikeSoup(true);
f3.setTheMa("酸辣面");
f3.setQuantity(2);
check(f3);

}

private static void check(WuMingFen fen){

System.out.println("这是:"+fen.getTheMa());
System.out.println("重量:"+fen.getQuantity());
if(fen.isLikeSoup()){
System.out.println("带汤");
}else{
System.out.println("不带");
}

}
public WuMingFen(String theMa, int quantity) {
this.theMa = theMa;
this.quantity = quantity;
}
public WuMingFen() {

}
public WuMingFen(String theMa, int quantity, boolean likeSoup) {
super();
this.theMa = theMa;
this.quantity = quantity;
this.likeSoup = likeSoup;
}
public String getTheMa() {
return theMa;
}

public void setTheMa(String theMa) {
this.theMa = theMa;
}

public int getQuantity() {
return quantity;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}

public boolean isLikeSoup() {
return likeSoup;
}

public void setLikeSoup(boolean likeSoup) {
this.likeSoup = likeSoup;
}
@Override
public String toString() {
return "WuMingFen [theMa=" + theMa + ", quantity=" + quantity
+ ", likeSoup=" + likeSoup + "]";
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式