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

[Ernest Yu] iP #619

Open
wants to merge 74 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
74 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
c9700d5
rename greet exit
ernestycr Aug 22, 2024
3a37ec7
echo
ernestycr Aug 22, 2024
7d54463
add list
ernestycr Aug 22, 2024
8d1d88e
mark as done
ernestycr Aug 22, 2024
2a18dae
todo event deadline
ernestycr Aug 22, 2024
833133a
automated text UI testing
ernestycr Aug 22, 2024
38f9bec
handle errors
ernestycr Aug 22, 2024
1b521ad
delete tasks
ernestycr Aug 22, 2024
a190e1e
delete tasks 2
ernestycr Aug 22, 2024
72e666e
Add writeToFile method
ernestycr Sep 1, 2024
cbeeef2
Add reading and writing to file
ernestycr Sep 1, 2024
6c942c6
Add datafile
ernestycr Sep 1, 2024
cbd56fd
remove B_word file
ernestycr Sep 1, 2024
e89bede
Merge branch 'branch-Level-7'
ernestycr Sep 1, 2024
356ec8c
Add Ui class
ernestycr Sep 1, 2024
63cec7f
Add Storage class
ernestycr Sep 1, 2024
e53a47f
Add TaskList class
ernestycr Sep 1, 2024
bc2746b
Add Parser class
ernestycr Sep 1, 2024
c9b71c5
Add Command, AddCommand class and update the rest
ernestycr Sep 1, 2024
987c3b1
Update Bword to mirror task page
ernestycr Sep 1, 2024
9683515
Add DeleteCommand class
ernestycr Sep 1, 2024
89ba645
Add MarkCommand class
ernestycr Sep 1, 2024
1e125c2
Add UnmarkCommand class
ernestycr Sep 1, 2024
885696a
Add ListCommand class
ernestycr Sep 1, 2024
ffd1bc3
level-7 with more OOP
ernestycr Sep 1, 2024
fd4fc4c
Fix mistakes made earlier
ernestycr Sep 1, 2024
7da5dcd
Add ExitCommand class
ernestycr Sep 1, 2024
ef6ce97
Restore all functionalities (I hope) of level7
ernestycr Sep 1, 2024
105be6c
Add LocalDate and modified relevant files
ernestycr Sep 2, 2024
7ce1c85
Merge branch: Add Level-8 as increment
ernestycr Sep 2, 2024
c69296f
Stop tracking TaskHandler.java
ernestycr Sep 2, 2024
75bceb8
Add .gitignore file
ernestycr Sep 2, 2024
7d741f1
Add and edit all files to branch-A-package
ernestycr Sep 2, 2024
20200b9
Merge branch 'branch-A-Packages': yes
ernestycr Sep 2, 2024
40d18a4
Save data file
ernestycr Sep 2, 2024
8b5c1b3
Merge branch 'add-gradle-support'
ernestycr Sep 2, 2024
4833381
Add ToDoTaskTest and ParserTest class
ernestycr Sep 2, 2024
a41eda4
Add javadoc comments to bot, command, exception packages
ernestycr Sep 2, 2024
454e46d
Add javadoc comments for Task.java
ernestycr Sep 2, 2024
f79e64f
Merge branch 'branch-A-JavaDoc'
ernestycr Sep 2, 2024
424cf74
Add javadoc comments to ToDoTask.java
ernestycr Sep 2, 2024
ff4ac5e
Merge branch 'branch-A-CodingStandard'
ernestycr Sep 2, 2024
54a5a8c
Add FindCommand and modified related classes
ernestycr Sep 3, 2024
2ee5da5
Resolve merge conflicts (hopefully)
ernestycr Sep 3, 2024
9c2135a
Add checkstyle
ernestycr Sep 5, 2024
dee2a80
Merge maybe with ff I forgot
ernestycr Sep 5, 2024
c2aa27f
Add gui till javafx level4
ernestycr Sep 12, 2024
9f50bcb
Edit the execute method in Command for the GUI
ernestycr Sep 12, 2024
91ec795
Merge branch 'branch-Level-10'
ernestycr Sep 12, 2024
f6c4932
Rectify codestyle for Main and Bword
ernestycr Sep 20, 2024
edf23bd
branch1 commit1
ernestycr Sep 22, 2024
7770545
Modify AddCommand for code quality
ernestycr Sep 22, 2024
e764925
Merge pull request #2 from somethingfishyfishy/branch-A-Assertions
somethingfishyfishy Sep 22, 2024
aa1b7ee
Merge changes from master to branch-A-CodeQuality
ernestycr Sep 22, 2024
4ec63b2
Merge pull request #3 from somethingfishyfishy/branch-A-CodeQuality
somethingfishyfishy Sep 22, 2024
f9ae1ad
Add comment for future reference for streams
ernestycr Sep 23, 2024
5d96c88
To Merge branch 'master' into branch-A-Streams
ernestycr Sep 23, 2024
25e0a01
Merge pull request #4 from somethingfishyfishy/branch-A-Streams
somethingfishyfishy Sep 23, 2024
149b7dc
Add Extension C-DetectDuplicates
ernestycr Sep 23, 2024
0489e23
Merge branch, add extension - C-DetectDuplicates
ernestycr Sep 23, 2024
ca812de
Add HelpCommand
ernestycr Sep 23, 2024
f14bd71
Merge branch 'branch-A-Extensions'
ernestycr Sep 23, 2024
303a829
Update README.md
somethingfishyfishy Sep 23, 2024
70d268e
Update README.md
somethingfishyfishy Sep 23, 2024
f617801
Add style to GUI
ernestycr Sep 28, 2024
3611a22
Merge branch 'master' of https://github.com/somethingfishyfishy/ip
ernestycr Sep 28, 2024
b8a2cdf
Beautify images
ernestycr Sep 28, 2024
352806d
Delete dead code
ernestycr Sep 28, 2024
d25df0f
Fix bugs of program
ernestycr Sep 28, 2024
2c5fa98
Update README.md
somethingfishyfishy Sep 28, 2024
a3acccc
Add jar Release File
ernestycr Sep 28, 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/bword.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
todo xyz
event bcd /from today /to tmr
deadline me /by fri
1 change: 1 addition & 0 deletions src/main/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TaskHandler.java

