public static void makeSandwich()
{
System.out.println("Enter First Name: ");
String name = Scanner.next();
double price = sandwich.getBreadPrice() + sandwich.getMeatPrice() + sandwich.getVegPrice();
sandwich.setPrice(price);
NumberFormat currency = NumberFormat.getCurrencyInstance();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
System.out.println(dateFormat.format(date) + " " + name + " " + sandwich.getBread() + " " + sandwich.getMeat() + " " + sandwich.getVegetables() + " " + currency.format(sandwich.getPrice()));
OrderLine.writeOrderLine(name, sandwich.getBread(), sandwich.getMeat(), sandwich.getVegetables(), sandwich.getPrice());
}
这是我的 orderline.app 代码
public class OrderLine{
private static Sandwich sandwich = null;
public static void writeOrderLine(String name, String bread, String meat, String veg, double price)
{
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
try
{
File productsFile = new File("orderline.txt");
PrintWriter out = new PrintWriter(
new BufferedWriter(
new FileWriter(productsFile, true)));
out.print(dateFormat.format(date) + "\t");
out.print(name + "\t");
out.print(sandwich.getBread() + "\t");
out.print(sandwich.getMeat() + "\t");
out.print(sandwich.getVegetables() + "\t");
out.println(sandwich.getPrice() + "\t");
out.close();
}
catch (IOException e)
{
System.out.println(e);
}
}
}
它根本不打印,但是当我在 orderline.java 中的 dateformat 之前添加这一行“sandwich = new Sandwich()”时它可以工作,但它最终给了我空字符串,因为我想我正在创建一个新的三明治. 我怎么称呼我已经做好的三明治?