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

[izruff] iP #626

Open
wants to merge 118 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
68c58c1
Add Gradle support
May 24, 2020
03523ec
Bump gradle and lib version
Eclipse-Dominator Aug 5, 2023
81a9c53
build.gradle: Prevent generating a second JAR file
aureliony Jul 16, 2024
edaa970
Rename main class
izruff Aug 21, 2024
2f4d559
Modify greeting message
izruff Aug 21, 2024
dd1abfc
Use code blocks for multi-line string
izruff Aug 21, 2024
5c2c821
Add exit message and modify greeting
izruff Aug 21, 2024
d83548d
Add echo feature
izruff Aug 21, 2024
bdecfd1
Create main loop for receiving user input
izruff Aug 21, 2024
729d3fd
Implement add task and list tasks
izruff Aug 21, 2024
5b35bb3
Add Task class
izruff Aug 21, 2024
e5cbbeb
Task.java: Add toString method
izruff Aug 21, 2024
857012c
Replace string-based tasks with Task instances
izruff Aug 21, 2024
c93d0cf
Add mark and unmark feature
izruff Aug 21, 2024
55e872b
Make Task abstract and improve code quality
izruff Aug 22, 2024
8a7b166
Add Todo, Deadline, and Event subclasses
izruff Aug 22, 2024
75cdc30
Add functionality to new task types
izruff Aug 24, 2024
7b2770c
Replace cat ASCII art
izruff Aug 24, 2024
d13673b
Add text UI testing
izruff Aug 24, 2024
b838af6
Add exception classes
izruff Aug 24, 2024
4fc5773
Add basic error handling
izruff Aug 25, 2024
972b076
Add delete task feature
izruff Aug 25, 2024
7b930d7
Update UI test to include delete
izruff Aug 27, 2024
2cfe70b
Update UI test to include examples of error handling
izruff Aug 27, 2024
40ac380
Add TaskList class
izruff Aug 31, 2024
833c3a6
Implement TaskList partially
izruff Aug 31, 2024
266b31a
Implement save to file with Storage class
izruff Aug 31, 2024
7cfde52
Add data folder to .gitignore
izruff Aug 31, 2024
67c4c4f
Implement Storage and save command on Mittens
izruff Aug 31, 2024
0351a2f
Implement Storage load on program start
izruff Sep 1, 2024
841b6b9
Merge branch 'branch-Level-7'
izruff Sep 1, 2024
5f638fc
Replace String date field on Deadline class with LocalDate
izruff Sep 4, 2024
f44fa76
Replace String date fields on Event class with LocalDate
izruff Sep 4, 2024
f601341
Merge branch 'branch-Level-8'
izruff Sep 4, 2024
790aea2
Add TextUi class
izruff Sep 5, 2024
d64de43
Add abstract Ui class to inherit TextUi
izruff Sep 5, 2024
100f96b
Add abstract Ui class to inherit TextUi
izruff Sep 5, 2024
6cecc3c
Add abstract Command class
izruff Sep 5, 2024
8d684da
Add StorageFileException class and handle errors in save and load met…
izruff Sep 5, 2024
0d99b06
Add InitializationException and handle possible errors
izruff Sep 5, 2024
696e9ba
Fix typo in showCommandCompletion
izruff Sep 5, 2024
5b91e9d
Refactor Mittens to use TaskList methods
izruff Sep 5, 2024
f843463
Rewrite Ui class and implement methods in TextUi
izruff Sep 5, 2024
9d36f62
Add command subclass for adding a new task
izruff Sep 5, 2024
f90170a
Partially implement Command and refactor Mittens
izruff Sep 5, 2024
a66297a
Make small changes for style consistency
izruff Sep 5, 2024
5454335
Overload showRegularMessage method for convenience
izruff Sep 5, 2024
42cb70c
Add command subclass for deleting a task
izruff Sep 5, 2024
18f66e6
Modify Command and its subclasses
izruff Sep 5, 2024
c66182d
Add command subclass for listing all tasks
izruff Sep 5, 2024
be8d194
Overload showRegularMessage with varargs
izruff Sep 5, 2024
39164a7
Add command subclasses for marking and unmarking a task
izruff Sep 5, 2024
9e8333d
Add command subclass for exiting the program
izruff Sep 5, 2024
f097245
Replace class methods in Mittens with use of Command instances
izruff Sep 5, 2024
22079d3
Add CommandParser class
izruff Sep 5, 2024
f6fb1bc
Implement CommandParser in Mittens
izruff Sep 5, 2024
8be896b
Refactor Mittens to utilize all other classes
izruff Sep 5, 2024
9c6640e
Merge branch 'branch-A-MoreOOP'
izruff Sep 5, 2024
0fe3fdc
Move all files to the mittens package
izruff Sep 5, 2024
eea6246
Move UI-related files to mittens.ui
izruff Sep 5, 2024
611e063
Add getter methods to Task and its subclasses
izruff Sep 5, 2024
5e7b078
Use getter methods instead of direct access to fields
izruff Sep 5, 2024
2fc2af5
Move task-related classes to mittens.task
izruff Sep 5, 2024
331666e
Move storage-related classes to mittens.storage
izruff Sep 5, 2024
3e55b1a
Move commands to mittens.commands
izruff Sep 5, 2024
3f45c68
Move parser-related classes to mittens.parser
izruff Sep 5, 2024
d272df3
Merge branch 'branch-A-Packages'
izruff Sep 5, 2024
a470a49
Merge branch 'add-gradle-support'
izruff Sep 5, 2024
0339cd4
Update name to Mittens
izruff Sep 6, 2024
507f25e
Add checkstyle plugin to Gradle
izruff Sep 6, 2024
10d0fe9
Write tests for CommandParser
izruff Sep 8, 2024
2da1cfd
Write tests for Storage
izruff Sep 8, 2024
ae4f677
Merge branch 'branch-A-JUnit'
izruff Sep 8, 2024
48add82
fix: Index off by 1 on delete, mark, and unmark commands
izruff Sep 11, 2024
23b66b6
fix: Remove extra newline from certain messages
izruff Sep 11, 2024
331651c
Add JavaDoc comments to Command and its subclasses
izruff Sep 20, 2024
c47210d
Add JavaDoc comments to Mittens class
izruff Sep 20, 2024
d88c6c2
Add JavaDoc comments to CommandParser and related classes
izruff Sep 20, 2024
fa54976
Add JavaDoc comments to exception classes
izruff Sep 20, 2024
1a98c3f
Add JavaDoc comments to Storage and related classes
izruff Sep 20, 2024
dbe4fba
Add JavaDoc comments to Task and TaskList
izruff Sep 20, 2024
15c92b5
Add JavaDoc comments to Ui and its subclasses
izruff Sep 20, 2024
88ff04d
Enforce explicit import statements
izruff Sep 20, 2024
240fd19
Auto-format code with Intellij code style
izruff Sep 20, 2024
2d252ab
Add find tasks by keyword functionality to TaskList
izruff Sep 20, 2024
5cd7674
Add FindCommand for finding tasks by given keyword
izruff Sep 20, 2024
95d14a3
Restore deleted part of message
izruff Sep 20, 2024
7e209a9
Fix typo
izruff Sep 20, 2024
a93b874
Update CommandParser to detect find commands
izruff Sep 20, 2024
cd0ffc2
Merge branch 'branch-A-JavaDoc'
izruff Sep 20, 2024
083c7c6
Merge branch 'branch-A-CodingStandard'
izruff Sep 20, 2024
8a9c0ef
Merge branch 'branch-Level-9'
izruff Sep 20, 2024
54339a5
Fix missing import statement
izruff Sep 20, 2024
2003c7d
Mittens.java: Refactor code and add method to load task list after in…
izruff Sep 22, 2024
9ce94a4
Update dependencies
izruff Sep 22, 2024
894d8b9
Implement JavaFxUi and refactor Ui class
izruff Sep 22, 2024
e604d36
Implement JavaFX GUI application
izruff Sep 22, 2024
9b28d4c
Remove redundant object
izruff Sep 22, 2024
6f25f39
Fix incorrect error message format
izruff Sep 22, 2024
340e6fe
Use PipedInputStream for user input processing
izruff Sep 23, 2024
f8596c1
Merge branch 'branch-Level-10'
izruff Sep 23, 2024
4dc21dc
Storage.java: Assert valid tasks types on save
izruff Sep 23, 2024
a931cdd
Mittens.java: Assert loaded task list not null
izruff Sep 23, 2024
94db3cf
Add RawCommandElements to represent command string
izruff Sep 23, 2024
0917c2b
Implement RawCommandElements in commands and parser
izruff Sep 23, 2024
07c74b9
Merge pull request #2 from izruff/branch-A-Assertions
izruff Sep 23, 2024
b20c07b
Merge branch 'master' into branch-A-CodeQuality
izruff Sep 23, 2024
5e8c468
Merge pull request #3 from izruff/branch-A-CodeQuality
izruff Sep 23, 2024
80f59aa
Fix unhandled out-of-bounds error
izruff Sep 23, 2024
53c9f07
Remove redundant constructors
izruff Sep 23, 2024
d12070e
Remove unused imports
izruff Sep 23, 2024
197289d
Remove unused method
izruff Sep 23, 2024
c3d4a54
Update Mittens error message
izruff Sep 23, 2024
e13dc97
Modify image size to fit more messages
izruff Sep 23, 2024
c15f4b5
Add UI screenshot for docs
izruff Sep 23, 2024
2bab46e
docs/README.md: Add product website
izruff Sep 23, 2024
ef88c69
Update product website
izruff Sep 23, 2024
32e0dbc
Fix Ui.png not showing on website
izruff Sep 24, 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
9 changes: 9 additions & 0 deletions src/main/java/BadInputException.java
Copy link

