Vote count:
0
I'm working on a assignment for my second semester java class and I'm having a little trouble trying to figure out how best to loop this. I need the "choose an option" line to pop up at the beginning of each loop and allow the user to enter a,b,c or q. If the user picks a,b,c I want to it do the action and then to return to the "choose an option" line and start over and if the user enters q it should quit. What kind of loop should I use for this?
public void go() throws Exception {
Scanner kb = new Scanner(System.in);
ArrayList<Task> list = new ArrayList<Task>();
TaskManager taskMgr = new TaskManager();
System.out.println("Welcome to MyTaskManager");
System.out.println("choose an option \n a: Add a new item \n b: Display tasks by date \n c: Display tasks by keyword \n q: quit");
System.out.println("Enter your choice");
String choice = kb.nextLine();
if (choice.equalsIgnoreCase("a")) {
taskMgr.makeTasks();
}
else if (choice.equalsIgnoreCase("b")) {
System.out.println("enter the date you wish to view: ");
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
String date=kb.nextLine();
Date dueDate = sdf.parse(date);
taskMgr.findTasksByDate(dueDate);
taskMgr.displayTaskReportByDate(dueDate);
}
else if (choice.equalsIgnoreCase("c")) {
System.out.println(" Enter a keyword: ");
String keyword=kb.nextLine();
System.out.println("Task that contain the term "+keyword);
taskMgr.findTasksByKeyword(keyword);
taskMgr.displayTaskReportByKeyword(keyword);
}
else if (choice.equalsIgnoreCase("q")) {
System.exit(0);
}
else {
System.exit(0);
}
}
asked 42 secs ago
Aucun commentaire:
Enregistrer un commentaire