Printing 'long' or 'short' form of a string
Hey guys I'm writing a program that has an abstract class 'Order' that is
extended by three classes 'NonProfitOrder', 'RegularOrder', and
'OverseasOrder'. Each implement the abstract method printOrder in the
abstract class.
The method accepts a string with is either "Long" or "Short"
If "Long" would look like:
Non-Profit Order
Location: CA
Total Price: 200.0
If "Short" would look like:
Non-Profit Order-Location: CA, Total Price: 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;
}
}
This is the code I have so far, which works fine to print "Long", my
question is how can I get it to print depending on which "Long" or "Short"
is called.
Is there a built in java method to do this? Or is there a certain way to
write this string?
Thanks for any and all help!
No comments:
Post a Comment