好的,伙计们,我有一个任务,它有一个抽象类“Order”和其他三个扩展它的类“OverseasOrder”、“RegularOrder”和“NonProfitOrder”
这是我的抽象类:
public abstract class Order {
protected String location;
protected double price;
public Order(double price, String location){
}
public abstract double calculateBill();
public String getLocation() {
return location;
}
public double getPrice() {
return price;
}
public abstract String printOrder(String format);
}
这是我的“NonProfitOrder”:
public class NonProfitOrder extends Order {
public NonProfitOrder(double price, String location) {
super(price, location);
}
public double calculateBill() {
double bill;
bill = price;
return bill;
}
public String printOrder(String format){
String Long = "Non-Profit Order" + "\nLocation: " + getLocation() + "\nTotal Price: " + getPrice();
return Long;
}
}
我正在一步一步地确保一切正常,所以这是我迄今为止编写的唯一课程。我遇到的问题是当我测试类似的东西时
public class OrderTester {
public static void main(String[] args) {
Order o;
o = new NonProfitOrder(2000.0, "NY");
System.out.println(o.printOrder("Long"));
}
}
非营利组织
位置:空
总价:0.0
我不确定我是否在我的字符串中调用了错误的“价格”和位置,或者我在尝试从抽象 Order 类中实现这些方法时做错了什么
感谢您的任何帮助!