东北大学java coffee实验一的代码哦

 

 大家好,今天给大家带来的是东北大学java coffee实验一的代码哦,欢迎大家积极讨论,参考一下就行,一起加油哦

import java.util.ArrayList;

public class HTMLSalesFormatter implements SalesFormatter{

	private static HTMLSalesFormatter singletonInstance;
	
	private HTMLSalesFormatter()
	{
		
	}
	
	public static HTMLSalesFormatter getSingletonInstance()
	{
		if(singletonInstance==null) 
		{
		return singletonInstance=new HTMLSalesFormatter();
		}
		
		return singletonInstance;
		
	}
	
	private ArrayList<String> zifuchuan=new ArrayList<String>();
	public String formatSales(Sales sales)
	{
		zifuchuan.add("<html>\n"+"  <body>\n"+"    <center><h2>Orders</h2></center>\n");
		
		for(Order order:sales)
		{
			zifuchuan.add("    <hr>\n"+"    <h4>Total = "+order.getTotalCost()+"</h4>\n");
			
			for(OrderItem orderItem:order)
			{
				zifuchuan.add("      <p>\n"+"        <b>code:</b> "+orderItem.getProduct().getCode()+"<br>\n");
				zifuchuan.add("        <b>quantity:</b> "+orderItem.getQuantity()+"<br>\n");
				zifuchuan.add("        <b>price:</b> "+orderItem.getProduct().getPrice()+"\n      </p>\n");
				
				
				
			}
			
			
		}
		zifuchuan.add("  </body>\n"+"</html>");
	
		String a="";
		for(int i=0;i<zifuchuan.size();i++)
		{
			a+=zifuchuan.get(i);
			
		}
		return a;
		
	}
	
	
}
import java.util.ArrayList;

public class PlainTextSalesFormatter implements SalesFormatter{

	private static PlainTextSalesFormatter singletonInstance;
	
	private PlainTextSalesFormatter()
	{
		
	}
	
	public static PlainTextSalesFormatter getSingletonInstance()
	{
		
		if(singletonInstance==null) 
		{
		return singletonInstance=new PlainTextSalesFormatter();
		}
		
		return singletonInstance;
	}
	
	
	private ArrayList<String> zifuchuan=new ArrayList<String>();
	public String formatSales(Sales sales)
	{
		int k=1;
		
		for(Order order:sales)
		{
			zifuchuan.add("------------------------\n");
			zifuchuan.add("Order "+k+"\n\n");
			for(OrderItem orderItem:order)
			{
				zifuchuan.add(orderItem.getQuantity()+" "+orderItem.getProduct().getCode()+" "+orderItem.getProduct().getPrice()+"\n\n");
				
				
				
			}
			zifuchuan.add("Total = "+order.getTotalCost()+"\n");
			k++;
			
		}
		
		String a="";
		for(int i=0;i<zifuchuan.size();i++)
		{
			a+=zifuchuan.get(i);
			
		}
		return a;
	}
	
	
}
import java.util.ArrayList;

public class XMLSalesFormatter implements SalesFormatter{

	private static XMLSalesFormatter singletonInstance;
	
	private XMLSalesFormatter()
	{
		
	}
	
	public static XMLSalesFormatter getSingletonInstance()
	{
		if(singletonInstance==null) 
		{
		return singletonInstance=new XMLSalesFormatter();
		}
		
		return singletonInstance;
		
	}
	
	private ArrayList<String> zifuchuan=new ArrayList<String>();
	public String formatSales(Sales sales)
	{
		zifuchuan.add("<Sales>\n");
		
		for(Order order:sales)
		{
			zifuchuan.add("  <Order total=\""+order.getTotalCost()+"\">\n");
			
			for(OrderItem orderItem:order)
			{
				zifuchuan.add("    <OrderItem quantity=\""+orderItem.getQuantity()+"\""+" price=\""+orderItem.getProduct().getPrice()+"\""+">"+orderItem.getProduct().getCode()+"</OrderItem>\n");
				
				
			}
			zifuchuan.add("  </Order>\n");
			
		}
		
		zifuchuan.add("</Sales>");
		
		String a="";
		for(int i=0;i<zifuchuan.size();i++)
		{
			a+=zifuchuan.get(i);
			
		}
		return a;
		
		
		
	}
	
}
import java.io.*;
import java.util.*;
//import java.text.*;

/**
 * This class implements a gourmet coffee system.
 *
 * @author author name
 * @version 1.1.0
 * @see Product
 * @see Coffee
 * @see CoffeeBrewer
 * @see Catalog
 * @see OrderItem
 * @see Order
 * @see SalesFormatter
 * @see PlainTextSalesFormatter
 * @see HTMLSalesFormatter
 * @see XMLSalesFormatter
 */
public class GourmetCoffee  {

	private static BufferedReader  stdIn =
		new  BufferedReader(new  InputStreamReader(System.in));
	private static PrintWriter  stdOut = new  PrintWriter(System.out, true);
	private static PrintWriter  stdErr = new  PrintWriter(System.err, true);

