java 面向对象编程练习题,急求答案~ 用MyEclipse编写 练习题】10.构造方法与
java面向对象编程练习题,急求答案~用MyEclipse编写练习题】10.构造方法与重载、包编写Addition类,该类中应包含一组实现两数相加运算的重载方法。实现加法...
java 面向对象编程练习题,急求答案~ 用MyEclipse编写
练习题】10.构造方法与重载、包
编写Addition类,该类中应包含一组实现两数相加运算的重载方法。
实现加法运算的方法,应接受两个参数(即加数和被加数),方法将两个参数进行加法运算后,返回相加结果。考虑可能针对不同的数据类型进行计算,重载一组方法,包括整型、长整型、浮点型、双精度浮点型、还有字符串。
在main方法中创建Addition类的实例,分别调用重载方法测试其效果。
应将Addition类打入到包中,以自己名字的拼音为包命名。 展开
练习题】10.构造方法与重载、包
编写Addition类,该类中应包含一组实现两数相加运算的重载方法。
实现加法运算的方法,应接受两个参数(即加数和被加数),方法将两个参数进行加法运算后,返回相加结果。考虑可能针对不同的数据类型进行计算,重载一组方法,包括整型、长整型、浮点型、双精度浮点型、还有字符串。
在main方法中创建Addition类的实例,分别调用重载方法测试其效果。
应将Addition类打入到包中,以自己名字的拼音为包命名。 展开
2个回答
2013-11-02
展开全部
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 + "]";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询