Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To do list using java #396

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions To Do list using java/ToDoListApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import java.util.ArrayList;
import java.util.Scanner;

class Task {
private final String description;

public Task(String description) {
this.description = description;
}

public String getDescription() {
return description;
}
}

public class ToDoListApp {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<Task> tasks = new ArrayList<>();
int choice;

do {
System.out.println("\nTo-Do List Menu:");
System.out.println("1. Add Task");
System.out.println("2. Remove Task");
System.out.println("3. View All Tasks");
System.out.println("4. Exit");
System.out.print("Choose an option: ");
choice = scanner.nextInt();
scanner.nextLine(); // consume newline

switch (choice) {
case 1:
System.out.print("Enter task description: ");
String description = scanner.nextLine();
tasks.add(new Task(description));
System.out.println("Task added!");
break;
case 2:
System.out.print("Enter task number to remove: ");
int index = scanner.nextInt() - 1;
if (index >= 0 && index < tasks.size()) {
tasks.remove(index);
System.out.println("Task removed!");
} else {
System.out.println("Invalid task number!");
}
break;
case 3:
System.out.println("\nYour To-Do List:");
for (int i = 0; i < tasks.size(); i++) {
System.out.println((i + 1) + ". " + tasks.get(i).getDescription());
}
break;
case 4:
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice! Try again.");
}
} while (choice != 4);

scanner.close();
}
}
Binary file not shown.
Binary file not shown.