htmlsalesformatter.java
来自「SSD3 Ex5 答案 。」· Java 代码 · 共 75 行
JAVA
75 行
/**
* This class implements a method that obtains an HTML
* representation of a {@link SalesFormatter} object.
*
* @author ll
* @version 1.0.0
* @see SalesFormatter
* @see Sales
* @see Order
* @see OrderItem
* @see HTMLSalesFormatter
*/
public class HTMLSalesFormatter implements SalesFormatter{
private final static String NEW_LINE =
System.getProperty("line.separator");
static private HTMLSalesFormatter singletonInstance = null;
static public HTMLSalesFormatter getSingletonInstance(){
if (singletonInstance == null) {
singletonInstance = new HTMLSalesFormatter();
}
return singletonInstance;
}
private HTMLSalesFormatter(){
}
public String formatSales(Sales sales){
String out = "<html>"
+ NEW_LINE
+ " <body>"
+ NEW_LINE + ""
+ " <center><h2>Orders</h2></center>"
+ NEW_LINE;
for(Order order:sales)
{
out+=" <hr>"
+ NEW_LINE
+ " <h4>Total="
+ order.getTotalCost()
+ "</h4>"
+ NEW_LINE;
for(OrderItem items:order)
{
out+=
" <p>"+NEW_LINE
+ " <b>code:</b>"
+ items.getProduct().getCode()
+ "<br>"
+ NEW_LINE
+ " <b>quantity:</b>"
+ items.getQuantity()+"<br>"
+ NEW_LINE
+ " <b>price:</b>"
+ items.getProduct().getPrice()
+ NEW_LINE
+ " </p>"+NEW_LINE;
}
}
out+=" </body>"+NEW_LINE+"</html>"+NEW_LINE;
return out;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?