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

[Agamjyot] IP #508

Open
wants to merge 81 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
57e2341
first commit
garfield-oo7 Aug 18, 2022
2b23dc8
Add Chatbot.java and modify Duke.java
garfield-oo7 Aug 18, 2022
c55c8ed
Duke Level-2: Add List
Aug 18, 2022
0660f25
Level-3: Mark as Done
garfield-oo7 Aug 19, 2022
9c8a970
Level-4 ToDos, Events, Deadlines
garfield-oo7 Aug 19, 2022
f257b8b
A-TextUiTesting
garfield-oo7 Aug 19, 2022
0ccc628
Level-6: Delete
garfield-oo7 Aug 19, 2022
bf66b62
Add ChatBot Exception class
garfield-oo7 Aug 19, 2022
4fe9d41
Level5: Handle Errors
garfield-oo7 Aug 19, 2022
3818960
Add Storage.java to save commands
garfield-oo7 Aug 29, 2022
57d85ac
Level-7 Save
garfield-oo7 Aug 29, 2022
f53dcee
Level-8 Date and Times
garfield-oo7 Aug 29, 2022
3afdcfa
Merge branch 'branch-Level-7'
garfield-oo7 Aug 29, 2022
384d581
Merge branch 'branch-Level-8'
garfield-oo7 Aug 29, 2022
8d6ddd7
Resolve conflict
garfield-oo7 Aug 30, 2022
c1bf358
Add ExecuteCommand() method
garfield-oo7 Sep 18, 2022
accb5a3
Add Ui.java
garfield-oo7 Sep 19, 2022
d9f7d38
Add TaskList.java
garfield-oo7 Sep 19, 2022
4523685
Extract out Command
garfield-oo7 Sep 19, 2022
5df069b
Rename ChatBotException to DukeException.java
garfield-oo7 Sep 19, 2022
9dd15c1
extract out Command even more
garfield-oo7 Sep 19, 2022
7bce990
Add Parser.java
garfield-oo7 Sep 19, 2022
49e2710
Make change Task.java subclass
garfield-oo7 Sep 19, 2022
88b482d
Finish A More OOP
garfield-oo7 Sep 19, 2022
4384133
Finished A-Packages
garfield-oo7 Sep 19, 2022
442ea6c
Add FindCommand.java
garfield-oo7 Sep 19, 2022
056eb0a
Follow coding standard
garfield-oo7 Sep 19, 2022
42706f7
Add JavaDocs
garfield-oo7 Sep 19, 2022
9c28a7c
Resolve conflict
garfield-oo7 Sep 19, 2022
51b2288
Merge branch 'A-JavaDoc'
garfield-oo7 Sep 19, 2022
4f3d6e9
Add gradle
garfield-oo7 Sep 21, 2022
c0827d8
Add JUnit Test
garfield-oo7 Sep 21, 2022
7b9bab4
Update build.gradle
garfield-oo7 Sep 22, 2022
dbf16c7
Add jar file
garfield-oo7 Sep 22, 2022
59b8e93
Update README.md
garfield-oo7 Sep 22, 2022
b3af198
Update User Guide
garfield-oo7 Sep 22, 2022
8a18dfb
Update user guide
garfield-oo7 Sep 22, 2022
4cea6b7
Fix bug in Event command
garfield-oo7 Sep 22, 2022
95a650f
Merge branch 'master' of github.com:garfield-oo7/ip
garfield-oo7 Sep 22, 2022
bf8695a
Update User guide
garfield-oo7 Sep 22, 2022
e848cc2
Update user guide
garfield-oo7 Sep 22, 2022
cbde808
Add simple GUI
garfield-oo7 Sep 28, 2022
e3fb39c
Finish Gui
garfield-oo7 Sep 28, 2022
7f9547b
fix bug in saveTaskList
garfield-oo7 Sep 28, 2022
df90777
Fix bug in saveTaskList function
garfield-oo7 Sep 28, 2022
ee8334f
Revert "fix bug in saveTaskList"
garfield-oo7 Sep 28, 2022
e837e13
Merge branch 'master' of github.com:garfield-oo7/ip
garfield-oo7 Sep 28, 2022
67177e2
Resolve merge conflict
garfield-oo7 Sep 28, 2022
62bc3da
Update build.gradle
garfield-oo7 Sep 28, 2022
b27f4b2
Update Ui.png
garfield-oo7 Sep 28, 2022
eb69c56
Add more exceptions
garfield-oo7 Oct 12, 2022
27889fa
Add more exceptions
garfield-oo7 Oct 12, 2022
83b6f98
Add more exceptions
garfield-oo7 Oct 12, 2022
5caa3a7
Update data file
garfield-oo7 Oct 12, 2022
c1b87ed
Update .gitignore file
garfield-oo7 Oct 12, 2022
ad0488a
Update .gitignore to ignore data file
garfield-oo7 Oct 12, 2022
5e973d5
Update duke,txt
garfield-oo7 Oct 12, 2022
6a8c444
Update image for chatbot and user
garfield-oo7 Oct 12, 2022
11569a4
Fix error in printing the list of tasks
garfield-oo7 Oct 12, 2022
71215d2
Refactor test
garfield-oo7 Oct 12, 2022
bb70659
Remove data file
garfield-oo7 Oct 12, 2022
fc79cf8
Update gui
garfield-oo7 Oct 12, 2022
f5d2536
Update find command
garfield-oo7 Oct 12, 2022
0832875
Update find command
garfield-oo7 Oct 12, 2022
40cd274
Change behaviour on application start up
garfield-oo7 Oct 13, 2022
741e01c
Add HelpCommand.java
garfield-oo7 Oct 13, 2022
64c3727
Update Scrollbar issue of GUI
garfield-oo7 Oct 16, 2022
9c7adf9
Remove unused import statements
garfield-oo7 Oct 16, 2022
dc7926c
Ignore empty user inputs
garfield-oo7 Oct 16, 2022
3ca54c8
Add header comments for pulbic class and methods
garfield-oo7 Oct 16, 2022
9b697d6
Fix error in Storage.java
garfield-oo7 Oct 16, 2022
8bffba6
Remove unnesscary files
garfield-oo7 Oct 17, 2022
761dc56
Add a new Ui.png image
garfield-oo7 Oct 17, 2022
d8654c7
Update README.md
garfield-oo7 Oct 17, 2022
6648332
Update README.md
garfield-oo7 Oct 17, 2022
7062d1d
Update README.md
garfield-oo7 Oct 17, 2022
810b80e
Update README.md
garfield-oo7 Oct 17, 2022
b083f5b
Update README.md
garfield-oo7 Oct 17, 2022
21d9bfa
Update README.md
garfield-oo7 Oct 17, 2022
3acb5cd
Update README.md
garfield-oo7 Oct 17, 2022
0aefd9e
Update README.md
garfield-oo7 Oct 17, 2022
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
4 changes: 4 additions & 0 deletions src/main/data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
T | 1 | read book
D | 0 | return book | June 6th
E | 0 | project meeting | Aug 6th 2-4pm
T | 1 | join sports club
83 changes: 83 additions & 0 deletions src/main/java/ChatBot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import java.util.ArrayList;

