Skip to content

Commit 52630a1

Browse files
ListScanner
1 parent fa3a573 commit 52630a1

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

ListScanner/readme.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# List Scanner (Java)
2+
3+
This is a simple console-based List Scanner application implemented in Java.
4+
5+
## How to Use
6+
7+
1. Compile and run `Main.java`.
8+
2. Choose options to manage tasks in your To-Do List.
9+
3. Follow the on-screen instructions to add, list, mark as completed, or remove tasks.
10+
11+
## Features
12+
13+
- Add new tasks with descriptions.
14+
- List all tasks in the To-Do List.
15+
- Mark tasks as completed.
16+
- Remove tasks from the list.
17+
- Interactive console interface.
18+
19+
## Technologies Used
20+
21+
- Java
22+
23+
Feel free to modify the code to add more features or extend its functionality.

ListScanner/scanner.java

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import java.util.ArrayList;
2+
import java.util.Scanner;
3+
4+
public class ToDoListApp {
5+
private static ArrayList<Task> taskList = new ArrayList<>();
6+
private static int taskIdCounter = 1;
7+
8+
public static void main(String[] args) {
9+
Scanner scanner = new Scanner(System.in);
10+
11+
while (true) {
12+
System.out.println("To-Do List Application");
13+
System.out.println("1. Add Task");
14+
System.out.println("2. List Tasks");
15+
System.out.println("3. Mark Task as Completed");
16+
System.out.println("4. Remove Task");
17+
System.out.println("5. Exit");
18+
System.out.print("Enter your choice: ");
19+
20+
int choice = scanner.nextInt();
21+
scanner.nextLine(); // Consume the newline
22+
23+
switch (choice) {
24+
case 1:
25+
addTask(scanner);
26+
break;
27+
case 2:
28+
listTasks();
29+
break;
30+
case 3:
31+
markTaskAsCompleted(scanner);
32+
break;
33+
case 4:
34+
removeTask(scanner);
35+
break;
36+
case 5:
37+
System.out.println("Goodbye!");
38+
System.exit(0);
39+
default:
40+
System.out.println("Invalid choice. Please try again.");
41+
}
42+
}
43+
}
44+
45+
private static void addTask(Scanner scanner) {
46+
System.out.print("Enter the task description: ");
47+
String description = scanner.nextLine();
48+
Task task = new Task(taskIdCounter, description);
49+
taskList.add(task);
50+
taskIdCounter++;
51+
System.out.println("Task added successfully!");
52+
}
53+
54+
private static void listTasks() {
55+
if (taskList.isEmpty()) {
56+
System.out.println("No tasks to display.");
57+
} else {
58+
System.out.println("Tasks:");
59+
for (Task task : taskList) {
60+
System.out.println(task);
61+
}
62+
}
63+
}
64+
65+
private static void markTaskAsCompleted(Scanner scanner) {
66+
System.out.print("Enter the task ID to mark as completed: ");
67+
int taskId = scanner.nextInt();
68+
scanner.nextLine(); // Consume the newline
69+
70+
for (Task task : taskList) {
71+
if (task.getId() == taskId) {
72+
task.setCompleted(true);
73+
System.out.println("Task marked as completed.");
74+
return;
75+
}
76+
}
77+
System.out.println("Task not found.");
78+
}
79+
80+
private static void removeTask(Scanner scanner) {
81+
System.out.print("Enter the task ID to remove: ");
82+
int taskId = scanner.nextInt();
83+
scanner.nextLine(); // Consume the newline
84+
85+
for (Task task : taskList) {
86+
if (task.getId() == taskId) {
87+
taskList.remove(task);
88+
System.out.println("Task removed.");
89+
return;
90+
}
91+
}
92+
System.out.println("Task not found.");
93+
}
94+
}
95+
96+
class Task {
97+
private int id;
98+
private String description;
99+
private boolean completed;
100+
101+
public Task(int id, String description) {
102+
this.id = id;
103+
this.description = description;
104+
this.completed = false;
105+
}
106+
107+
public int getId() {
108+
return id;
109+
}
110+
111+
public String getDescription() {
112+
return description;
113+
}
114+
115+
public boolean isCompleted() {
116+
return completed;
117+
}
118+
119+
public void setCompleted(boolean completed) {
120+
this.completed = completed;
121+
}
122+
123+
@Override
124+
public String toString() {
125+
return id + ". [" + (completed ? "X" : " ") + "] " + description;
126+
}
127+
}

0 commit comments

Comments
 (0)