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

sarjinius iP #474

Open
wants to merge 59 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
55f9f9f
docs/README.md: Tweak document template
Jan 7, 2024
f837ddb
Add Gradle support
May 24, 2020
a6f7324
Bump gradle and lib version
Eclipse-Dominator Aug 5, 2023
4fda194
Greets the user
sarjinius Jan 26, 2024
30db664
Exits with goodbye message
sarjinius Jan 26, 2024
5b2458d
Adds horizontal lines
sarjinius Jan 26, 2024
a4fbab2
Adds echo method
sarjinius Jan 26, 2024
dff389f
Echoes commands until bye is input.
sarjinius Jan 26, 2024
7f84653
Adds indentations
sarjinius Jan 26, 2024
bdb8f27
Renames command to task, creates a task list, modifies echo method to…
sarjinius Jan 26, 2024
1f1e2b1
Adds method that prints task list
sarjinius Jan 26, 2024
c3c9722
Creates a new Task class
sarjinius Jan 27, 2024
7458497
Adds mark, unmark, and toString methods to Task class
sarjinius Jan 27, 2024
1bfce71
Adds isCommandBye, isCommandList, and getTask methods.
sarjinius Jan 27, 2024
1d5af97
Adds isCommandMark, isCommandUnmark, and getIndex methods.
sarjinius Jan 27, 2024
3057eee
Adds markTaskAsDone and markTaskAsNotDone methods
sarjinius Jan 27, 2024
dbd50a2
Adds classes Todo, Deadline and Event that extend the Task class.
sarjinius Jan 29, 2024
b565b98
Adds isCommandTodo, isCommandDeadline, isCommandEvent, and numTasks m…
sarjinius Jan 29, 2024
0178d19
Adds methods that gets the fields to be used in the Todo, Deadline, a…
sarjinius Jan 29, 2024
08d5140
Replaces addTask method with addTodo, addDeadline, addEvent methods, …
sarjinius Jan 29, 2024
c70784b
Updates input and expected scripts for automated testing
sarjinius Jan 30, 2024
8e8f791
Handles empty description errors and unknown command errors
sarjinius Jan 31, 2024
2d54ec1
Adds support for deleting tasks from the list.
sarjinius Jan 31, 2024
da1e33c
Uses Enums for Command Types and moves different classes to new files
sarjinius Feb 11, 2024
f774215
Moves methods from Virtue class to other classes
sarjinius Feb 11, 2024
8ef4a63
Initializes task list from hard drive when chatbot starts up.
sarjinius Feb 12, 2024
5ff1d0b
Writes task list into file after list is modified.
sarjinius Feb 12, 2024
b012664
Merge branch 'branch-Level-7'
sarjinius Feb 12, 2024
4e82e16
Adds ability for chatbot to understand dates and times.
sarjinius Feb 13, 2024
c03eaf8
Merge branch 'branch-Level-8'
sarjinius Feb 13, 2024
e89cfd2
Code refactored to add more OOP
sarjinius Feb 13, 2024
85c0262
Merge branch 'add-gradle-support'
sarjinius Feb 13, 2024
a36cee0
Can run the chatbot using Gradle
sarjinius Feb 14, 2024
9169b79
TodoTest.java cannot import Todo class
sarjinius Feb 14, 2024
beebe61
Added testing ability for Todo and VirtueTaskList classes.
sarjinius Feb 14, 2024
36260c6
Changes .jar name created to virtue.jar
sarjinius Feb 14, 2024
9839681
Added JavaDoc to most classes and methods
sarjinius Feb 15, 2024
341de20
Code modified to follow the coding standard
sarjinius Feb 15, 2024
7d86535
JavaDoc modified to follow coding standard
sarjinius Feb 15, 2024
17640c9
Adds a find method that can filter the task list by a keyword.
sarjinius Feb 15, 2024
23bc68a
Merge branch 'branch-Level-9'
sarjinius Feb 15, 2024
2936133
Merge branch 'branch-A-JavaDoc'
sarjinius Feb 15, 2024
462fa52
Merge branch 'branch-A-CodingStandard'
sarjinius Feb 15, 2024
2740425
Finds coding style violations and resolves them
sarjinius Feb 16, 2024
0b48734
Merge branch 'branch-A-CheckStyle'
sarjinius Feb 16, 2024
95de22d
Incorporates a GUI into the chatbot.
sarjinius Feb 20, 2024
819a874
Merge branch 'branch-Level-10'
sarjinius Feb 20, 2024
bf1cf6f
Adds assert checks to the code
sarjinius Feb 24, 2024
86214c2
Refactors the code to improve code quality.
sarjinius Feb 24, 2024
347f5f9
Merge pull request #2 from sarjinius/branch-A-Assertions
sarjinius Feb 25, 2024
8036d65
Merge branch 'master' into branch-A-CodeQuality
sarjinius Feb 25, 2024
3f42a80
Merge pull request #3 from sarjinius/branch-A-CodeQuality
sarjinius Feb 25, 2024
19a8b03
Merge branch 'master' of https://github.com/sarjinius/ip
sarjinius Feb 25, 2024
7ab0a1c
Provide a way to perform commands on multiple tasks
sarjinius Feb 26, 2024
f311cf5
Merge branch 'branch-C-MassOps'
sarjinius Feb 26, 2024
6688e6e
Give credit for reused work
sarjinius Feb 26, 2024
2d3f605
Add a representative screenshot to the docs folder
sarjinius Feb 26, 2024
5d9d7fd
Add a brief user guide
sarjinius Feb 26, 2024
6b00519
Provide appropriate messages to invalid inputs
sarjinius Mar 6, 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
3 changes: 3 additions & 0 deletions data/virtue.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
T | 0 | Finish Assignment
D | 0 | Prepare Gift | Feb 22nd
E | 1 | Spend time | Feb 12 | Feb 14
135 changes: 135 additions & 0 deletions src/main/Duke/virtue/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package virtue;