Choose a reason for hiding this comment

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

How come you have a TaskHandler.java class which is not used?

Copy link
Author

Choose a reason for hiding this comment

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

To be removed in future updates.

10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

95 changes: 95 additions & 0 deletions src/main/java/chatBot/bot/Bword.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package chatBot.bot;

import chatBot.command.Command;

/** Bword is a chatbot that helps with planning tasks
*
*/

public class Bword {
private static final String FILELOCATION = "./data/bword.txt";
//public static final String HLINE = "____________________________________________________________\n";

private Storage storage;
private TaskList taskList;
private Ui ui;

Bword(String s) {
this.ui = new Ui();
this.storage = new Storage(s);
try {
this.taskList = new TaskList(this.storage.load());
} catch (Exception e) {
ui.showLoadingError();
this.taskList = new TaskList();
}
}

void run() {
this.ui.showWelcome();
boolean isExit = false;

Choose a reason for hiding this comment

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

I like how you name your boolean here with prefix 'is'.

Copy link
Author

Choose a reason for hiding this comment

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

thanks


while (!isExit) {
try {
String fullCommand = this.ui.readCommand();
this.ui.showLine(); // show the divider line ("_______")
Command c = Parser.parse(fullCommand);
c.execute(this.taskList, this.ui, this.storage);
isExit = c.isExit();
} catch (Exception e) {
this.ui.showError(e.getMessage());
} finally {
this.ui.showLine();
}
}
}

public static void main(String[] args) {
Bword bot = new Bword(FILELOCATION);
bot.run();

/*
TaskHandler th = new TaskHandler();
File file;
try {
file = new File(FILELOCATION);
Scanner sc = new Scanner(file);
while (sc.hasNextLine()) {
String s = sc.nextLine();
// System.out.println(s);
th.addPastTask(s);
}
sc.close();
} catch (FileNotFoundException e) {
System.out.println("File not found");
e.printStackTrace();
return;
}
*/
// Scanner sc = new Scanner(System.in);

/*
enum States {to_loop, to_exit, to_list}
States currentState = States.to_loop;

while (currentState != States.to_exit) {
String command = sc.next();
String s = sc.nextLine();
System.out.print(HLINE);
String tmp = s.strip();
if (command.equals("bye")) {
break;
}
th.handleCommand(command, s);
System.out.print(HLINE);
}

file.delete();
th.writeToFile(FILELOCATION);

System.out.println(
" Bye. Hope to see you again soon!\n" +
HLINE);
*/
}
}
113 changes: 113 additions & 0 deletions src/main/java/chatBot/bot/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package chatBot.bot;