class ChatBot {

private String name;
Copy link

Choose a reason for hiding this comment

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

Nothing major, but I feel like naming it botName would be clearer to understand, since later on there will be many possible instances of "names of tasks" and such.

private final String line = "------------------------------" +
"----------------------------------";
private ArrayList<Task> tasks;

ChatBot(String name) {

this.name = name;
this.tasks = new ArrayList<Task>();

}

public void greet() {

System.out.println(line + "\n\t Hello I'm " + name + "!!\n" +
"What do you wanna chat about today?\n" + line);
}

public void addTask(Task task) {

this.tasks.add(task);
System.out.println(line + "\n\tGot it. I just added the " +
"task:\n\t\t" + task + "\n\tNow you have " +
"" + this.tasks.size() + " tasks in the list\n" + line);
}

public void printTasks() {

System.out.println(line);

if(this.tasks.size() == 0) {

System.out.println("You currently have no tasks");
} else {

for (int i = 0; i < this.tasks.size(); i++) {

System.out.println("\t" + (i + 1) + ". " + this.tasks.get(i));
}
}
System.out.println(line);
}

public void markDone(int index) {

this.tasks.get(index).done(true);
Copy link

Choose a reason for hiding this comment

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

Since you have a relatively long chain of code to run, it might be better to omit the this at the start of the code and just use tasks.get(index).done(true) instead. This also applies to all the instances of this.tasks you used in this ChatBot Class.

System.out.println(line + "\n\tExcellent! I have marked " +
"the task as done:\n\t" + this.tasks.get(index) + "\n" + line);
}

public void markUndone(int index) {

this.tasks.get(index).done(false);
System.out.println(line + "\n\tNoted! I have marked " +
"the task as not done yet:\n\t"
+ this.tasks.get(index) + "\n" + line);
}

public void delete(int index) {

System.out.println(line + "\n\tNoted. I've remove this task:" +
this.tasks.get(index));
this.tasks.remove(index);
System.out.println("\t Now you have " + this.tasks.size() + " " +
"tasks in the list.\n" + line);
}

public void echo(String input) {

System.out.println(line + "\n\t" + input + "\n" + line);
}

public void bye() {

System.out.println(line + "\n\t Bye. Looking forward to chating " +
"with you soon again!\n" + line);
}

}
8 changes: 8 additions & 0 deletions src/main/java/ChatBotException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class ChatBotException extends Exception {

ChatBotException(String message) {

super(message);
}

}
39 changes: 39 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


