东北大学软件学院面向对象程序设计实验四GourmetCoffee.java

更新时间:2023-06-29 18:44:55 阅读: 评论:0

import java.io.*;
import java.util.*;
*;
/**
* This class implements a gourmet coffee system.
*
* @author author name
* @version 1.1.0
* @e Product
* @e Coffee
* @e CoffeeBrewer
* @e Catalog
* @e OrderItem
* @e Order
* @e SalesFormatter
* @e PlainTextSalesFormatter
* @e HTMLSalesFormatter
* @e XMLSalesFormatter
* @e CatalogLoader
* @e FileCatalogLoader
*/
public class GourmetCoffee  {
private static BufferedReader  stdIn =
new  BufferedReader(new  InputStreamReader(System.in));
private static PrintWriter  stdOut = new  PrintWriter(System.out, true);
小米路由器3cprivate static PrintWriter  stdErr = new  , true);
private Catalog  catalog;
private Sales  sales;
private SalesFormatter salesFormatter;
/**
* Loads catalog data from a file and starts the application.
* <p>
* The name of the file is specified in the command arguments.
* </p>
*
* @param args  String arguments.
* @throws IOException if there are errors in the input.
*/
public static void  main(String[]  args) throws IOException  {
Catalog catalog = null;
if (args.length != 1) {
stdErr.println("Usage: java GourmetCoffee filename");
} el {
try {
catalog =
(new FileCatalogLoader()).loadCatalog(args[0]);
} catch (FileNotFoundException fnfe) {
stdErr.println("The file does not exist");
斑鸠调it(1);
} catch (DataFormatException dfe) {
stdErr.println("The file contains malformed data: "
+ Message());
}
GourmetCoffee  application =
狠狠2015
new GourmetCoffee(catalog);
application.run();
}
}
/**
* Constructs a <code>GourmetCoffee</code> object.
* Initializes the catalog data with the value specified
* in the parameter.
*
* @param initialCatalog a product catalog
优美近义词
*/
private GourmetCoffee(Catalog initialCatalog) {
this.catalog = initialCatalog;
this.sales = new Sales();
this.salesFormatter =
loadSales();
}
/**
* Initializes the sales object.
*/
private void loadSales() {
Order orderOne = new Order();
Product productOne = Product("C001");
if (productOne != null) {
orderOne.addItem(new OrderItem(productOne, 5));
this.sales.addOrder(orderOne);
}
Order orderTwo = new Order();
Product productTwo = Product("C002");
Product productThree = Product("A001");
if ((productTwo != null) && (productThree != null)) {
orderTwo.addItem(new OrderItem(productTwo, 2));
orderTwo.addItem(new OrderItem(productThree, 2));
this.sales.addOrder(orderTwo);
}
Order orderThree = new Order();
Product productFour = Product("B002");
if (productFour != null) {
家政服务合同
orderThree.addItem(new OrderItem(productFour, 1));
this.sales.ad
dOrder(orderThree);
}
}
/
**
* Prents the ur with a menu of options and executes the
* lected task.
*/
private void run() throws IOException  {
int  choice = getChoice();
while (choice != 0)  {
if (choice == 1)  {
displayCatalog();
} el if (choice == 2)  {
this.salesFormatter =
writeFile(
readFilename(),
this.salesFormatter.formatSales(this.sales));
} el if (choice == 3)  {
this.salesFormatter =
writeFile(
readFilename(),
this.salesFormatter.formatSales(this.sales));
} el if (choice == 4)  {
this.salesFormatter =
咪咪色吧writeFile(
readFilename(),
this.salesFormatter.formatSales(this.sales));
}
choice = getChoice();
}
}
/**
* Displays a menu of options and verifies the ur's choice.
*
* @return an integer in the range [0,7]
*/
private int  getChoice() throws IOException  {
int  input;
do  {
try  {
stdErr.println();
stdErr.print("[0]  Quit\n"
+ "[1]  Display Catalog\n"
+ "[2]  Save sales (Plain Text)\n"
+ "[3]  Save sales (HTML)\n"
+ "[4]  Save sales (XML)\n"
+ "choice> ");
stdErr.flush();
input = Integer.adLine());
stdErr.println();
if (0 <= input && 4 >= input)  {
break;
} el {
stdErr.println("Invalid choice:  " + input);
}
} catch (NumberFormatException  nfe)  {
stdErr.println(nfe);
}
}  while (true);
return  input;
}
/**
* Displays the catalog.
*/
private void displayCatalog() {
int size = NumberOfProducts();
if (size == 0) {
stdErr.println("The catalog is empty");
} el {
送柴侍御王昌龄for (Product product : this.catalog) {
stdOut.Code() + " "
+ Description());
}
}
}
/**
* Creates a new file (which has the specified name) and writes
* the specified string to the new file.
*
* @param filename name of the file that will store the data
* @param content data to be stored
*/
private void writeFile(String filename, String content)
throws IOException {
/* PLACE YOUR CODE HERE */
File file = new File(filename);
ists())
开始图标
file.delete();
FileWriter fileWriter = new Name(), true);
BufferedWriter bufferWriter = new BufferedWriter(fileWriter);
bufferWriter.write(content);
bufferWriter.clo();
}
/**
* Prompts the ur for a filename (the name of the file that
* will store the sales information) and returns the ur's
* respon.
*
* @return name of a file
*/
private  String readFilename() throws IOException  {
stdErr.print(
"Filename> ");
stdErr.flush();
adLine();
}
}

本文发布于:2023-06-29 18:44:55,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1060471.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:路由器   服务   开始   小米
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图