【发布时间】:2020-08-05 05:59:25
【问题描述】:
public class Order {
boolean isFilled;
double billAmount;
String shipping;
public Order(boolean filled, double cost, String shippingMethod) {
if (cost > 24.00) {
System.out.println("High value item!");
}
isFilled = filled;
billAmount = cost;
shipping = shippingMethod;
}
public void ship() {
if (isFilled) {
System.out.println("Shipping");
System.out.println("Shipping cost: " + calculateShipping());
} else {
System.out.println("Order not ready");
}
}
public double calculateShipping() {
if (shipping ="Regular") {
return 0;
} else if (shipping = "Express") {
return 1.75;
} else {
return .50;
}
}
public static void main(String[] args) {
// do not alter the main method!
Order book = new Order(true, 9.99, "Express");
Order chemistrySet = new Order(false, 72.50, "Regular");
book.ship();
chemistrySet.ship();
}
}
上面的代码导致这个错误:
Order.java:26: error: incompatible types: String cannot be converted to boolean
if (shipping="Regular")
{
^
Order.java:28: error: incompatible types: String cannot be converted to boolean
} else if (shipping = "Express") {
^
2 errors
【问题讨论】:
-
下面我的回答对你有帮助吗?如果有效请采纳
-
这里有人在说话,如果解决了问题,请接受我的回答,帮助我努力发现您的问题,您只需单击一下即可奖励我的帮助,成为乐于助人的会员这个社区的,请不要忽略这个stackoverflow.com/help/someone-answers
-
你能接我的电话吗?
标签: java methods boolean conditional-statements instance