htmlsalesformatter.java

来自「ssd 3 java程序练习 exercise 5 绝对没有问题」· Java 代码 · 共 45 行

JAVA
45 行
字号

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 + =
减小字号Ctrl + -
显示快捷键?