public class Command {
// The available types of commands in Virtue.
public enum CommandType {

Choose a reason for hiding this comment

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

Using an enum to define CommandType was a good idea, since it groups together related constants, and makes the code more readable

BYE ("bye", false, false),
LIST ("list", false, false),
MARK ("mark", true, false),
UNMARK ("unmark", true, false),
TODO ("todo", false, true),
DEADLINE ("deadline", false, true),
EVENT ("event", false, true),
DELETE("delete", true, false);

private final String string;
private final boolean hasIndex;
private final boolean hasDescription;

CommandType(String string,
boolean hasIndex,
boolean hasDescription) {
this.string = string;
this.hasIndex = hasIndex;
this.hasDescription = hasDescription;
}

@Override
public String toString() {
return this.string;
}
}

private String command;
protected CommandType type;
protected int index;
protected String description;
protected String by;
protected String from;
protected String to;

public Command(String command) throws VirtueException {

Choose a reason for hiding this comment

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

having javadoc comments here will help with understanding of the code

this.command = command;
this.type = getCommandType();

if (this.type.hasIndex) {
this.index = getIndex();
}

if (this.type.hasDescription) {
this.description = getDescription();
}

if (this.type == CommandType.DEADLINE) {
this.by = getBy();
}

if (this.type == CommandType.EVENT) {
this.from = getFrom();
this.to = getTo();
}
}

// Gets the type of the command, which is its first word.
private CommandType getCommandType() throws UnknownCommandTypeException {
String firstWord = command.split(" ", 2)[0];

for (CommandType type : CommandType.values()) {
if (firstWord.equals(type.toString())) {
return type;
}
}

throw new UnknownCommandTypeException();

Choose a reason for hiding this comment

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

using specific exceptions makes error handling more precise and helps with debugging

}

// Gets the index input by the user for a mark/unmark/delete command.
private int getIndex() throws EmptyIndexException, IndexFormatException {
try {
return Integer.parseInt(command.split(" ", 2)[1]);
} catch (ArrayIndexOutOfBoundsException e) {
throw new EmptyIndexException(type.toString());
} catch (NumberFormatException e) {
throw new IndexFormatException(type.toString());
}
}

// Gets the description for a todo/deadline/event command.
private String getDescription() throws EmptyDescriptionException {
String description;
String firstWordRemoved;

try {
firstWordRemoved = command.split(" ", 2)[1];
} catch (ArrayIndexOutOfBoundsException e) {
throw new EmptyDescriptionException(type.toString());
}

switch (type) {
case DEADLINE:
description = firstWordRemoved.split("/by", 2)[0];
break;
case EVENT:
description = firstWordRemoved.split(" /from ", 2)[0];
break;
default: // case TODO
description = firstWordRemoved;
}

return description;
}

// Gets the deadline for a deadline command.
private String getBy() {
String firstWordRemoved = command.split(" ", 2)[1];
return firstWordRemoved.split(" /by ", 2)[1];
}

// Gets the start for a deadline command.
private String getFrom() {
String firstWordRemoved = command.split(" ", 2)[1];
String fromAndTo = firstWordRemoved.split(" /from ", 2)[1];
return fromAndTo.split(" /to ", 2)[0];
}

// Gets the end for a deadline command.
private String getTo() {
String firstWordRemoved = command.split(" ", 2)[1];
String fromAndTo = firstWordRemoved.split(" /from ", 2)[1];
return fromAndTo.split(" /to ", 2)[1];
}

public boolean isBye() {
return type == CommandType.BYE;
}
}
20 changes: 20 additions & 0 deletions src/main/Duke/virtue/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package virtue;

public class Deadline extends VirtueTask {
private String by;

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

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + this.by + ")";
}

@Override
public String fileFormat() {
return "D | " + super.fileFormat() + " | " + by;
}
}
7 changes: 7 additions & 0 deletions src/main/Duke/virtue/EmptyDescriptionException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package virtue;

public class EmptyDescriptionException extends VirtueException {
public EmptyDescriptionException(String type) {
super("OOPS!!! The description of a " + type + " cannot be empty.");
}
}
7 changes: 7 additions & 0 deletions src/main/Duke/virtue/EmptyIndexException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package virtue;