import chatBot.command.*;
import chatBot.exception.EmptyDescException;
import chatBot.exception.InvalidCommandException;
import chatBot.task.Deadline;
import chatBot.task.Event;
import chatBot.task.Task;
import chatBot.task.ToDoTask;

import java.time.format.DateTimeParseException;

public class Parser {
static Task parseTask(String s) {

Choose a reason for hiding this comment

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

Should this String and the Task variable later be named more descriptively, as you are using them throughout the method?

String command = s.split(" ")[0];
String desc = s.substring(s.indexOf(" "));

desc = desc.stripLeading();

Task t = null;

if (command.equals("todo")) {
try {
t = new ToDoTask(desc);
} catch (Exception e) {
Ui.printAnything(e.getMessage());
}
} else if (command.equals("deadline")) {
try {
String[] arr = desc.split("/by");
try {
t = new Deadline(arr[0].strip(), arr[1].strip());
} catch (ArrayIndexOutOfBoundsException e) {
Ui.printAnything("missing /by");
} catch (DateTimeParseException ex) {
Ui.printAnything("Incorrect date format stored: " + arr[1].strip());
}
} catch (EmptyDescException e) {
Ui.printAnything(e.getMessage());
}
} else if (command.equals("event")) {
String[] arr = desc.split("/from");
String[] arr2 = new String[0];
try {
arr2 = arr[1].split("/to");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("missing /from");
}
t = null;
try {
try {
t = new Event(arr[0].strip(), arr2[0].strip(), arr2[1].strip());
} catch (ArrayIndexOutOfBoundsException ex) {
System.out.println("missing /to");
} catch (DateTimeParseException ex) {
System.out.println("Incorrect date format stored: " + arr[1].strip());
}
} catch (Exception e) {
Ui.printAnything(e.getMessage());
}
} else {
try {
throw new InvalidCommandException();
} catch (InvalidCommandException e) {
Ui.printAnything(e.getMessage());
}
//System.out.println("Unknown command: " + command);
}

if (t == null) {
System.out.println("null tasked returned back to Storage.load()");
}

return t;
}

static Command parse(String fullCommand) {

Choose a reason for hiding this comment

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

Should these methods have header comments to make the parameters and return values more clear?

String action = fullCommand.split(" ")[0];
String desc = fullCommand.substring(fullCommand.indexOf(" ") + 1);
if (fullCommand.indexOf(" ") == -1) {
desc = "";
}
Command c = null;
if (action.equals("mark")) {
c = new MarkCommand(Integer.parseInt(desc) - 1);
// Task t = this.tasks.get(Integer.parseInt(desc) - 1).markAsDone();
// System.out.println("I've marked as done:\n" + t);
} else if (action.equals("unmark")) {
c = new UnmarkCommand(Integer.parseInt(desc) - 1);
// Task t = this.tasks.get(Integer.parseInt(desc) - 1).markAsNotDone();
// System.out.println("I've marked as not done:\n" + t);
} else if (action.equals("list")) {
c = new ListCommand();
// System.out.println(this.getTasksString());
} else if (action.equals("todo") || action.equals("deadline") || action.equals("event")) {
//System.out.println("action is: " + action + " and desc is: " + desc + ".");
c = new AddCommand(action, desc);
} else if (action.equals("delete")) {
c = new DeleteCommand(Integer.parseInt(desc));
// this.deleteTask(Integer.parseInt(desc));
} else if (action.equals("bye")) {
c = new ExitCommand();
} else {
try {
throw new InvalidCommandException();
} catch (InvalidCommandException e) {
System.out.println(e);
}
//System.out.println("Unknown command: " + command);
}
return c;
}
}
62 changes: 62 additions & 0 deletions src/main/java/chatBot/bot/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package chatBot.bot;

