Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
90c8452
Level-0 Increment
DarkDragoon2002 Aug 22, 2024
6027a2d
Level-1
DarkDragoon2002 Aug 28, 2024
0d164dd
Level-2
DarkDragoon2002 Aug 28, 2024
dded6bf
Level-3
DarkDragoon2002 Aug 28, 2024
d0d0bda
A-CodingStandard
DarkDragoon2002 Aug 28, 2024
a43c3b2
Added ToDo, Deadline and Event
DarkDragoon2002 Sep 6, 2024
6a7f020
Added UI Text Testing
DarkDragoon2002 Sep 7, 2024
0d50273
Implemented Deadline and Event Constructor Exceptions
DarkDragoon2002 Sep 10, 2024
cb16bf3
Implemented ToDo Constructor Exceptions and Error Catching for chat c…
DarkDragoon2002 Sep 10, 2024
913e641
Implemented Packages
DarkDragoon2002 Sep 10, 2024
f0c0fab
Added Comments
DarkDragoon2002 Sep 12, 2024
36dbaff
Merge pull request #1 from DarkDragoon2002/branch-A-Packages
DarkDragoon2002 Sep 12, 2024
2d8b65a
Implemented ArrayList
DarkDragoon2002 Sep 19, 2024
5b59c6f
Implemented delete function & cleaned up code
DarkDragoon2002 Sep 19, 2024
c4ca544
Implemented Data Writing System
DarkDragoon2002 Sep 20, 2024
f0b78b9
Merge pull request #2 from DarkDragoon2002/branch-Level-6
DarkDragoon2002 Sep 20, 2024
0941170
Merge branch 'master' into branch-Level-7
DarkDragoon2002 Sep 20, 2024
9672976
Merge pull request #3 from DarkDragoon2002/branch-Level-7
DarkDragoon2002 Sep 20, 2024
2d5e67e
Bugfix and Created JAR file
DarkDragoon2002 Sep 20, 2024
c88fc8c
Migrated UI to separate Class
DarkDragoon2002 Oct 8, 2024
e2f954e
Migrate TaskList Functions from Task
DarkDragoon2002 Oct 9, 2024
1e844eb
Migrated Parser functions from Juan
DarkDragoon2002 Oct 9, 2024
44b8d55
Fixed Corrupted Data Handling
DarkDragoon2002 Oct 9, 2024
43e739f
Extracted Command Handling from Parser and Followed Good Coding Princ…
DarkDragoon2002 Oct 9, 2024
075bdcf
Merge pull request #4 from DarkDragoon2002/master
DarkDragoon2002 Oct 9, 2024
8eff0ee
Implemented DateTime feature and Updated Exception Handling
DarkDragoon2002 Oct 9, 2024
01d0c9d
Implement find function
DarkDragoon2002 Oct 9, 2024
cdf58d0
Merge pull request #5 from DarkDragoon2002/branch-Level-8
DarkDragoon2002 Oct 9, 2024
8d0bb25
Merge branch 'master' into branch-Level-9
DarkDragoon2002 Oct 9, 2024
4e5f9fa
Merge pull request #6 from DarkDragoon2002/branch-Level-9
DarkDragoon2002 Oct 9, 2024
2935ec3
Improved Code Quality
DarkDragoon2002 Oct 9, 2024
e439f74
Merge branch 'master' of https://github.com/DarkDragoon2002/ip
DarkDragoon2002 Oct 9, 2024
936c109
Updated UI-Text-Testing Files
DarkDragoon2002 Oct 9, 2024
42cbb2c
Updated JavaDoc Comments
DarkDragoon2002 Oct 9, 2024
364eab3
Merge pull request #7 from DarkDragoon2002/branch-A-JavaDoc
DarkDragoon2002 Oct 9, 2024
e64f9dc
Resolved Merge Conflicts
DarkDragoon2002 Oct 9, 2024
16bf1b5
Merge branch 'master' of https://github.com/DarkDragoon2002/ip
DarkDragoon2002 Oct 9, 2024
97be193
Updated README.md
DarkDragoon2002 Oct 10, 2024
45abc71
Update README.md
DarkDragoon2002 Oct 10, 2024
4175b23
Update README.md
DarkDragoon2002 Oct 10, 2024
98d3df5
Update README.md
DarkDragoon2002 Oct 10, 2024
246fbcb
Storage Bug Fix
DarkDragoon2002 Oct 10, 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
35 changes: 35 additions & 0 deletions src/main/java/CustomExceptions/DeadlineConstructorException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package CustomExceptions; // Package for custom exceptions
import TaskChildren.Task; // Import Task class to manage task deletion

