こんにちは、「NonProfitOrder」、「RegularOrder」、および「OverseasOrder」の 3 つのクラスによって拡張された抽象クラス「Order」を持つプログラムを作成しています。それぞれが、抽象クラスで抽象メソッド printOrder を実装します。
このメソッドは、「Long」または「Short」のいずれかの文字列を受け入れます
「長い」が次のようになる場合:
非営利の注文
場所: カリフォルニア州
合計金額: 200.0
「Short」が次のようになる場合:
非営利の注文場所: CA、合計金額: 200.0
public class NonProfitOrder extends Order {
public NonProfitOrder(double price, String location) {
super(price, location);
}
public double calculateBill() {
return getPrice();
}
public String printOrder(String format){
String Long = "Non-Profit Order" + "\nLocation: " + getLocation() + "\nTotal Price: " + getPrice();
return Long;
}
}
これは私がこれまで持っていたコードで、「Long」を印刷するのに問題なく動作します。私の質問は、「Long」または「Short」のどちらが呼び出されるかに応じて、どのように印刷できるかです。
これを行う組み込みのJavaメソッドはありますか?または、この文字列を記述する特定の方法はありますか?
助けてくれてありがとう!