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

[ZiliaAJY] iP #26

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1e4f606
Add rename, greet, exit features
ZiliaAJY Aug 19, 2024
572029a
Add rename, greet, exit features
ZiliaAJY Aug 22, 2024
c55d4cc
Add 'Echo', 'Add, List', 'Mark as Done' features, and Task class
ZiliaAJY Aug 28, 2024
13abd01
Align code with Java coding standards
ZiliaAJY Aug 28, 2024
c66bb95
Add Todo, Event, and Deadline features
ZiliaAJY Aug 31, 2024
b039dc1
Refactor code and update names; add JavaDoc comments
ZiliaAJY Aug 31, 2024
b211e72
Update input.txt and expected.txt for testing scenarios
ZiliaAJY Sep 4, 2024
533b98c
Update comments and remove typos
ZiliaAJY Sep 4, 2024
b2210b3
Add "CongloException.java" file
ZiliaAJY Sep 7, 2024
f6fab3f
Add and Refactor Exception handling
ZiliaAJY Sep 7, 2024
3d681c7
Merge branch 'branch-Level-5'
ZiliaAJY Sep 7, 2024
5ef469c
Update JavaDoc comments to include exception details
ZiliaAJY Sep 7, 2024
aed0ccc
Add "QuickManual.java" file to print instructions manual
ZiliaAJY Sep 7, 2024
b0c3f13
Organize classes into packages and update Conglo.java to use them
ZiliaAJY Sep 7, 2024
7fc6aa2
Merge branch 'branch-A-Packages'
ZiliaAJY Sep 7, 2024
78f99e1
Implement automatic task saving and loading from disk
ZiliaAJY Sep 13, 2024
f1916e6
Replace arrays with ArrayLists and add task deletion
ZiliaAJY Sep 13, 2024
7106d51
Merge branch 'branch-Level-6'
ZiliaAJY Sep 13, 2024
b43d56d
Resolved merge conflicts between branch-Level-6 and branch-Level-7
ZiliaAJY Sep 13, 2024
209eed1
Fix runtest.bat; update input/expected files; handle "list" exception
ZiliaAJY Sep 16, 2024
a9541f7
Fix symbol display
ZiliaAJY Sep 16, 2024
8348d78
Implement automatic task saving and loading from disk
ZiliaAJY Sep 13, 2024
980a0bc
Resolved merge conflict between master and branch-Level-7
ZiliaAJY Sep 17, 2024
b9935e3
Merge branch 'branch-Level-7'
ZiliaAJY Sep 17, 2024
6cad730
Extract code into Ui, Storage, Parser, and TaskList classes
ZiliaAJY Sep 28, 2024
fd417a5
Clean up typos
ZiliaAJY Sep 28, 2024
791c952
Refactor extracted classes
ZiliaAJY Sep 28, 2024
263e667
Implement date parsing for Deadlines
ZiliaAJY Sep 28, 2024
14f52ce
Implement Task Search Feature
ZiliaAJY Sep 28, 2024
ff9aaa2
Add Javadoc comments to all classes and methods for comprehensive doc…
ZiliaAJY Sep 29, 2024
afe81f6
Merge pull request #1 from ZiliaAJY/branch-Level-8
ZiliaAJY Sep 29, 2024
67f9aff
Resolved merge conflicts with master
ZiliaAJY Sep 29, 2024
ed72fa4
Resolved merge conflicts with master
ZiliaAJY Sep 29, 2024
9aa2d97
Merge pull request #2 from ZiliaAJY/branch-Level-9
ZiliaAJY Sep 29, 2024
b5b403f
Resolved merge conflicts with master
ZiliaAJY Sep 29, 2024
aee9480
Merge pull request #3 from ZiliaAJY/branch-A-JavaDoc
ZiliaAJY Sep 29, 2024
19d3c30
Update test case to include 'Date' and 'Find' features
ZiliaAJY Sep 29, 2024
146b65e
Update README.md: Add features, commands, prerequisites, and setup in…
ZiliaAJY Oct 1, 2024
ad59a07
Clean up code formatting and update comments for clarity
ZiliaAJY Oct 3, 2024
ea67181
Refactor code and update comments for clarity
ZiliaAJY Oct 3, 2024
bc9fe9d
Merge branch 'master' of https://github.com/ZiliaAJY/ip
ZiliaAJY Oct 3, 2024
ac0e563
Add method to create file if it does not exist
ZiliaAJY Oct 11, 2024
4dfee35
Fix parsing int bug in mark task
ZiliaAJY Oct 11, 2024
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
5 changes: 5 additions & 0 deletions data/conglo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
T | ✓ | run
E | ✗ | sleep | from 3am to 10pm
D | ✗ | slides | by mon
D | ✓ | eat | by 8pm
E | ✗ | cs2113 lecture | from Fri 4pm to 6pm
Binary file added src/main/java/Conglo.class
Binary file not shown.
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: conglo.Conglo

