plaintextsalesformatter.java

来自「SSD3 Ex5 答案 。」· Java 代码 · 共 61 行

JAVA
61 行
字号

/**
  * This class implements a method that obtains a plain text
  * representation of a {@link SalesFormatter} object.
  *
  * @author ll
  * @version  1.0.0
  * @see SalesFormatter
  * @see Sales
  * @see Order
  * @see OrderItem
  * @see PlainTextSalesFormatter 
  */


public class PlainTextSalesFormatter implements SalesFormatter {
	
	 private final static String NEW_LINE =
	        System.getProperty("line.separator");
	 
	 static private PlainTextSalesFormatter singletonInstance
     = null;

	static public PlainTextSalesFormatter getSingletonInstance(){
		
		if (singletonInstance == null) {
            singletonInstance = new PlainTextSalesFormatter();
        }

        return singletonInstance;

	}
	private PlainTextSalesFormatter(){
		
		
	}
	public String formatSales(Sales sales){
		String out="";
		int a=1;
		for(Order order:sales)
		{
			out+= "------------------------"+NEW_LINE+
	                 "Order " + a +NEW_LINE+""+NEW_LINE;
			a++;
			for(OrderItem items:order)
			{
				out+=items.getQuantity()
				     +" "+items.getProduct().getCode()
				     +" "+items.getProduct().getPrice()
				     +NEW_LINE;
				
				
			}
			out+=NEW_LINE+"Total="+order.getTotalCost()+NEW_LINE;
		}

        return out;

	}
}

⌨️ 快捷键说明

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