⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlsalesformatter.java

📁 CMU Java课程设计
💻 JAVA
字号:
import java.util.Iterator;

public class HTMLSalesFormatter implements SalesFormatter {
    private final static String NEW_LINE =

        System.getProperty("line.separator");
	static HTMLSalesFormatter singletonInstance;
	static public HTMLSalesFormatter getSingletonInstance()
	//Static method that obtains the single instance of class HTMLSalesFormatter. 
	{

        if (singletonInstance == null) {

            singletonInstance = new HTMLSalesFormatter();

        }
        return singletonInstance;
	}
	private HTMLSalesFormatter()
	//Constructor that is declared private so it is inaccessible to other classes. A private constructor makes it impossible for any other class to create an instance of class HTMLSalesFormatter. 
	{
		
	}
	public String formatSales(Sales sales)
	//Produces a string that contains the specified sales information in an HTML format. 
	{
		int numOrders = sales.getNumberOfOrders();
		String out = "" ;
		if (numOrders != 0) {
			 out = "<html>"

                 + NEW_LINE

                 + "  <body>"

                 + NEW_LINE + ""

                 + "    <center><h2>Orders</h2></center>"

                 + NEW_LINE;
				int orderNumber = 1;
				for (Iterator i = sales.getOrdersIterator();i.hasNext();) {
					Order order = (Order) i.next();
				    out += "    <hr>"

		                   + NEW_LINE

		                   + "    <h4>Total ="+order.getTotalCost()+"<h4>"+"\n";

				    orderNumber++;
					for (Iterator j= order.getItemsIterator();j.hasNext();){
						OrderItem item=(OrderItem) j.next();
						out+="<p>"
							+ NEW_LINE;			
						 out +="<b>code:</b>"+item.getProduct().getCode()+"<br>"+NEW_LINE;
						 out +="<b>quantity:</b>"+item.getQuantity()+"<br>"+NEW_LINE;
						 out +=" <b>price:</b> "+item.getProduct().getPrice()+NEW_LINE;
						 out +="</p>"+NEW_LINE;
						 }
					out+="\nTotal ="+order.getTotalCost()+"\n";
					}
				 out +="</body>"+NEW_LINE;
				 out +="</html>"+NEW_LINE;
		}
				else
				{
				System.out.println("Sorry~There is no sales");
				}
				return out;
				}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -