public void displayShopList(String customerName) { for (Customer customer : customersList) { if (customerName.equals(customer.getName())) { stdOut.println("\nHere are the restaurants close to " + customerName); stdOut.println( "--------------------restaurants----------------------\n" + customer.getShopList().toString()); return; }
时间: 2023-08-15 12:44:03 浏览: 41
这是一个 Java 方法,用于根据顾客的名称显示其附近的所有餐厅信息。方法中使用 for-each 循环遍历所有顾客对象,检查是否有与输入的顾客名称匹配的顾客对象。如果找到匹配的顾客对象,就调用该顾客对象的 getShopList() 方法获取该顾客附近的所有餐厅的信息,并使用 System.out.println() 方法将这些信息输出到控制台。如果没有找到匹配的顾客对象,就不进行任何操作。这个方法的作用是根据顾客的名称,获取其附近的所有餐厅信息,并展示给用户。
相关问题
public void registerOrder() throws Exception { System.out.println("Please input your order like this: yourname_restaurantIdcode_foodIdcode" + "\n for example:" + "Lucy_0001_01"); while (true) { String str = null; try { str = stdIn.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } StringTokenizer stringTokenizer = new StringTokenizer(str, "_"); String customerName = (String) stringTokenizer.nextElement(); for (Customer customer : customersList) { if (customerName.equals(customer.getName())) { String shopIdcode = (String) stringTokenizer.nextElement(); // shopList.get(resturantName); String foodIdCode = (String) stringTokenizer.nextElement(); Food food = shopList.get(shopIdcode).getFoodList().getFood(foodIdCode); if (food == null) { stdErr.println("Failed in load food. \nmaybe in this resturant doesn't have this food." + "shopid: " + shopIdcode + " foodIdCode: " + foodIdCode); break; }
这是一个 Java 方法,用于注册订单。方法中使用 while 循环来不断读取用户输入的订单信息,直到用户输入有效的订单信息为止。在循环体内,首先使用 System.out.println() 方法提示用户输入订单信息的格式,并使用 System.in.readLine() 方法读取用户输入的订单信息。然后使用 StringTokenizer 类对用户输入的订单信息进行解析,获取订单中的顾客姓名、餐厅 ID 编码、菜品 ID 编码等信息。接着,使用 for-each 循环遍历顾客列表,查找与输入的顾客姓名相匹配的顾客对象。如果找到了匹配的顾客对象,则获取餐厅 ID 编码对应的餐厅对象,并使用餐厅对象的 getFood() 方法获取指定菜品 ID 编码对应的菜品对象。如果菜品对象不存在,则使用 System.err.println() 方法输出错误信息,提示用户检查输入的订单信息是否正确。如果菜品对象存在,则将订单信息保存到订单记录列表中,并使用 System.out.println() 方法提示用户订单注册成功。这个方法的作用是根据用户输入的订单信息,注册一个新的订单,并将订单信息保存到订单记录列表中。
Write a Java class for representing a work order in a warehouse shipment system.
public class WorkOrder {
// properties
private int orderNumber;
private String customerName;
private String address;
private String product;
private int quantity;
private boolean isCompleted;
// constructor
public WorkOrder(int orderNumber, String customerName, String address, String product, int quantity) {
this.orderNumber = orderNumber;
this.customerName = customerName;
this.address = address;
this.product = product;
this.quantity = quantity;
this.isCompleted = false;
}
// getter methods
public int getOrderNumber() {
return orderNumber;
}
public String getCustomerName() {
return customerName;
}
public String getAddress() {
return address;
}
public String getProduct() {
return product;
}
public int getQuantity() {
return quantity;
}
public boolean isCompleted() {
return isCompleted;
}
// setter method
public void completeOrder() {
this.isCompleted = true;
}
}