我丢失了花括号还是正在发生其他事情,而我完全破坏了Java,这是它可以提供的唯一错误?我已经参加了很长时间了,我看不到它的缺失之处。我尝试过删除并放在括号中。我不断收到此错误:
Pizza.java:40:错误:缺少返回语句 } ^ 1个错误
工具已完成,退出代码为1
public class Pizza {
private String customerName;
private String pizzaSize;
private int toppings;
Pizza (String name, String size, int number){
customerName = name;
pizzaSize = size;
toppings = toppings;
}
public String getCustomerName(){
return customerName;
}
public void setCustomerName(String name){
customerName = name;
}
public double calculateCharge(){
final double SMALL_BASE_CHARGE = 6.50;
final double SMALL_TOPPING_CHARGE = .75;
final double MEDIUM_BASE_CHARGE = 10.50;
final double MEDIUM_TOPPING_CHARGE = 1.25;
final double LARGE_BASE_CHARGE = 14.50;
final double LARGE_TOPPING_CHARGE = 1.75;
double charge = 0.0;
}
}
答案 0 :(得分:2)
您的编译器说您在calculateCharge()方法末尾缺少返回语句。
因此,只需添加一个return语句,像这样
public double calculateCharge()
{
final double SMALL_BASE_CHARGE = 6.50;
final double SMALL_TOPPING_CHARGE = .75;
final double MEDIUM_BASE_CHARGE = 10.50;
final double MEDIUM_TOPPING_CHARGE = 1.25;
final double LARGE_BASE_CHARGE = 14.50;
final double LARGE_TOPPING_CHARGE = 1.75;
double charge = 0.0;
// TODO: Do your math here
return charge;
}
答案 1 :(得分:1)
不缺少括号,消息清晰
error: missing return statement
您指定了calculateCharge()
函数将返回double
,但您忘记返回某些内容。
public double calculateCharge()
{
final double SMALL_BASE_CHARGE = 6.50;
final double SMALL_TOPPING_CHARGE = .75;
final double MEDIUM_BASE_CHARGE = 10.50;
final double MEDIUM_TOPPING_CHARGE = 1.25;
final double LARGE_BASE_CHARGE = 14.50;
final double LARGE_TOPPING_CHARGE = 1.75;
double charge = 0.0;
// HERE
return charge;
}