253 changes: 253 additions & 0 deletions src/main/java/conglo/Conglo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
package conglo;

import conglo.manual.*;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use wildcard imports

import conglo.task.*;
import conglo.exception.*;
import conglo.storage.*;

import java.util.ArrayList;
import java.util.Scanner;

/**
* Conglo is a command-line task management application that allows users to
* add tasks, mark tasks as done or not done, and list tasks. The tasks can
* include ToDos, Events, and Deadlines.
*/
public class Conglo {

// Constants
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant comment

protected static final String LINE_SEPARATOR = "-------------------------------------";

// Class variables
protected static String command;
private static final ArrayList<Task> taskList = TaskStorage.loadTasks();
protected static boolean isDelete = false;

/**
* The main method that starts the Conglo application. It handles user input
* and processes commands until the user types "bye".
*
* @param args Command-line arguments (not used).
*/
public static void main(String[] args) {
greetUser();
Scanner scanner = new Scanner(System.in);
command = scanner.nextLine();
while (!command.equals("bye")) {
try {
processCommand(command);
} catch (CongloException e) {
System.out.println(e.getMessage());
}
printLineSeparator();
command = scanner.nextLine();
}
scanner.close();
sayGoodbye();
}

/**
* Prints a line separator to the console.
*/
public static void printLineSeparator() {
System.out.println(LINE_SEPARATOR);
}

private static void saveTasks() {
TaskStorage.saveTasks(taskList);
}

/**
* Greets the user when the application starts.
*/
public static void greetUser() {
printLineSeparator();
System.out.println("Hola! I'm Conglo, the friendly task manager.");
printLineSeparator();
QuickManual.printManual();
printLineSeparator();
listTasks();
printLineSeparator();
}

/**
* Echoes the details of the newly added task and the current task count.
*
* @param task The task to be echoed.
*/
public static void echoTask(Task task) {
int size = taskList.size();
if (isDelete) {
System.out.println("Okie! Task is removed from list:");
size--;
} else {
System.out.println("All done! Task added to list:");
}
String taskSuffix = size > 1 ? " tasks" : " task";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could consider making this "easy to read" by using explicit if ... else block.

System.out.println(" " + task.toFileFormat());
System.out.println("The list has " + size + taskSuffix + " now.");
}

/**
* Lists all the tasks currently in the task list.
*/
public static void listTasks() {
if (taskList.isEmpty()) {
System.out.println("The list is empty!");
}
for (int i = 0; i < taskList.size(); i++) {
System.out.println((i + 1) + ". " + taskList.get(i).toFileFormat());
}
}

/**
* Marks a task as done or not done based on the user command.
*
* @param words The split command words where the first word is "mark" or "unmark".
* @throws CongloException.InvalidTaskNumber If the task number is invalid or out of range.
*/
public static void markTask(String[] words) throws CongloException.InvalidTaskNumber {
int i;
try {
i = Integer.parseInt(words[1].substring(0, 1)) - 1;
} catch (NumberFormatException e) {
System.out.println("Invalid format! Please provide a task number >.<");
return;
}

if (i >= taskList.size() || i < 0) {
throw new CongloException.InvalidTaskNumber();
}
if (words[0].equals("mark")) {
taskList.get(i).markAsDone();
System.out.println("Nice! I've marked this task as done:");
} else {
taskList.get(i).markAsNotDone();
System.out.println("OK, I've marked this task as not done yet:");
}
System.out.println(taskList.get(i).toFileFormat());
}

/**
* Adds a todo task to the task list.
*
* @param sentence The command containing the task description.
*/
public static void addTodo(String sentence) {
Todo todo = new Todo(sentence);
taskList.add(todo);
echoTask(todo);
saveTasks();
}

/**
* Adds a deadline task to the task list.
*
* @param sentence The command containing the task description and deadline.
* @throws CongloException.InvalidFormat If the deadline format is incorrect.
*/
public static void addDeadline(String sentence) throws CongloException.InvalidFormat {
if (!sentence.contains(" /by ")) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can try improving SLAP in such cases

throw new CongloException.InvalidFormat("deadline");
}
String[] words = sentence.split(" /by ");
Deadline deadline = new Deadline(words[0], words[1]);
taskList.add(deadline);
echoTask(deadline);
saveTasks();
}

