目测以下程序代码能编译通过吗?不能的话有什么错误?若有错误则尝试在不改变原程
序语义的情况下,给出两种解决方案并分别实现在Calculator1.java和Calculator2.java
中(两种方法针对Exception的错误)。(找错误的时候尽量不使用IDE辅助,尽可能的找
出所有错误)。
package chapt3;
public class Calculator { public float getValue(String type) throws Exception {
// 获得产品单价
if (type.equals("cookie")) {
return 1.11f;
} else if (type.equals("pie")) {
return 5.5f;
}
}
public int getValue(String type) throws Exception {
// 获得产品数量
if (type.equals("cookie")) {
return 10;
} else {
return 20;
}
}
public float calculate() {
float price = getValue("cookie");
int amount = getValue("cookie");
return price * amount;
}
}
各位大虾,救救我。谢谢
序语义的情况下,给出两种解决方案并分别实现在Calculator1.java和Calculator2.java
中(两种方法针对Exception的错误)。(找错误的时候尽量不使用IDE辅助,尽可能的找
出所有错误)。
package chapt3;
public class Calculator { public float getValue(String type) throws Exception {
// 获得产品单价
if (type.equals("cookie")) {
return 1.11f;
} else if (type.equals("pie")) {
return 5.5f;
}
}
public int getValue(String type) throws Exception {
// 获得产品数量
if (type.equals("cookie")) {
return 10;
} else {
return 20;
}
}
public float calculate() {
float price = getValue("cookie");
int amount = getValue("cookie");
return price * amount;
}
}
各位大虾,救救我。谢谢
public float getValue(String type)
public int getValue(String type)
第一个函数少一个return
两个函数一样怎么行呢~~! getValue(String type) ;getValue(String type)
还有你用) throws Excepion列出异常 也没有try 语句~~~