	private Sales  sales;

	private SalesFormatter  salesFormatter;

	/**
	 * Loads data into the catalog and starts the application.
	 *
	 * @param args  String arguments.  Not used.
	 * @throws IOException if there are errors in the input.
	 */
	public static void  main(String[]  args) throws IOException  {

		GourmetCoffee  application = new  GourmetCoffee();
		application.run();

	}

	/**
	 * Constructs a <code>GourmetCoffee</code> object and
	 * initializes the catalog and sales data.
	 *
	 * @param initialCatalog a product catalog
	 */
	private GourmetCoffee() {

		this.sales = new Sales();
		this.salesFormatter = 
			PlainTextSalesFormatter.getSingletonInstance();

		loadSales(loadCatalog());
	}

	/**
	 * Creates an empty catalog and then add products to it.
	 *
	 * @return a product catalog
	 */
	private Catalog loadCatalog() {

		Catalog catalog = new Catalog();

		catalog.addProduct(
			new Coffee("C001", "Colombia, Whole, 1 lb", 17.99,
				"Colombia", "Medium", "Rich and Hearty", "Rich",
				"Medium", "Full"));
		catalog.addProduct(
			new Coffee("C002", "Colombia, Ground, 1 lb", 18.75,
				"Colombia", "Medium", "Rich and Hearty", "Rich",
				"Medium","Full"));
		catalog.addProduct(
			new Coffee("C003", "Italian Roasts, Whole, 1 lb",
				16.80, "Latin American Blend", "Italian Roast",
				"Dark and heavy", "Intense", "Low", "Medium"));
		catalog.addProduct(
			new Coffee("C004", "Italian Roasts, Ground, 1 lb",
				17.55, "Latin American Blend", "Italian Roast",
				"Dark and heavy", "Intense", "Low", "Medium"));
		catalog.addProduct(
			new Coffee("C005", "French Roasts, Whole, 1 lb",
				16.80, "Latin American Blend", "French Roast",
				"Bittersweet, full intense", "Intense, full", "None", "Medium"));
		catalog.addProduct(
			new Coffee("C006", "French Roasts, Ground, 1 lb",
				17.55, "Latin American Blend", "French Roast",
				"Bittersweet, full intense", "Intense, full", "None", "Medium"));
		catalog.addProduct(
			new Coffee("C007", "Guatemala, Ground, 1 lb", 17.99,
				"Guatemala", "Medium", "Rich and complex", "Spicy",
				"Medium to high", "Medium to full"));
		catalog.addProduct(
			new Coffee("C008", "Guatemala, Ground, 1 lb", 18.75,
				"Guatemala", "Medium", "Rich and complex", "Spicy",
				"Medium to high", "Medium to full"));
		catalog.addProduct(
			new Coffee("C009", "Guatemala, Whole, 1 lb", 19.99,
				"Sumatra", "Medium", "Vibrant and powdery",
				"Like dark chocolate", "Gentle", "Rich and full"));
		catalog.addProduct(
			new Coffee("C010", "Guatemala, Ground, 1 lb", 20.50,
				"Sumatra", "Medium", "Vibrant and powdery",
				"Like dark chocolate", "Gentle", "Rich and full"));
		catalog.addProduct(
			new Coffee("C011", "Special Blend, Whole, 1 lb",
				16.80, "Latin American Blend", "Dark roast",
				"Full, roasted flavor", "Hearty", "Bold and rich", "Full"));
		catalog.addProduct(
			new Coffee("C012", "Special Blend, Ground, 1 lb",
				17.55, "Latin American Blend", "Dark roast",
				"Full, roasted flavor", "Hearty", "Bold and rich", "Full"));

		catalog.addProduct(
			new CoffeeBrewer("B001", "Home Coffee Brewer",
				150.00, "Brewer 100", "Pourover", 6));
		catalog.addProduct(
			new CoffeeBrewer("B002", "Coffee Brewer, 2 Warmers",
				200.00, "Brewer 200", "Pourover", 12));
		catalog.addProduct(
			new CoffeeBrewer("B003", "Coffee Brewer, 3 Warmers",
				280.00, "Brewer 210", "Pourover", 12));
		catalog.addProduct(
			new CoffeeBrewer("B004", "Commercial Brewer, 20 cups",
				380.00, "Quick Coffee 100", "Automatic", 20));
		catalog.addProduct(
			new CoffeeBrewer("B005", "Commercial Brewer, 40 cups",
				480.00, "Quick Coffee 200", "Automatic", 40));

		catalog.addProduct(
			new Product("A001", "Almond Flavored Syrup", 9.00));
		catalog.addProduct(
			new Product("A002", "Irish Creme Flavored Syrup", 9.00));
		catalog.addProduct(
			new Product("A003", "Mint Flavored syrup", 9.00));
		catalog.addProduct(
			new Product("A004", "Caramel Flavored Syrup", 9.00));
		catalog.addProduct(
			new Product("A005", "Gourmet Coffee Cookies", 12.00));
		catalog.addProduct(
			new Product("A006", "Gourmet Coffee Travel Thermo", 18.00));
		catalog.addProduct(
			new Product("A007", "Gourmet Coffee Ceramic Mug", 8.00));
		catalog.addProduct(
			new Product("A008", "Gourmet Coffee 12 Filters", 15.00));
		catalog.addProduct(
			new Product("A009", "Gourmet Coffee 36 Filters", 45.00));

		return catalog;
	}

