?? plaintextsalesformatter.java
字號:
public class PlainTextSalesFormatter implements SalesFormatter {
static private PlainTextSalesFormatter singletonInstance
= null;
static public PlainTextSalesFormatter getSingletonInstance() {
if (singletonInstance == null) {
singletonInstance = new PlainTextSalesFormatter();
}
return singletonInstance;
}
private PlainTextSalesFormatter() {
}
public String formatSales(Sales sales) {
int number=0;
double totalCost=0.0;
String string=new String();
String NEW_LINE =System.getProperty("line.separator");
for(Order elementOne :sales) {
string+=("----------------------"+NEW_LINE);
number++;
string+=("Order "+number+NEW_LINE);
for(OrderItem elementTwo :elementOne) {
string+=(elementTwo.getQuantity()+" "+
elementTwo.getProduct().getCode()+" "+
elementTwo.getProduct().getPrice()+NEW_LINE);
totalCost+=elementTwo.getValue();
}
string+=("Total = "+totalCost+NEW_LINE);
}
return string;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -