如何解决如何创建菜单系统以允许用户随意运行程序?
我正在尝试做到这一点,以便用户可以将员工信息添加到cvs文件引入的链接列表中。允许用户使用菜单系统来运行该程序,但是希望如此。我试图创建到菜单中的代码是发布在我的公共static void main中的。
public static void main(String[] args) {
Scanner blue = new Scanner(system.in);
//variables
int run = 0;
String choice2;
String choice1;
String IdDel;
int EmId = 0;
int Delete;
String findId;
int fId = 0;
char quit = 'n';
String input;
int choice = 0;
//Allow the user to add data
while (quit != 'q') {
System.out.println("First Name: ");
String fName = blue.nextLine();
System.out.println("Last Name: ");
String lName = blue.nextLine();
System.out.println("City: ");
String city = blue.nextLine();
System.out.println("State: ");
String state = blue.nextLine();
System.out.println("Employee ID: ");
EmId = Integer.parseInt(blue.nextLine());
//Add first or last
System.out.println("Enter this info first or last to the list? f/l");
choice1 = blue.nextLine().toLowerCase();
switch (choice1) {
case "f":
theList.insertFirst(fName,lName,city,state,EmId);
break;
case "l":
theList.insertLast(fName,EmId);
break;
default:
System.out.println("That was not a choice ");
break;
}
theList.displayForward();
//Allow the user to delete by employee number
System.out.println("Would you like to delete an employee? y/n");
IdDel = blue.nextLine().toLowerCase();
switch (IdDel) {
case "y":
System.out.println("Enter in the value to delete: ");
Delete = Integer.parseInt(blue.nextLine());
theList.deleteKey(Delete);
break;
case "n":
quit = IdDel.charat(0);
break;
default:
System.out.println("That was not a choice. ");
break;
}
//Allow the user to search by last name
System.out.println("Would you like to search for an employee? y/n");
findId = blue.nextLine().toLowerCase();
switch (findId) {
case "y":
System.out.println("Enter in the ID of the employee you wish to search for: ");
theList.findData(fId);
break;
case "n":
quit = findId.charat(0);
break;
default:
System.out.println("That was not a choice. ");
break;
}
//theList.displayForward();
String thePath = "c:\\z\\data100k.csv";
readFile(thePath);
theList.displayForward();
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。