	/**
	 * Initializes the sales object.
	 */
	private void loadSales(Catalog catalog) {

		Order orderOne = new Order();

		orderOne.addItem(new OrderItem(catalog.getProduct("C001"), 5));
		this.sales.addOrder(orderOne);

		Order orderTwo = new Order();

		orderTwo.addItem(new OrderItem(catalog.getProduct("C002"), 2));
		orderTwo.addItem(new OrderItem(catalog.getProduct("A001"), 2));
		this.sales.addOrder(orderTwo);

		Order orderThree = new Order();

		orderThree.addItem(new OrderItem(catalog.getProduct("B002"), 1));
		this.sales.addOrder(orderThree);
	}

	/**
	 * Displays a menu of options and verifies the user's choice.
	 *
	 * @return an integer in the range [0,3]
	 */
	private int  getChoice() throws IOException  {

		int  input;

		do  {
			try  {
				stdErr.println();
				stdErr.print("[0]  Quit\n"
				             + "[1]  Display sales (Plain Text)\n"
				             + "[2]  Display sales (HTML)\n"
				             + "[3]  Display sales (XML)\n"
				             + "choice> ");
				stdErr.flush();

				input = Integer.parseInt(stdIn.readLine());

				stdErr.println();

				if (0 <= input && 3 >= input)  {
					break;
				} else {
					stdErr.println("Invalid choice:  " + input);
				}
			} catch (NumberFormatException  nfe)  {
				stdErr.println(nfe);
			}
		}  while (true);

		return  input;
	}

	/**
	 * Changes the sales formatter.
	 *
	 * @param newFormatter a sales formatter
	 */
	private void setSalesFormatter(SalesFormatter newFormatter){

		/* PLACE YOUR CODE HERE */
		this.salesFormatter=newFormatter;
		
		
	}

	/**
	 * Displays the sales information in the current format.
	 */
	private void displaySales() {

		/* PLACE YOUR CODE HERE */
		System.out.println(this.salesFormatter.formatSales(sales));
		
		
	}

	/**
	 * Presents the user with a menu of options and executes the
	 * selected task.
	 */
	private void run() throws IOException  {

		int  choice = getChoice();

		while (choice != 0)  {

			if (choice == 1)  {

				/* PLACE YOUR CODE HERE */
			  GourmetCoffee L=new GourmetCoffee();
			  L.setSalesFormatter(PlainTextSalesFormatter.getSingletonInstance());
			  L.displaySales();
				

			} else if (choice == 2)  {

				/* PLACE YOUR CODE HERE */
				GourmetCoffee B=new GourmetCoffee();
				B.setSalesFormatter(HTMLSalesFormatter.getSingletonInstance());
				B.displaySales();
				

			} else if (choice == 3)  {

				/* PLACE YOUR CODE HERE */
				GourmetCoffee D=new GourmetCoffee();
				D.setSalesFormatter(XMLSalesFormatter.getSingletonInstance());
				D.displaySales();

			}

			choice = getChoice();
		}
	}
}

宝贝,参考一下就行,别直接抄,好歹改一下参数与命名,一起加油哦

阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。去创作
  • 11
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
微信小程序是一种运行在微信客户端中的应用程序,能够为用户提供各种服务和功能。Coffeeshop是一个开源的微信小程序项目,它致力于为用户提供咖啡店的在线预订和支付服务。 这个小程序源代码包含了咖啡店的前后端代码和数据库设计。前端代码使用了微信小程序的开发语言和框架,能够提供良好的用户界面和良好的用户体验。后端代码则使用了常见的后端开发语言和框架,与前端代码相结合,实现了用户预订咖啡和支付的功能。 在Coffeeshop小程序中,用户可以通过浏览咖啡店的菜单、了解咖啡店的位置和营业时间等信息。用户可以选择需要的咖啡、数量和附加选项,然后进行预订。系统会生成一个唯一的订单编号,并生成相应的二维码供用户扫描支付。用户支付成功后,系统会发送通知给咖啡店,并在数据库中记录订单信息。 对于咖啡店来说,他们可以通过Coffeeshop小程序管理菜单、设置营业时间和地点等信息。当顾客预订咖啡时,咖啡店可以及时收到通知,然后准备咖啡和相关配料。咖啡店可以使用后台管理系统查看订单信息,包括订单详情、支付状态和顾客联系方式等。 通过这个开源项目,其他开发者可以学习和了解微信小程序的开发流程和技术细节。他们可以根据自己的需求和喜好,对源代码进行修改和自定义,以创建适合自己咖啡店或其他行业的小程序。这个开源项目也可以帮助咖啡店提升服务质量和效率,提高用户满意度和利润。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

76博68

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值