// Custom exception class for handling errors in Deadline task construction
public class DeadlineConstructorException extends Exception {

// Constructor that takes an error message as input
public DeadlineConstructorException(String message) {
// Call the superclass (Exception) constructor with a detailed error message
super("DEADLINE CONSTRUCTOR EXCEPTION: " + errorMessage(message));

// If an error occurs, the latest task added is deleted to prevent invalid tasks
Task.deleteLatestTask();
}

// Private helper method to interpret the error message
// It checks for specific missing components in the deadline command
private static String errorMessage(String message) {
// Check if the "/by" keyword is missing, which is needed for deadline tasks
if (!(message.contains(" /by "))) {
return "MISSING BY COMMAND"; // Return specific error if "/by" is not found
}

// Split the task input string into task description and deadline parts
String[] taskStringBreakdown = message.replace("deadline ", "").split(" /by ");

// Check if the task description before "/by" is empty
if (taskStringBreakdown[0].isEmpty()) {
return "MISSING TASK STATEMENT"; // Return specific error if no task description
}

// If none of the specific errors match, return an unknown error
return "UNKNOWN ERROR";
}
}
43 changes: 43 additions & 0 deletions src/main/java/CustomExceptions/EventConstructorException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package CustomExceptions; // Package for custom exceptions
import TaskChildren.Task; // Import Task class to manage task deletion

// Custom exception class for handling errors in Event task construction
public class EventConstructorException extends Exception {

// Constructor that takes an error message as input
public EventConstructorException(String message) {
// Call the superclass (Exception) constructor with a detailed error message
super("EVENT CONSTRUCTOR EXCEPTION: " + errorMessage(message));

// If an error occurs, the latest task added is deleted to prevent invalid tasks
Task.deleteLatestTask();
}

// Private helper method to interpret the error message
// It checks for specific missing components in the event command
private static String errorMessage(String message) {
// Check if the "/from" and "/to" keywords are missing, which are needed for event tasks
if (!(message.contains(" /from ") || message.contains(" /to "))) {
return "MISSING FROM/TO COMMANDS"; // Return specific error if either "/from" or "/to" is missing
}

// Split the task input string into task description and the time period starting with "/from"
String[] taskStringBreakdown = message.replace("event ", "").split(" /from ");

// Check if the task description before "/from" is empty
if (taskStringBreakdown[0].isEmpty()) {
return "MISSING TASK STATEMENT"; // Return specific error if no task description is provided
}

// Further split the time period into "from" and "to" parts
String[] fromToStringBreakdown = taskStringBreakdown[1].split(" /to ");

// Check if both "from" and "to" components are present
if (fromToStringBreakdown.length != 2) {
return "MISSING FROM/TO DATES"; // Return specific error if either "from" or "to" date is missing
}

// If none of the specific errors match, return an unknown error
return "UNKNOWN ERROR";
}
}
31 changes: 31 additions & 0 deletions src/main/java/CustomExceptions/ToDoConstructorException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package CustomExceptions; // Package for custom exceptions
import TaskChildren.Task; // Import Task class to manage task deletion

