-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.java
More file actions
60 lines (50 loc) · 1.62 KB
/
main.java
File metadata and controls
60 lines (50 loc) · 1.62 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
import java.util.Date;
public class TodoList {
// Class to represent a single Todo item with a description and a due date
class TodoItem {
String description;
Date dueDate;
public TodoItem(String description, Date dueDate) {
this.description = description;
this.dueDate = dueDate;
}
@Override
public String toString() {
return "Task: " + description + " | Due Date: " + dueDate;
}
}
// Array to store the Todo items
private TodoItem[] todoItems;
private int count;
// Constructor
public TodoList(int size) {
todoItems = new TodoItem[size];
count = 0;
}
// Method to add a Todo item
public void addTodoItem(String description) {
if (count < todoItems.length) {
todoItems[count] = new TodoItem(description);
count++;
} else {
System.out.println("Todo list is full!");
}
}
// Method to display all Todo items
public void displayTodoItems() {
for (int i = 0; i < count; i++) {
System.out.println(todoItems[i]);
}
}
public static void main(String[] args) {
// Create a TodoList object with space for 5 items
TodoList myTodoList = new TodoList(5);
System.out.println("Add-todo change");
System.out.println("This is add-date change");
// Add some todo items
myTodoList.addTodoItem("Finish Java assignment");
myTodoList.addTodoItem("Grocery shopping");
// Display all items
myTodoList.displayTodoItems();
}
}