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(),用于查看粉是否符合要求。即:将对象的三个属性打印在控制台上。 展开
为“无名的粉”写一个类: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(),用于查看粉是否符合要求。即:将对象的三个属性打印在控制台上。 展开
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();
}
}
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();
}
}
展开全部
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 + "]";
}
}
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 + "]";
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询