📄 plaintextsalesformatter.java
字号:
/**
* This class implements a method that obtains a plain text
* representation of a {@link SalesFormatter} object.
*
* @author ll
* @version 1.0.0
* @see SalesFormatter
* @see Sales
* @see Order
* @see OrderItem
* @see PlainTextSalesFormatter
*/
public class PlainTextSalesFormatter implements SalesFormatter {
private final static String NEW_LINE =
System.getProperty("line.separator");
static private PlainTextSalesFormatter singletonInstance
= null;
static public PlainTextSalesFormatter getSingletonInstance(){
if (singletonInstance == null) {
singletonInstance = new PlainTextSalesFormatter();
}
return singletonInstance;
}
private PlainTextSalesFormatter(){
}
public String formatSales(Sales sales){
String out="";
int a=1;
for(Order order:sales)
{
out+= "------------------------"+NEW_LINE+
"Order " + a +NEW_LINE+""+NEW_LINE;
a++;
for(OrderItem items:order)
{
out+=items.getQuantity()
+" "+items.getProduct().getCode()
+" "+items.getProduct().getPrice()
+NEW_LINE;
}
out+=NEW_LINE+"Total="+order.getTotalCost()+NEW_LINE;
}
return out;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -