?? htmlsalesformatter.java
字號:
public class HTMLSalesFormatter implements SalesFormatter {
static private HTMLSalesFormatter singletonInstance
= null;
static public HTMLSalesFormatter getSingletonInstance() {
if (singletonInstance == null) {
singletonInstance = new HTMLSalesFormatter();
}
return singletonInstance;
}
private HTMLSalesFormatter() {
}
public String formatSales(Sales sales) {
double totalCost=0.0;
String string=new String();
String NEW_LINE =System.getProperty("line.separator");
string+=("<html>"+NEW_LINE+
" <body>"+NEW_LINE+
" <center><h2>Orders</h2></center>"+NEW_LINE);
for(Order elementOne :sales) {
for(OrderItem elementTwo :elementOne) {
totalCost+=elementTwo.getValue();
}
string+=("<hr>"+NEW_LINE+
"<h4>Total = "+totalCost+"</h4>");
for(OrderItem elementThere :elementOne) {
string+=(" <p>"+NEW_LINE+
"<b>code:</b> "+elementThere.getProduct().getCode()+
"<br>"+NEW_LINE+
"<b>code:</b> "+elementThere.getQuantity()+
"<br>"+NEW_LINE+
"<b>code:</b> "+elementThere.getProduct().getPrice()+
"<br>"+NEW_LINE+
" </p>");
}
}
string+=(" </body>"+NEW_LINE+
"</html>");
return string;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -