关于以下项目的澄清

这是要做的任务。

  1. 当所有数据均有效时,设置orderId并将Order对象添加到静态列表(orderlist)。
  2. 2.“ orderId”应比已在数组列表中放置的订单数多1。
  3. 如果违反任何方法,则引发异常。

注意:请考虑验证方法为真。

我一直坚持进行下去。需要澄清请解释要求什么!

包com.foodzoo.OrderFood;

导入java.util.List; 导入java.util.Scanner;

公共类JavaBasicMain {

public static List<Order> orderlist;

public static void main(String[] args) {

    Order order = new Order();// create an Object of Order class to initiate the required variables.
    Scanner scan = new Scanner(System.in);// Use Scanner Class to get input from the User/Console.
    System.out.println("Enter the name:");// prompt the user to enter the Name.
    order.setName(scan.nextLine());// set the console read value to setName method in Order class.
    System.out.println("Enter the emailId:");
    order.setEmailId(scan.nextLine());
    System.out.println("Enter the mobileNo:");
    order.setMobileNo(scan.nextLong());
    System.out.println("Enter the ordertype(snacks/meal):");
    scan.next();
    order.setOrderType(scan.nextLine());
    System.out.println("Enter the menu(veg/non-veg/vegan):");
    order.setMenu(scan.nextLine());

    // Instantiate an object of ValidateElement Class to validate the input provided
    // by the User.
    ValidateElements validateElement = new ValidateElements();

    // Invoking all methods in ValidateElement Class.
    try {
        validateElement.validateEmailId(order.getEmailId());
        validateElement.validateMobileNumber(order.getMobileNo());
        validateElement.validateName(order.getName());

    } catch (Exception exeption) {
        System.out.println("Invalid Data!");
    }
    //orderlist.add(order.get);
    //System.out.println(orderlist.toString());

}

}

OrderClass 包com.foodzoo.OrderFood;

公共类命令{

private String name;
private String emailId;
private String orderType;
private String menu;
private Long mobileNo;
private Integer orderId;
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getEmailId() {
    return emailId;
}
public void setEmailId(String emailId) {
    this.emailId = emailId;
}
public String getOrderType() {
    return orderType;
}
public void setOrderType(String orderType) {
    this.orderType = orderType;
}
public String getMenu() {
    return menu;
}
public void setMenu(String menu) {
    this.menu = menu;
}
public Long getMobileNo() {
    return mobileNo;
}
public void setMobileNo(Long mobileNo) {
    this.mobileNo = mobileNo;
}
public Integer getOrderId() {
    return orderId;
}
public void setOrderId(Integer orderId) {
    this.orderId = orderId;
}

} **************************************** ValidateElements类************ ***** 包com.foodzoo.OrderFood;

公共类ValidateElements {

public boolean validateEmailId(String emailId) {

    if (emailId.contains("xyz"))
        return true;
    else
        return false;
}

public boolean validateName(String name) {
    if (name.contains("xyz"))
        return true;
    else
        return false;
}

public boolean validateMobileNumber(long number) {
    if (number==123)
        return true;
    else
        return false;
}

}

评论