public class EmptyIndexException extends VirtueException{
public EmptyIndexException(String type) {
super("OOPS!!! The description of a " + type + " command cannot be empty.");
}
}
22 changes: 22 additions & 0 deletions src/main/Duke/virtue/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package virtue;

public class Event extends VirtueTask {
private String from;
private 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() + " (from: " + this.from + " to: " + this.to + ")";
}

@Override
public String fileFormat() {
return "E | " + super.fileFormat() + " | " + from + " | " + to;
}
}
7 changes: 7 additions & 0 deletions src/main/Duke/virtue/IndexFormatException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package virtue;

public class IndexFormatException extends VirtueException {
public IndexFormatException(String type) {
super("The index of a " + type + " command must be an integer.");
}
}
17 changes: 17 additions & 0 deletions src/main/Duke/virtue/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package virtue;

public class Todo extends VirtueTask {
public Todo(String description) {
super(description);
}

@Override
public String toString() {
return "[T]" + super.toString();
}

@Override
public String fileFormat() {
return "T | " + super.fileFormat();
}
}
7 changes: 7 additions & 0 deletions src/main/Duke/virtue/UnknownCommandTypeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package virtue;

public class UnknownCommandTypeException extends VirtueException {
public UnknownCommandTypeException() {
super("OOPS!!! I'm sorry, but I don't know what that means :-(");
}
}
81 changes: 81 additions & 0 deletions src/main/Duke/virtue/Virtue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package virtue;

import java.io.IOException;
import java.util.Scanner;

public class Virtue {
// The scanner the chatbot uses to scan users' inputs.
Scanner sc = new Scanner(System.in);

// The task list to be used by the chatbot.
VirtueTaskList taskList = new VirtueTaskList();

// A horizontal line.
private static final String horizontalLine = "____________________________________________________________";

Choose a reason for hiding this comment

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

its very good that you made this final, and abstracted printing with indents and printing horizontal lines, it would have been very difficult to read otherwise


// Prints with an indention.
protected static void printWithIndent(String str) {
System.out.println(" " + str);
}

// Prints a horizontal line.
protected static void printHorizontalLine() {
printWithIndent(horizontalLine);
}

// Greets the user.
private void greet() {
printHorizontalLine();
printWithIndent("Hello! I'm Virtue \n What can I do for you?");
printHorizontalLine();
}

// Exits with a goodbye message.
private void bye() {
printHorizontalLine();
printWithIndent("Bye. Hope to see you again soon!");
printHorizontalLine();
}

// Takes inputs from user until bye has been input.
private void takeInputsUntilBye() {
Command currentCommand;
// While user hasn't input bye, add task to task list
while (true) {
// If list is input, print list, else add task to list
try {
String input = sc.nextLine();
currentCommand = new Command(input);
} catch (VirtueException e) {
printHorizontalLine();
System.out.println(" " + e.getMessage());
printHorizontalLine();
continue;
}

if (currentCommand.isBye()) {
break;
} else {
try {
taskList.executeCommand(currentCommand);
VirtueFileWriter.writeToFile(taskList);
} catch (IOException e) {
System.out.println("OOPS! An error occurred while taking the inputs: " + e.toString());
}
}
}
}

// Runs the chatbot.
private void run() {

Choose a reason for hiding this comment

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

its really good you abstracted out the functions, and made the run() method concise

taskList = VirtueFileReader.initializeTaskList();
greet();
takeInputsUntilBye();
bye();
}

public static void main(String[] args) {
Virtue virtue = new Virtue();
virtue.run();
}
}
8 changes: 8 additions & 0 deletions src/main/Duke/virtue/VirtueException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package virtue;

// Exceptions unique to Virtue.
public class VirtueException extends Exception {
public VirtueException(String message) {
super(message);
}
}
38 changes: 38 additions & 0 deletions src/main/Duke/virtue/VirtueFileReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package virtue;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class VirtueFileReader {

Choose a reason for hiding this comment

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

It would be nice to explain what the file reader does for the application in a comment. Might be more important when in the future we deal with different files with more than one purpose


public static VirtueTaskList initializeTaskList() {
VirtueTaskList taskList = new VirtueTaskList();

File directory = new File("data");
File file = new File("data/virtue.txt");

if (!directory.exists()) {
directory.mkdir();
}

if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
System.out.println("OOPS! An error occurred while creating the file: " + e.getMessage());
}
}

try {
Scanner sc = new Scanner(file);
while (sc.hasNext()) {
taskList.addFromFile(sc.nextLine());
}
} catch (IOException e) {
System.out.println("OOPS! An error occurred while reading the file: " + e.getMessage());
}

return taskList;
}
}
13 changes: 13 additions & 0 deletions src/main/Duke/virtue/VirtueFileWriter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package virtue;

import java.io.FileWriter;
import java.io.IOException;

public class VirtueFileWriter {

public static void writeToFile(VirtueTaskList taskList) throws IOException {
FileWriter fileWriter = new FileWriter("data/virtue.txt");
fileWriter.write(taskList.fileFormat());
fileWriter.close();
}
}
Loading