class Deadline extends Task {

private LocalDateTime completeBy;

Deadline(String description, String completeBy) {
super(description, false);
this.completeBy = LocalDateTime.parse(completeBy,
DateTimeFormatter.ofPattern("[d/M/y HHmm]"));;
}

Deadline(String description, boolean isDone, String completeBy) {

super(description, isDone);

this.completeBy = LocalDateTime.parse(completeBy,
DateTimeFormatter.ofPattern("[d/M/y HHmm]"));;

}

@Override
public String toFileString() {

return "D | " + (this.isDone ? 1 : 0) + " | " +
this.description + " | " + this.completeBy;
}

@Override
public String toString() {

return "[D]" + super.toString() + " (by: " +
completeBy.format(DateTimeFormatter.ofPattern("MMM d yyyy"))
+ ")";
}

}
107 changes: 97 additions & 10 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,97 @@
public class Duke {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
}
}
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
import java.util.ArrayList;

public class Duke {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

ChatBot chatBot = new ChatBot("duke");

Storage taskStorage = new Storage();

chatBot.greet();

boolean quit = false;
String input;
String[] command;
String time; // for the deadline or time of the event
String taskName;

try {
ArrayList<Task> tasks = taskStorage.convertToTaskList();
while (!quit) {

try {
input = sc.next();

switch (input) {

case "bye":
quit = true;
chatBot.bye();
try {
taskStorage.saveTaskList(tasks);
} catch (IOException io) {
chatBot.echo(io.getMessage() + "\nUnable to save data. " +
"All the data will be lost!");
}
break;
case "list":
chatBot.printTasks();
break;
case "mark":
chatBot.markDone(sc.nextInt() - 1);
sc.nextLine();
break;
case "unmark":
chatBot.markUndone(sc.nextInt() - 1);
sc.nextLine();
break;
case "deadline":
command = sc.nextLine().split(" /by ");
chatBot.addTask(new Deadline(command[0], command[1]));
break;
case "event":
command = sc.nextLine().split(" /at ");
chatBot.addTask(new Events(command[0], command[1]));
Copy link

Choose a reason for hiding this comment

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

Perhaps it would be better to abstract out command[0] and command[1] by doing:

  • keyword = command[0] or firstWord = command[0]
  • restOfCommand = command[1]

before you pass it into your Class Constructors for greater clarity. 😄

Copy link
Author

Choose a reason for hiding this comment

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

yes, thank you for pointing that out, will make the changes in future commits.

break;
case "todo":
taskName = sc.nextLine();
if (taskName.isEmpty()) {
throw new ChatBotException("The description of todo cannot be empty " +
"please use the format:\n\t" +
"todo <description>");
}
chatBot.addTask(new ToDo(taskName));
break;
case "delete":
chatBot.delete(sc.nextInt() - 1);
sc.nextLine();
break;
default:
sc.nextLine();
throw new ChatBotException("I am sorry, but I don't " +
"understand this command");
}

} catch (ChatBotException e) {

chatBot.echo(e.getMessage());
}

}

} catch(FileNotFoundException e) {
chatBot.echo(e.getMessage() + "\n Creating new file");
try {
taskStorage.createDataFile();
} catch (IOException ioe) {
chatBot.echo(e.getMessage() + "Couldn't create new file");
}
}
}
}
39 changes: 39 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;


