📄 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 + -