Introduction
The Task Reminder Application in Java is a simple yet effective tool for managing tasks and setting reminders. The program allows users to create, view, and delete tasks, and it provides a notification when a task is due. This is an excellent project for beginners to get hands-on experience with basic Java programming concepts like arrays, loops, and date/time handling.
Objective
The objective of this project is to develop a task reminder application using Java. It will enable users to:
- Set tasks with due dates.
- View the list of tasks and their statuses.
- Delete completed tasks.
- Set reminders for tasks and get notified when the task is due.
Java Code for Task Reminder Application
import java.util.ArrayList; import java.util.Scanner; import java.util.Date; import java.text.SimpleDateFormat; class Task { String taskName; String dueDate; public Task(String taskName, String dueDate) { this.taskName = taskName; this.dueDate = dueDate; } @Override public String toString() { return "Task: " + taskName + ", Due Date: " + dueDate; } } public class TaskReminderApp { private static ArrayList taskList = new ArrayList<>(); private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { while (true) { displayMenu(); int choice = scanner.nextInt(); scanner.nextLine(); // consume the newline switch (choice) { case 1: addTask(); break; case 2: viewTasks(); break; case 3: deleteTask(); break; case 4: checkReminder(); break; case 5: System.out.println("Exiting the Task Reminder application. Goodbye!"); return; default: System.out.println("Invalid option, please try again."); } } } public static void displayMenu() { System.out.println("\nTask Reminder Application Menu"); System.out.println("1. Add a Task"); System.out.println("2. View Tasks"); System.out.println("3. Delete a Task"); System.out.println("4. Check Reminders"); System.out.println("5. Exit"); System.out.print("Choose an option: "); } public static void addTask() { System.out.print("Enter task name: "); String taskName = scanner.nextLine(); System.out.print("Enter due date (yyyy-MM-dd): "); String dueDate = scanner.nextLine(); taskList.add(new Task(taskName, dueDate)); System.out.println("Task added successfully!"); } public static void viewTasks() { if (taskList.isEmpty()) { System.out.println("No tasks available."); } else { System.out.println("\nCurrent Tasks:"); for (Task task : taskList) { System.out.println(task); } } } public static void deleteTask() { System.out.print("Enter task name to delete: "); String taskName = scanner.nextLine(); boolean taskFound = false; for (Task task : taskList) { if (task.taskName.equalsIgnoreCase(taskName)) { taskList.remove(task); System.out.println("Task deleted successfully!"); taskFound = true; break; } } if (!taskFound) { System.out.println("Task not found."); } } public static void checkReminder() { String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); boolean reminderFound = false; for (Task task : taskList) { if (task.dueDate.equals(currentDate)) { System.out.println("Reminder: " + task); reminderFound = true; } } if (!reminderFound) { System.out.println("No tasks are due today."); } } }
Explanation of the Program Structure
The program has a simple structure consisting of the following parts:
- Task Class: This represents a task with two attributes: the task’s name and its due date.
- TaskReminderApp Class: This is the main class where the application logic resides. It contains methods to display the menu, add tasks, view tasks, delete tasks, and check for reminders.
- Scanner: It is used to take user input from the console.
- ArrayList: It stores the list of tasks created by the user.
- SimpleDateFormat: It is used to format the current date and compare it with the task due dates.
How to Run the Program
Follow these steps to run the Task Reminder application:
-
- Install Java Development Kit (JDK) on your system if it’s not already installed.
- Save the code in a file named
TaskReminderApp.java
. - Open a terminal or command prompt, navigate to the directory containing the file, and compile the program by running the following command:
javac TaskReminderApp.java
-
- Run the program with the following command:
java TaskReminderApp
- The program will start, and you can interact with the menu to manage tasks and set reminders.