// Custom exception class for handling errors in ToDo task construction
public class ToDoConstructorException extends Exception {

// Constructor that takes an error message as input
public ToDoConstructorException(String message) {
// Call the superclass (Exception) constructor with a detailed error message
super("TODO CONSTRUCTOR EXCEPTION: " + errorMessage(message));

// If an error occurs, the latest task added is deleted to prevent invalid tasks
Task.deleteLatestTask();
}

// Private helper method to interpret the error message
// It checks for specific missing components in the todo command
private static String errorMessage(String message) {

// Remove the "todo" keyword from the message to isolate the task statement
String taskString = message.replace("todo ", "");

// Check if the task statement is empty
if (taskString.isEmpty()) {
return "MISSING TASK STATEMENT"; // Return specific error if the task description is missing
}

// If none of the specific errors match, return an unknown error
return "UNKNOWN ERROR";
}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

139 changes: 139 additions & 0 deletions src/main/java/Juan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import CustomExceptions.*; // Import custom exception classes
import TaskChildren.*; // Import task-related classes like ToDo, Deadline, and Event

import java.util.Scanner; // Import Scanner for user input

public class Juan {
// Constant for common error message to improve code readability and reusability
private final static String porFavor = "Por Favor?\n";

// Main entry point for the application
public static void main(String[] args) {
// Display initial line and welcome message
lineMessage();
helloMessage();
lineMessage();

// Continue chatting as long as user doesn't exit
boolean continueChatting = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Boolean variables/methods should be named to sound like booleans.
The same error is present in other parts of the code.

while (continueChatting) {
// Chat feature to handle user input
continueChatting = chatFeature();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can consider extracting this part further to match same level of abstraction in this method.
E.g.

readData();
salary = basic * rise + 1000;
tax = (taxable ? salary * 0.07 : 0);
displayResult();

versus

readData();
processData();
displayResult();


// Display goodbye message when the chat ends
byeMessage();
lineMessage();
}

// Handles user input and executes corresponding actions
public static boolean chatFeature() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This method is very long, you can consider extracting the details for each case into separate methods. It will be better to keep each method short.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback just updated this! I extracted it into another class to make it easier to read


Scanner scanner = new Scanner(System.in); // Initialize the scanner for reading user input
String line = scanner.nextLine(); // Read user input
lineMessage(); // Print separator line

// Handle "bye" command to end chat
if (line.equals("bye")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

May the command words also be variables, for later use or easier management?

return false; // End the conversation
}
// Handle "list" command to display the list of tasks
else if (line.equals("list")) {
Task.printTasksList(); // Print task list from Task class
}
// Handle "mark" command to mark a task as completed
else if (line.startsWith("mark ")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Try to avoid magic literals(e.g. numbers, strings), you can consider using named constants instead. It will be useful especially when the particular literals are used multiple times in the code.
E.g.

static final double PI = 3.14236;
static final int MAX_SIZE = 10;
...
return PI;
...
return MAX_SIZE - 1;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback just updated this!

try {
int taskIndex = Integer.parseInt(line.replace("mark ", "")) - 1; // Parse the task index
Task.mark(taskIndex); // Mark the task as done
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
// Handle invalid index or format exceptions
System.out.println(porFavor + "MARK EXCEPTION: INVALID TASK INDEX");
} catch (NullPointerException e) {
// Handle null task case
System.out.println(porFavor + "MARK EXCEPTION: NULL TASK INDEX");
}
}
// Handle "unmark" command to unmark a task as completed
else if (line.startsWith("unmark ")) {
try {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Try to keep else if and closing curly bracket on the same line.
E.g.

if (condition) {
    statements;
} else if (condition) {
    statements;
} else {
    statements;
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the feedback just updated this!

int taskIndex = Integer.parseInt(line.replace("unmark ", "")) - 1; // Parse the task index
Task.unmark(taskIndex); // Unmark the task
} catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
// Handle invalid index or format exceptions
System.out.println(porFavor + "UNMARK EXCEPTION: INVALID TASK INDEX");
} catch (NullPointerException e) {
// Handle null task case
System.out.println(porFavor + "UNMARK EXCEPTION: NULL TASK INDEX");
}

}
// Handle "todo" command to create a new ToDo task
else if (line.startsWith("todo ")) {
try {
new ToDo(line); // Create a new ToDo object
} catch (ToDoConstructorException e) {
// Handle custom ToDo exception
System.out.println(porFavor + e.getMessage());
}
}
// Handle "deadline" command to create a new Deadline task
else if (line.startsWith("deadline ")) {
try {
new Deadline(line); // Create a new Deadline object
} catch (DeadlineConstructorException e) {
// Handle custom Deadline exception
System.out.println(porFavor + e.getMessage());
}
}
// Handle "event" command to create a new Event task
else if (line.startsWith("event ")) {
try {
new Event(line); // Create a new Event object
} catch (EventConstructorException e) {
// Handle custom Event exception
System.out.println(porFavor + e.getMessage());
}
}
// Default case for unrecognized commands
else {
System.out.println(porFavor + "UNRECOGNIZED REQUEST"); // Inform user about an unrecognized command
}

lineMessage(); // Print separator line
return true; // Continue conversation
}

// Utility function to print a separator line for clean output formatting
public static void lineMessage() {
String line = "____________________________________________________________\n";
System.out.print(line);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For the messages, should it be static variables instead and what the methods do is just printing it out?


// Displays a welcome message when the program starts
public static void helloMessage() {
String greeting =
" ._-'-_ .\n" +
" . ' /_-_-_\\ ` .\n" +
" .' |-_-_-_-| `.\n" +
" ( `.-_-_-.' )\n" +
" !`. .'!\n" +
" ! ` . . ' !\n" +
" ! ! ! ! ! ! ! ! !\n" +
" / / \\ \\\n" +
" _-| \\___ ___/ /-_\n" +
" (_ )__\\_)\\(_/__( _)\n" +
" ))))\\X\\ ((((\n" +
" \\/ \\/ \n" +
"Hola Amigo, I am Juan Cervantes Salamanca from Michoacan \n" +
"Welcome to la familia \n" +
"How can we help you? \n";
System.out.print(greeting); // Print the welcome message
}

// Displays a goodbye message when the program ends
public static void byeMessage() {
String bye = "Adios amigo, la familia will miss you\n";
System.out.print(bye); // Print the goodbye message
}
}
34 changes: 34 additions & 0 deletions src/main/java/TaskChildren/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package TaskChildren; // Package for Task-related classes

import CustomExceptions.DeadlineConstructorException; // Import custom exception for Deadline tasks

// Deadline class, a child class of Task, represents a task with a specific deadline
public class Deadline extends Task {

// Variable to store the deadline date/time string
private String deadlineString;

// Constructor for creating a Deadline task
public Deadline(String inputString) throws DeadlineConstructorException {
// Call the parent class (Task) constructor with the task description (before the "/by" keyword)
super(inputString.replace("deadline ", "").split(" /by ")[0]);

// Check if the "/by" keyword is missing or if the task description is empty
if (!(inputString.contains(" /by ")) || this.taskString.isEmpty()) {
throw new DeadlineConstructorException(inputString); // Throw custom exception if validation fails
}

// Extract the deadline portion of the input string (after the "/by" keyword)
this.deadlineString = inputString.replace("deadline ", "").split(" /by ")[1];

// Display a confirmation message when a Deadline task is successfully created
constructorMessage();
}

// Override the checkboxString method to include the "[D]" tag and the deadline information
@Override
public String checkboxString() {
// Call the parent method and add the "[D]" tag and deadline string to the checkbox format
return "[D]" + super.checkboxString() + " (by: " + deadlineString + ")";
}
}
44 changes: 44 additions & 0 deletions src/main/java/TaskChildren/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package TaskChildren; // Package for Task-related classes

import CustomExceptions.EventConstructorException; // Import custom exception for Event tasks

// Event class, a child class of Task, represents a task with a specific start and end time
public class Event extends Task {

// Variables to store the start and end times of the event
private String fromString;
private String toString;

// Constructor for creating an Event task
public Event(String inputString) throws EventConstructorException {
// Call the parent class (Task) constructor with the task description (before the "/from" keyword)
super(inputString.replace("event ", "").split(" /from ")[0]);

// Validate if both "/from" and "/to" keywords are present, and the task description is not empty
if (!(inputString.contains(" /from ") & inputString.contains(" /to ")) || this.taskString.isEmpty()) {
throw new EventConstructorException(inputString); // Throw custom exception if validation fails
}

// Split the input to extract the start and end times
String[] fromToStrings = inputString.replace("event ", "").split(" /from ")[1].split(" /to ");

// Check if both "from" and "to" times are provided
if (fromToStrings.length != 2) {
throw new EventConstructorException(inputString); // Throw custom exception if either is missing
}

// Set the from and to times for the event
this.fromString = fromToStrings[0];
this.toString = fromToStrings[1];

// Display a confirmation message when an Event task is successfully created
constructorMessage();
}

// Override the checkboxString method to include the "[E]" tag, start time, and end time
@Override
public String checkboxString() {
// Call the parent method and add the "[E]" tag along with the event's start and end times
return "[E]" + super.checkboxString() + " (from: " + fromString + " to: " + toString + ")";
}
}
Loading