-
Notifications
You must be signed in to change notification settings - Fork 591
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
[rithanisk] iP #628
base: master
Are you sure you want to change the base?
[rithanisk] iP #628
Changes from 36 commits
68c58c1
03523ec
81a9c53
cbdfbef
f5d0ce4
6337950
385c024
e0259a6
57d0f52
aaa66e6
88a4cc0
02ca5a8
8198949
942f9dd
c9cc960
ed638cd
d147984
85169c3
b82909a
372acbc
5ec62b2
1df07c6
371d156
7102fb8
d82a6df
6ac738f
ae44114
37590d3
4c846fd
031de66
23c3b7c
4c10cf4
14df377
afc1c44
87c6085
53225a6
2dd1625
22b2545
ac61409
364473c
5cc28dc
e0191a5
3de59c4
7986baa
42c8bb6
d966dfd
6d1e44f
1e8ac52
292415c
5b58896
8adff34
a727c43
ebeac23
0d87cc6
a81eaec
aa54427
907b121
a22041e
9656fdb
cdf8123
8be7a20
b5175de
6e1250c
3881d59
fe065fc
125b1fc
29e0933
9207521
a0edf47
d3bd7f7
f4d751c
1d59c3d
8c213cc
51b805f
bb48a6c
7d128d1
5e1033a
60c19a6
44cc1e0
b78f02b
d316c2c
907af5c
c9ff9e2
07e8a3d
a2bfd7e
4945fdb
cd33e2f
cb06003
cbc0da1
4b5ce1b
28fea11
a77f817
30e2ab3
eb5747a
50fee28
030fd98
96be4ec
313f97b
5f3747f
74a4e00
a7830a2
72bda1d
2604679
b79bf08
f92948d
2df5036
5ddc219
6803d36
06e8d99
9b68d4e
bb9e0e7
a7aae71
f409bd2
556523d
269c838
6e23335
32eba93
b5cb65e
cbaf565
243f1da
e4c31d9
d2218fb
3a9d438
af6adf7
d71f6fd
4157321
5e9dbed
b39d2aa
2fb065c
d8aaf7c
0dd1d21
6d8ccf5
a144c16
97e1e1b
8e43074
bf82caf
052aee3
940e0b6
cbbb28e
6b571cc
8f2e0aa
eb08763
d4a7a47
8d6cf46
2df71b8
6c09883
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
public class Deadline extends Task { | ||
/** | ||
* Constructs a Deadline task with the specified description and deadline | ||
* | ||
* @param description The description of the task provided by the user | ||
* @param deadline The deadline of the task provided by the user | ||
*/ | ||
private String deadline; | ||
public Deadline(String description, String deadline) { | ||
super(description); | ||
this.deadline = deadline; | ||
} | ||
|
||
/** | ||
* Returns a string representation of the Deadline object. | ||
* The string includes a "[D]" prefix to indicate that this is a Deadline task, | ||
* followed by the string representation provided by the Task superclass. | ||
* | ||
* @return A string in the format: "[D] <super.toString()>" | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "[D] " + super.toString() + "(by: " + this.deadline + ")"; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
public class Event extends Task { | ||
private String start; | ||
private String end; | ||
|
||
/** | ||
* Constructs an Event task with the specified description, start time, and end time | ||
* | ||
* @param description The description of the task provided by the user | ||
* @param start The start time of the task provided by the user | ||
* @param end The end time of the task provided by the user | ||
*/ | ||
public Event(String description, String start, String end) { | ||
super(description); | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
/** | ||
* Returns a string representation of the Event object. | ||
* The string includes a "[E]" prefix to indicate that this is an Event task, | ||
* followed by the string representation provided by the Task superclass. | ||
* | ||
* @return A string in the format: "[E] <super.toString()>" | ||
*/ | ||
@Override | ||
public String toString() { | ||
return "[E] " + super.toString() + " (from: " + start + " to: " + end + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
import java.util.Scanner; | ||
|
||
public class Nebula { | ||
/** | ||
* Entry point of the application. Initializes the UI, task list, and parser, | ||
* then processes user commands in a loop until "bye" is entered | ||
* | ||
* @param args command-line arguments (not used) | ||
*/ | ||
public static void main(String[] args) { | ||
Ui ui = new Ui(); | ||
TaskList taskList = new TaskList(); | ||
Parser parser = new Parser(); | ||
|
||
System.out.println(ui.greeting()); | ||
|
||
Scanner sc = new Scanner(System.in); | ||
while(sc.hasNext()) { | ||
String command = sc.nextLine(); | ||
|
||
if(command.equals("bye")) { | ||
System.out.println(ui.goodbye()); | ||
break; | ||
} | ||
|
||
else if(command.equals("list")) { | ||
System.out.println(ui.displayList()); | ||
} | ||
|
||
else if(command.startsWith("mark")) { | ||
try { | ||
validateCommand(command, taskList); | ||
} catch (NebulaException e) { | ||
System.out.println(e.getMessage()); | ||
continue; | ||
} | ||
int taskNum = parser.splitCommandAndTaskNumber(command); | ||
System.out.println(taskList.markTask(taskNum)); | ||
} | ||
|
||
else if(command.startsWith("unmark")) { | ||
try { | ||
validateCommand(command, taskList); | ||
} catch (NebulaException e) { | ||
System.out.println(e.getMessage()); | ||
continue; | ||
} | ||
int taskNum = parser.splitCommandAndTaskNumber(command); | ||
System.out.println(taskList.unmarkTask(taskNum)); | ||
} | ||
|
||
else if(command.startsWith("delete")) { | ||
try { | ||
validateCommand(command, taskList); | ||
} catch (NebulaException e) { | ||
System.out.println(e.getMessage()); | ||
continue; | ||
} | ||
int taskNum = parser.splitCommandAndTaskNumber(command); | ||
System.out.println(taskList.deleteTask(taskNum)); | ||
} | ||
|
||
else { | ||
try { | ||
validateCommand(command, taskList); | ||
} catch (NebulaException e) { | ||
System.out.println(e.getMessage()); | ||
continue; | ||
} | ||
|
||
TaskType taskType = parseTaskType(command); | ||
|
||
switch (taskType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good us of switch and case. But the indentation level of switch and case should be the same according to the coding standard that we adhere to. |
||
case TODO: | ||
String taskDescription = parser.splitCommandAndTaskDescription(command); | ||
Task newTodo = new Todo(taskDescription); | ||
String addedTodo = taskList.addTask(newTodo); | ||
System.out.println(addedTodo); | ||
break; | ||
|
||
case DEADLINE: | ||
String taskInformation = parser.splitCommandAndTaskDescription(command); | ||
String taskDescriptionDeadline = parser.splitDeadlineCommand(taskInformation)[0]; | ||
String taskDeadline = parser.splitDeadlineCommand(taskInformation)[1]; | ||
Task newDeadline = new Deadline(taskDescriptionDeadline, taskDeadline); | ||
String addedDeadline = taskList.addTask(newDeadline); | ||
System.out.println(addedDeadline); | ||
break; | ||
|
||
case EVENT: | ||
String taskInfo = parser.splitCommandAndTaskDescription(command); | ||
String taskDescriptionEvent = parser.splitEventCommand(taskInfo)[0]; | ||
String startInfo = parser.splitEventCommand(taskInfo)[1]; | ||
String endInfo = parser.splitEventCommand(taskInfo)[2]; | ||
|
||
String taskStart = parser.splitCommandAndTaskDescription(startInfo); | ||
String taskEnd = parser.splitCommandAndTaskDescription(endInfo); | ||
|
||
Task newEvent = new Event(taskDescriptionEvent, taskStart, taskEnd); | ||
String addedEvent = taskList.addTask(newEvent); | ||
System.out.println(addedEvent); | ||
break; | ||
|
||
case UNKNOWN: | ||
System.out.println("Unknown command type."); | ||
break; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
/** | ||
* Validates the user's input for the correct format and content | ||
* | ||
* @param command the user input command | ||
* @param taskList the current list of tasks | ||
* @throws NebulaException if the command is invalid or improperly formatted | ||
*/ | ||
public static void validateCommand(String command, TaskList taskList) throws NebulaException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used verb for method. Good. |
||
Parser parser = new Parser(); | ||
Ui ui = new Ui(); | ||
|
||
if (command.isEmpty()) { | ||
throw new NebulaException("Please enter a command!"); | ||
} else if (!(command.startsWith("todo") || command.startsWith("deadline") | ||
|| command.startsWith("event") || command.startsWith("mark") | ||
|| command.startsWith("unmark") || command.startsWith("delete") | ||
|| command.startsWith("list") || command.startsWith("bye"))) { | ||
throw new NebulaException(ui.displayUnknownCommandException()); | ||
} else if (command.startsWith("mark") || command.startsWith("unmark") || command.startsWith("delete")) { | ||
String[] parts = command.split(" ", 2); | ||
if (parts.length < 2 || parts[1].trim().isEmpty()) { | ||
throw new NebulaException(ui.displayUnknownTaskNumberException()); | ||
} | ||
try { | ||
int taskIndex = Integer.parseInt(parts[1].trim()) - 1; // Convert to 0-based index | ||
if (taskIndex < 0 || taskIndex >= TaskList.getTaskListLength()) { | ||
throw new NebulaException(ui.displayNonexistentTaskNumberException()); | ||
} | ||
} catch (NumberFormatException e) { | ||
throw new NebulaException(ui.displayUnknownTaskNumberException()); | ||
} | ||
} else { | ||
String[] parts = command.split(" ", 2); | ||
if (parts.length < 2 || parts[1].trim().isEmpty()) { | ||
throw new NebulaException(ui.displayUnknownMessageException()); | ||
} | ||
|
||
String description = parts[1].trim(); | ||
|
||
if (command.startsWith("deadline")) { | ||
if (!description.contains("/by")) { | ||
throw new NebulaException(ui.displayUnknownDeadlineException()); | ||
} | ||
} else if (command.startsWith("event")) { | ||
if (!description.contains("/from") || !description.contains("/to")) { | ||
throw new NebulaException(ui.displayUnknownEventTimingException()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Determines the TaskType based on the command prefix | ||
* | ||
* @param command the input command string | ||
* @return the corresponding TaskType, or unknown TaskType if unrecognized | ||
*/ | ||
public static TaskType parseTaskType(String command) { | ||
if (command.startsWith("todo")) { | ||
return TaskType.TODO; | ||
} else if (command.startsWith("deadline")) { | ||
return TaskType.DEADLINE; | ||
} else if (command.startsWith("event")) { | ||
return TaskType.EVENT; | ||
} else { | ||
return TaskType.UNKNOWN; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
public class NebulaException extends Exception { | ||
/** | ||
* Constructs a NebulaException with the specified error message | ||
* | ||
* @param error The String description of the error message | ||
*/ | ||
public NebulaException(String error) { | ||
super(error); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
public class Parser { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used noun for class. Good. |
||
/** | ||
* Splits the command string to extract the task number | ||
* | ||
* @param command The command string containing the command and task number | ||
* @return The task number as an integer | ||
*/ | ||
public int splitCommandAndTaskNumber(String command) { | ||
String taskNum = command.split(" ", 2)[1]; | ||
return Integer.parseInt(taskNum); | ||
} | ||
|
||
/** | ||
* | ||
* @param command The command string containing the command and task description | ||
* @return The task description as a String | ||
*/ | ||
public String splitCommandAndTaskDescription(String command) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good naming convention followed |
||
|
||
return command.split(" ", 2)[1]; | ||
} | ||
|
||
/** | ||
* | ||
* @param command The command string containing the command, task description, and deadline | ||
* @return The task deadline as a String | ||
*/ | ||
public String[] splitDeadlineCommand(String command) { | ||
|
||
return command.split("/by ", 2); | ||
} | ||
|
||
/** | ||
* | ||
* @param command The command string containing the command, task description, | ||
* event start time, and event end time | ||
* @return The event start and end time as a String | ||
*/ | ||
public String[] splitEventCommand(String command) { | ||
|
||
return command.split(" /", 3); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
public class Task { | ||
private final String description; | ||
private boolean isDone; | ||
|
||
/** | ||
* Constructs a Task with the specified description | ||
* The task is initialized with the given description and is marked as not done | ||
* | ||
* @param description The description of the task provided by the user | ||
*/ | ||
public Task (String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
/** | ||
* Returns the description of this task | ||
* | ||
* @return The description of the task | ||
*/ | ||
public String getDescription() { | ||
return this.description; | ||
} | ||
|
||
/** | ||
* Checks if the task has been completed | ||
* | ||
* @return true if the task is completed, false otherwise | ||
*/ | ||
public boolean isDone() { | ||
return this.isDone; | ||
} | ||
|
||
/** | ||
* Sets the completion status of the task | ||
* | ||
* @param isDone true to mark the task as completed, false to mark it as not completed | ||
*/ | ||
public void setDone(boolean isDone) { | ||
this.isDone = isDone; | ||
} | ||
|
||
/** | ||
* Returns the status icon representing the completion state of the task | ||
* Returns "X" if the task is completed, otherwise returns " " | ||
* | ||
* @return A string representing the status icon of the task | ||
*/ | ||
public String getStatusIcon() { | ||
return isDone ? "X" : " "; | ||
} | ||
|
||
/** | ||
* Returns a string representation of the object which includes the | ||
* status icon and the description of the object | ||
* | ||
* @return A string in the format: "[<statusIcon>] <description>" | ||
*/ | ||
public String toString() { | ||
return "[" + getStatusIcon() + "] " + getDescription(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good that you have included a javadoc for the modified toString() method even though it is not required to. According to coding standards maybe you could consider to remove the @return line and only provide additional details about your modification