/**
* Adds an event task to the task list.
*
* @param sentence The command containing the task description, start, and end times.
* @throws CongloException.InvalidFormat If the event format is incorrect.
*/
public static void addEvent(String sentence) throws CongloException.InvalidFormat {
if (!sentence.contains(" /from ") || !sentence.contains(" /to ")) {
throw new CongloException.InvalidFormat("event");
}
String[] words = sentence.split(" /from | /to ");
Event event = new Event(words[0], words[1], words[2]);
taskList.add(event);
echoTask(event);
saveTasks();
}

public static void deleteTask(String word) throws CongloException.InvalidTaskNumber {
int i;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a more descriptive variable name.

try {
i = Integer.parseInt(word) - 1;
} catch (NumberFormatException e) {
System.out.println("Invalid format! Please provide a task number >.<");
return;
}
if (i >= taskList.size() || i < 0) {
throw new CongloException.InvalidTaskNumber();
}
isDelete = true;
echoTask(taskList.get(i));
taskList.remove(i);
isDelete = false;
saveTasks();
}

/**
* Processes the user's command and invokes the corresponding action.
*
* @param command The full command entered by the user.
* @throws CongloException If the command is invalid or an error occurs while processing.
*/
public static void processCommand(String command) throws CongloException {
String[] words = command.split(" ", 2);
switch(words[0]) {
case "list":
if (words.length > 1) {
throw new CongloException.InvalidFormat("list");
}
listTasks();
break;
case "unmark":
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fall through comment is needed

case "mark":
if (words.length == 1 || words[1].isEmpty()) {
throw new CongloException.MissingTaskNumber(words[0]);
}
markTask(words);
break;
case "delete":
if (words.length == 1 || words[1].isEmpty()) {
throw new CongloException.MissingTaskNumber(words[0]);
}
deleteTask(words[1]);
break;
case "todo":
if (words.length == 1 || words[1].isEmpty()) {
throw new CongloException.MissingDescription("Todo");
}
addTodo(words[1]);
break;
case "deadline":
if (words.length == 1 || words[1].isEmpty()) {
throw new CongloException.MissingDescription("deadline");
}
addDeadline(words[1]);
break;
case "event":
if (words.length == 1 || words[1].isEmpty()) {
throw new CongloException.MissingDescription("event");
}
addEvent(words[1]);
break;
default:
throw new CongloException.UnknownCommand();
}
}

/**
* Prints a goodbye message when the user exits the application.
*/
public static void sayGoodbye() {
System.out.println("Goodbye. See you next time!");
printLineSeparator();
}
}
59 changes: 59 additions & 0 deletions src/main/java/conglo/exception/CongloException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package conglo.exception;

public class CongloException extends Exception {

public CongloException(String message) {
super(message);
}

// Custom exception for unknown commands
public static class UnknownCommand extends CongloException {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider making these separate classes rather than nested classes

public UnknownCommand() {
super("Sorry, I'm not smart enough to understand what you mean.");
}
}

// Custom exception for missing description
public static class MissingDescription extends CongloException {
public MissingDescription(String type) {
super("Oopsies, please add a description of " + type + ".");
}
}

// Custom exception for invalid task number
public static class InvalidTaskNumber extends CongloException {
public InvalidTaskNumber() {
super("Invalid task number! Please try again.");
}
}

// Custom exception for missing task number
public static class MissingTaskNumber extends CongloException {
public MissingTaskNumber(String action) {
super("Please provide task number to " + action + ".");
}
}

// Custom exception for invalid input format
public static class InvalidFormat extends CongloException {
public InvalidFormat(String type) {
super(generateMessage(type));
}

private static String generateMessage(String type) {
switch (type) {
case "list":
return "Do you mean 'list'?";
case "deadline":
return "Oh dear, your deadline command is a bit off."
+ System.lineSeparator() + "Please use: deadline [description] /by [deadline].";
case "event":
return "Oh no! Your event command needs a bit of tweaking."
+ System.lineSeparator() + "Try: event [description] /from [start time] /to [end time].";
default:
return "Oops! Looks like there's a hiccup in your command."
+ System.lineSeparator() + "Please follow the correct format.";
}
}
}
}
19 changes: 19 additions & 0 deletions src/main/java/conglo/manual/QuickManual.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package conglo.manual;

public class QuickManual {

/**
* Prints a quick manual of instructions for the Conglo application.
*/
public static void printManual() {
System.out.println("Here's a quick manual to get you started:");
System.out.println("1. Add a todo: todo [description]");
System.out.println("2. Add a deadline: deadline [description] /by [deadline]");
System.out.println("3. Add an event: event [description] /from [start time] /to [end time]");
System.out.println("4. Mark a task as done: mark [task number]");
System.out.println("5. Unmark a task: unmark [task number]");
System.out.println("6. Delete a task: delete [task number]");
System.out.println("7. List all tasks: list");
System.out.println("8. Exit the application: bye");
}
}
Loading