class Events extends Task {

private LocalDateTime eventTime;

Events(String description, String eventTime) {

super(description, false);
this.eventTime = LocalDateTime.parse(eventTime,
DateTimeFormatter.ofPattern("[d/M/y HHmm]"));;
}

Events(String description, boolean isDone, String eventTime) {

super(description, isDone);
this.eventTime = LocalDateTime.parse(eventTime,
DateTimeFormatter.ofPattern("[d/M/y HHmm]"));;

}

@Override
public String toFileString() {

return "E | " + (this.isDone ? 1 : 0) + " | " +
this.description + " | " + this.eventTime;
}

@Override
public String toString() {

return "[E]" + super.toString() + " (at: " +
eventTime.format(DateTimeFormatter.ofPattern("MMM d yyyy"))
+ ")";
}

}
87 changes: 87 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;

class Storage {

private final String DATA_FILEPATH = "ip/src/main/data/duke.txt";


public void createDataFile() throws IOException {

String[] dataPathList = DATA_FILEPATH.split("/");
String currentDirectory = "";

for(int i = 0; i < dataPathList.length - 1; i++) {

currentDirectory += dataPathList[i];
File directory = new File(currentDirectory);

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

currentDirectory += "/";

}

File newFile = new File(DATA_FILEPATH);
newFile.createNewFile();
}

public ArrayList<Task> convertToTaskList() throws FileNotFoundException {

ArrayList<Task> taskList = new ArrayList<Task>();
File file = new File(DATA_FILEPATH);
Scanner sc = new Scanner(file);

while(sc.hasNextLine()) {

String task = sc.nextLine();
char type = task.charAt(0);
Copy link

Choose a reason for hiding this comment

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

type could be more clearly specified to be taskType.

boolean isDone = task.charAt(1) == '1';
String[] description = task.substring(2).split("\\|");

switch(type){

case 'T':
taskList.add(new ToDo(description[0], isDone));
break;
case 'D':
taskList.add(new Deadline(description[0], isDone, description[1]));
break;
case 'E':
taskList.add(new Events(description[0], isDone, description[1]));
Copy link

Choose a reason for hiding this comment

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

Similarly, you could abstract out

  1. description[0] to be taskName = description[0] and
  2. description[1] to be restOfDescription = description[1]

before passing them into the respective Constructors.

break;
default:
break;
}

}

return taskList;

}

public void saveTaskList(ArrayList<Task> taskList) throws IOException {

FileWriter fw = new FileWriter(DATA_FILEPATH);

for(Task t : taskList) {

fw.write(t.toFileString() + System.lineSeparator());

}

fw.close();

}




}
Loading