GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Java/Programs/ToDoList.java at main · Koder-Sunil/Java Expand file tree/ Copy pathToDoList.javaMore file actions 76 lines (69 loc) · 2.28 KB / Copy pathToDoList.javaFile metadata and controls76 lines (69 loc) · 2.28 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 package Programs; import java.util.ArrayList; import java.util.Scanner; public class ToDoList { public static void main(String[] args) { ArrayList<String> tasks = new ArrayList<>(); list(tasks); } public static void list(ArrayList<String> tasks) { Scanner sc = new Scanner(System.in); System.out.print("Function you want to apply(1-4):\n" + "1- View\n" + "2- Add\n" + "3- Delete All Tasks\n" + "> "); int desiredFunction = sc.nextInt(); choose(desiredFunction, tasks, sc); } public static void choose(int desiredFunction, ArrayList<String> tasks, Scanner sc) { if (desiredFunction == 1) { viewTask(tasks); } else if (desiredFunction == 2) { addTask(tasks); } else if (desiredFunction == 3) { deleteTasks(tasks); } else { System.out.println("Please choose in the range of 1 till 3 only!"); list(tasks); } } static void addTask(ArrayList<String> tasks) { Scanner sc = new Scanner(System.in); System.out.print("Task to save\n> "); tasks.add(sc.nextLine()); System.out.print("Add more?\n 1- Yes\n 2- No\n> "); int yn = sc.nextInt(); if (yn == 1) { addTask(tasks); } else if (yn == 2){ list(tasks); } else { System.out.println("Invalid number!"); addTask(tasks); } } static void viewTask(ArrayList<String> tasks) { if (tasks.isEmpty()) { System.out.println(""" -------------------- No current tasks! --------------------"""); } else { System.out.println(""" -------------------- Tasks --------------------"""); int counter = 1; for (int i = 0; i < tasks.size(); i++) { System.out.println(counter + "- " + tasks.get(i)); counter++; } } System.out.println("\nSelect from the following commands:"); list(tasks); } static void deleteTasks(ArrayList<String> tasks) { tasks.clear(); } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |