我如何确保这些字段在用户填写时不会留空?这是一个类文件,填写的信息会被另一个主文件调用。我想确保信息已填写,但要等到最后所有其他内容都已完成(我正在处理其他类文件)。如果名称留空,那么我希望程序说明名称字段留空并且需要填写,然后我才能单击完成按钮。任何和所有的帮助表示赞赏。
import java.util.Scanner;
public class fillInfo
{
public String name;
public String address;
public String telephone;
public void readInput()
{
Scanner keyboard = new Scanner(System.in);
System.out.println("What is the customers name?");
name = keyboard.nextLine();
System.out.println("What is the customers telephone number?");
telephone = keyboard.nextLine();
System.out.println("What is the customers address?");
address = keyboard.nextLine();
}
public void writeOutput()
{
System.out.println("Sold to: "+ name);
System.out.println("Telephone: "+ telephone);
System.out.println("Address: "+ address);
}
}