Choose a reason for hiding this comment

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

Good variable names

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class BadInputException extends MittensException {
Copy link

Choose a reason for hiding this comment

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

Perhaps you should have all files in a package?

private static final String MITTENS_MESSAGE = "Meow?! What does that mean?";
private static final String HELP_MESSAGE = "Type 'help' to see a list of commands," +
Copy link

Choose a reason for hiding this comment

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

Good naming of final variables and ensuring line length is consistent

" or 'help <command>' to see more about a specific command.";

public BadInputException(String message) {
super(message, MITTENS_MESSAGE, HELP_MESSAGE);
}
}
13 changes: 13 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Deadline extends Task {
Copy link

Choose a reason for hiding this comment

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

Would be great if you add a header comment for all public classes and methods

protected String by;

public Deadline(String description, String by) {
super(description);
this.by = by;
}

@Override
public String toString() {
return "[D]" + super.toString() + " (due " + this.by + ")";
}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

15 changes: 15 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Event extends Task {
protected String from;
protected String to;

public Event(String description, String from, String to) {
super(description);
this.from = from;
this.to = to;
}

@Override
public String toString() {
return "[E]" + super.toString() + " (" + this.from + " -- " + this.to + ")";
}
}
208 changes: 208 additions & 0 deletions src/main/java/Mittens.java
Copy link

Choose a reason for hiding this comment

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

Good variable names. Cute cat!

Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
import java.util.ArrayList;
import java.util.Scanner;

public class Mittens {

// Unfortunately we were unable to use the initial cat ASCII art due to the
// Unicode characters interfering with the UI tests.
private final static String GREETING_MESSAGE = """

/\\_/\\ ____________________
>^,^< / Hi, I'm Mittens! \\
/ \\ \\ I'm a cat! Meow :3 /
(___)_/ --------------------
""";

private final static String EXIT_MESSAGE = """

/\\_/\\ _____________
>^,^< ( Bye-bye! :3 )
/ \\ -------------
(___)_/
""";
Copy link

Choose a reason for hiding this comment

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

Modifiers should be given in this order private static final for consistency


private static ArrayList<Task> tasks = new ArrayList<>();

public static void greet() {
System.out.println(GREETING_MESSAGE);
}

public static void echo(String command) {
int len = command.length();
String message = """

/\\_/\\ %s
>^,^< ( %s )
/ \\ %s
(___)_/
""".formatted("_".repeat(len + 2),
command, "-".repeat(len + 2));

System.out.println(message);
}

public static void addTask(Task task) {
tasks.add(task);
System.out.printf("\nI've added \"%s\" to your list :3\n\n", task.getDescription());
}

public static void listTasks() {
if (tasks.size() == 0) {
System.out.println("\nMeow?! Your list is empty!\n");
return;
}
System.out.printf("\nYou have %d tasks in your list, here they are :3\n", tasks.size());
for (int i = 0; i < tasks.size(); i++) {
Task task = tasks.get(i);
System.out.printf("%d. %s\n", i + 1, task.toString());
}
System.out.print("\n");
}

public static void markTaskAsDone(int index) throws BadInputException {
if (index > tasks.size()) {
throw new BadInputException("Task index is out of range");
}
Task task = tasks.get(index - 1);
task.markAsDone();
System.out.printf("\nMeow, I scratched the check box for you:\n%s\n\n", task.toString());
}

public static void markTaskAsNotDone(int index) throws BadInputException {
if (index > tasks.size()) {
throw new BadInputException("Task index is out of range");
}
Task task = tasks.get(index - 1);
task.markAsNotDone();
System.out.printf("\nMeow, I unscratched the check box for you:\n%s\n\n", task.toString());
}

public static void deleteTask(int index) throws BadInputException {
if (index > tasks.size()) {
throw new BadInputException("Task index is out of range");
}
Task task = tasks.remove(index - 1);
System.out.printf("\nMeow, I deleted the task '%s' for you :3\n\n", task.getDescription());
}

public static void exit() {
System.out.println(EXIT_MESSAGE);
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

greet();

while (true) {
System.out.print("> ");
String input = scanner.nextLine();
Copy link

Choose a reason for hiding this comment

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

Would be great if you handled whitespaces after a command (e.g. "bye ") as well


try {
if (input.equals("bye")) {
break;
} else if (input.equals("list")) {
listTasks();
} else if (input.startsWith("mark")) {
try {
int index = Integer.parseInt(input.split(" ")[1]);
markTaskAsDone(index);
} catch (NumberFormatException e) {
throw new BadInputException("Argument for command 'mark' must be a number");
}
} else if (input.startsWith("unmark")) {
try {
int index = Integer.parseInt(input.split(" ")[1]);
markTaskAsNotDone(index);
} catch (NumberFormatException e) {
throw new BadInputException("Argument for command 'mark' must be a number");
}
} else if (input.startsWith("delete")) {
try {
int index = Integer.parseInt(input.split(" ")[1]);
deleteTask(index);
} catch (NumberFormatException e) {
throw new BadInputException("Argument for command 'delete' must be a number");
}
} else if (input.startsWith("todo")) {
String description = input.substring(5);

Todo newTodo = new Todo(description);
addTask(newTodo);
} else if (input.startsWith("deadline")) {
// Separate the inputs so that the first element contains the description while
// the rest contains flags.
String[] inputs = input.split(" /");
String description = inputs[0].substring(9);

String by = null;
for (int i = 1; i < inputs.length; i++) {
String[] flagWords = inputs[i].split(" ");
if (flagWords[0].equals("by")) {
if (by == null) {
by = inputs[i].substring(3);
} else {
throw new BadInputException("Found duplicate of 'by' flag");
}
} else {
throw new BadInputException("'%s' is not a known flag".formatted(flagWords[0]));
}
}

if (by == null) {
throw new BadInputException("Command 'deadline' must have a 'by' flag");
}

Deadline newDeadline = new Deadline(description, by);
addTask(newDeadline);
} else if (input.startsWith("event")) {
// Separate the inputs so that the first element contains the description while
// the rest contains flags.
String[] inputs = input.split(" /");
String description = inputs[0].substring(6);

String from = null;
String to = null;
for (int i = 1; i < inputs.length; i++) {
String[] flagWords = inputs[i].split(" ");
if (flagWords[0].equals("from")) {
if (from == null) {
from = inputs[i].substring(5);
} else {
throw new BadInputException("Found duplicate of 'from' flag");
}
} else if (flagWords[0].equals("to")) {
if (to == null) {
to = inputs[i].substring(3);
} else {
throw new BadInputException("Found duplicate of 'to' flag");
}
} else {
throw new BadInputException("'%s' is not a known flag".formatted(flagWords[0]));
}
}

if (from == null) {
throw new BadInputException("Command 'event' must have a 'from' flag");
}

if (to == null) {
throw new BadInputException("Command 'event' must have a 'to' flag");
}

Event newEvent = new Event(description, from, to);
addTask(newEvent);
} else {
throw new BadInputException("'%s' is not a known command".formatted(input));
}
} catch (MittensException e) {
e.echo();
} catch (Exception e) {
UnknownException newException = new UnknownException(e.getMessage());
newException.echo();
}
}

exit();
}
}
35 changes: 35 additions & 0 deletions src/main/java/MittensException.java
Copy link

Choose a reason for hiding this comment

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

Good variable names. Cute cat.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class MittensException extends Exception {
private final String mittensMessage;
private final String helpMessage;

public MittensException(String message, String mittensMessage, String helpMessage) {
super(message);
this.mittensMessage = mittensMessage;
this.helpMessage = helpMessage;
}

public String getMittensMessage() {
return this.mittensMessage;
}

public String getHelpMessage() {
return this.helpMessage;
}

public void echo() {
String message = """

/\\_/\\ %s
>x.x< ( %s )
/ \\ %s
(___)_/

Error: %s
%s
""".formatted("_".repeat(this.getMittensMessage().length() + 2),
this.getMittensMessage(), "-".repeat(this.getMittensMessage().length() + 2),
this.getMessage(), this.helpMessage);

System.out.println(message);
}
}
30 changes: 30 additions & 0 deletions src/main/java/Task.java
Copy link

Choose a reason for hiding this comment

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

Good use of boolean variable names

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
public abstract class Task {
protected String description;
protected boolean isDone;

public Task(String description) {
this.description = description;
this.isDone = false;
}

public String getDescription() {
return this.description;
}

public String getStatusIcon() {
return (this.isDone ? "X" : " ");
}

public void markAsDone() {
this.isDone = true;
}

public void markAsNotDone() {
this.isDone = false;
}

@Override
public String toString() {
return "[" + this.getStatusIcon() + "] " + this.description;
}
}
10 changes: 10 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Todo extends Task {
public Todo(String description) {
super(description);
}

@Override
public String toString() {
return "[T]" + super.toString();
}
}
9 changes: 9 additions & 0 deletions src/main/java/UnknownException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class UnknownException extends MittensException {
private static final String MITTENS_MESSAGE = "Meow?! Something went wrong...";
private static final String HELP_MESSAGE = "I'm not sure what went wrong. You can try again," +
" or type 'help' to see a list of commands.";

public UnknownException(String message) {
super(message, MITTENS_MESSAGE, HELP_MESSAGE);
}
}
Loading