Skip to content
Merged
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
116 changes: 116 additions & 0 deletions src/main/java/Lys.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
import java.util.*;
import java.io.*;

/**
* Represents a task with a description and completion status.
* This is an abstract class and should be extended by specific task types.
*/
abstract class Task {
protected String description;
protected boolean isDone;

/**
* Constructs a new Task with a description.
*
* @param description The task description.
*/
public Task(String description) {
this.description = description;
this.isDone = false;
}

/**
* Marks this task as completed.
*/
public void markAsDone() {
this.isDone = true;
}

/**
* Marks this task as not completed.
*/
public void unmarkAsDone() {
this.isDone = false;
}

/**
* Gets the type of the task as a string.
*
* @return Task type identifier.
*/
public abstract String getTaskType();

@Override
Expand All @@ -26,6 +46,9 @@ public String toString() {
}
}

/**
* Represents a basic ToDo task.
*/
class ToDo extends Task {
public ToDo(String description) {
super(description);
Expand All @@ -37,9 +60,18 @@ public String getTaskType() {
}
}

/**
* Represents a task with a deadline.
*/
class Deadline extends Task {
private String by;

/**
* Constructs a Deadline task.
*
* @param description The task description.
* @param by The due date/time of the task.
*/
public Deadline(String description, String by) {
super(description);
this.by = by;
Expand All @@ -56,10 +88,20 @@ public String toString() {
}
}

/**
* Represents an event task with a start and end time.
*/
class Event extends Task {
private String from;
private String to;

/**
* Constructs an Event task.
*
* @param description The task description.
* @param from The starting time.
* @param to The ending time.
*/
public Event(String description, String from, String to) {
super(description);
this.from = from;
Expand All @@ -77,35 +119,59 @@ public String toString() {
}
}

/**
* Handles user interface interactions.
*/
class Ui {
private Scanner scanner;

public Ui() {
scanner = new Scanner(System.in);
}

/**
* Reads a command from the user.
*
* @return The user input command.
*/
public String readCommand() {
return scanner.nextLine().trim();
}

/**
* Displays a line separator.
*/
public void showLine() {
System.out.println("____________________________________________________________");
}

/**
* Displays a message within formatted lines.
*
* @param message The message to be displayed.
*/
public void showMessage(String message) {
showLine();
System.out.println(message);
showLine();
}
}

/**
* Handles loading and saving tasks to a file.
*/
class Storage {
private String filePath;

public Storage(String filePath) {
this.filePath = filePath;
}

/**
* Loads tasks from the storage file.
*
* @return A list of task descriptions.
*/
public List<String> load() {
List<String> tasks = new ArrayList<>();
File file = new File(filePath);
Expand Down Expand Up @@ -145,23 +211,46 @@ public void save(List<Task> tasks) {
}
}

/**
* Parses user input commands.
*/
class Parser {
/**
* Splits input command into command word and arguments.
*
* @param input The full command string.
* @return An array containing the command and arguments.
*/
public static String[] parse(String input) {
return input.split(" ", 2);
}
}

/**
* Manages a list of tasks.
*/
class TaskList {
private List<Task> tasks;

public TaskList() {
this.tasks = new ArrayList<>();
}

/**
* Adds a task to the task list.
*
* @param task The task to be added.
*/
public void addTask(Task task) {
tasks.add(task);
}

/**
* Marks or unmarks a task as completed.
*
* @param index The index of the task in the list.
* @param isDone True to mark as done, false to unmark.
*/
public void markTask(int index, boolean isDone) {
if (isDone) {
tasks.get(index).markAsDone();
Expand All @@ -170,10 +259,18 @@ public void markTask(int index, boolean isDone) {
}
}

/**
* Deletes a task from the list.
*
* @param index The index of the task to delete.
*/
public void deleteTask(int index) {
tasks.remove(index);
}

/**
* Displays all tasks in the list.
*/
public void listTasks() {
if (tasks.isEmpty()) {
System.out.println("Your task list is empty.");
Expand All @@ -185,6 +282,9 @@ public void listTasks() {
}
}

/**
* Find a task with relevant words in the list.
*/
public void findTasks(String keyword) {
List<Task> matchingTasks = new ArrayList<>();
for (Task task : tasks) {
Expand All @@ -203,6 +303,11 @@ public void findTasks(String keyword) {
}
}

/**
* Retrieves the number of tasks in the list.
*
* @return The size of the task list.
*/
public int getSize() {
return tasks.size();
}
Expand All @@ -212,6 +317,9 @@ public List<Task> getTasks() {
}
}

/**
* Main class that runs the Lys chatbot.
*/
public class Lys {
private Ui ui;
private Storage storage;
Expand All @@ -236,6 +344,9 @@ public Lys() {
}
}

/**
* Runs the chatbot, handling user commands.
*/
public void run() {
ui.showMessage("Hello! I'm Lys.\nWhat can I do for you?");
boolean isRunning = true;
Expand Down Expand Up @@ -342,6 +453,11 @@ public void run() {
}
}

/**
* Entry point of the program.
*
* @param args Command line arguments.
*/
public static void main(String[] args) {
new Lys().run();
}
Expand Down