import chatBot.task.Task;

import java.io.File; // Import the File class
import java.io.FileNotFoundException; // Import this class to handle errors
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.io.FileWriter;

public class Storage {
private File file;
private final String filePath;

Storage(String filePath) {

Choose a reason for hiding this comment

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

Perhaps an access modifier could be added for the constructor here for the sake of completeness :)

this.filePath = filePath;
try {
this.file = new File(filePath);
} catch (NullPointerException e) {
System.out.println("pathname unrecognised");
} catch (Exception e) {
System.out.println("Exception occured: " + e.getMessage());
}
}

ArrayList<Task> load() {
ArrayList<Task> tasks = new ArrayList<>();
Scanner sc = null;
try {
sc = new Scanner(file);
while (sc.hasNextLine()) {
String s = sc.nextLine();
Task t = Parser.parseTask(s);
if (t == null) {
continue;
}
tasks.add(t);
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
sc.close();
file.delete();
return tasks;
}

public void writeToFile(String s) {
try {
FileWriter myWriter = new FileWriter(filePath);
myWriter.write(s);
myWriter.close();
// myWriter.write("Files in Java might be tricky, but it is fun enough!");
// myWriter.close();
// System.out.println("Successfully wrote to the file.");
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}

}
57 changes: 57 additions & 0 deletions src/main/java/chatBot/bot/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package chatBot.bot;

import chatBot.task.Task;

import java.util.ArrayList;

/** TaskList serves the purpose of where all the Task is being stored
* @param tasks - there are previous tasks stored in ./data and is retreived.
*/
public class TaskList {
private ArrayList<Task> tasks;

TaskList(ArrayList<Task> tasks) {
this.tasks = tasks;
}

TaskList() {
this.tasks = new ArrayList<Task>();
}

public void addTask(Task task) {
this.tasks.add(task);
}

/** Create String object for storing back into file in Storage class */
public String getTaskCommands() {
String s = "";
for (Task t : this.tasks) {
s += t.getOriginalCommand() + "\n";
}
return s;
}

public int size() {
return this.tasks.size();
}

public Task getTask(int index) {
return this.tasks.get(index);
}

public void listTasks() {
String s = "";
for (int i = 0; i < this.tasks.size(); i++) {
s += String.format("%d.", i + 1) + this.tasks.get(i) + "\n";
}
System.out.println(s.stripTrailing());
}

public String getTaskToString(int index) {
return this.tasks.get(index).toString();
}

public void removeTask(int index) {
this.tasks.remove(index);
}
}
43 changes: 43 additions & 0 deletions src/main/java/chatBot/bot/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package chatBot.bot;

import java.util.Scanner;

public class Ui {
private Scanner scanner;
public static final String HLINE = "____________________________________________________________\n";

Ui() {
this.scanner = new Scanner(System.in);
}

void showWelcome() {
System.out.print(HLINE +
" Hello! I'm 'B word'\n" +
" What can I do for you?\n" +
HLINE);
}

Choose a reason for hiding this comment

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

Could consider proper access modifiers for most methods in this class


public void showGoodbye() {
System.out.println("Bye. Hope to see you again soon!");
}

void showLine() {
System.out.println(HLINE);
}

String readCommand() {
return this.scanner.nextLine();
}

void showError(String error) {
System.out.println(error);
}

void showLoadingError() {
System.out.println("Something went wrong when loading file");
}

static void printAnything(String s) {
System.out.println(s);
}
}
Loading