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

[Weiye] iP #295

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
356f7d2
Duke class: implement level 1 functionalities
TeddYE Jan 23, 2022
5741e28
Duke class: Implement level 2 functionalities
TeddYE Jan 23, 2022
ad6aed9
Duke class: remove redundant codes
TeddYE Jan 23, 2022
44b496e
Duke class: Implement Level-3 functionalities
TeddYE Jan 24, 2022
ae02dd3
Duke class: implement Level-4 functionalities
TeddYE Jan 24, 2022
bee688a
Update i/o files for testing
TeddYE Jan 24, 2022
6fe8ceb
Duke class: implement level-5 functionalities
TeddYE Jan 29, 2022
3910a1f
Duke class: implement level-6 functionalities
TeddYE Jan 29, 2022
8874be8
Implement A-Enums functionalities
TeddYE Jan 29, 2022
042bfe3
Add parser class to parse the user input into different commands
TeddYE Jan 30, 2022
256377e
Duke class: implement level-7 functionalities
TeddYE Feb 1, 2022
7e35173
Merge pull request #1 from TeddYE/branch-Level-7
TeddYE Feb 1, 2022
0762e16
Implement level-8 functionalities
TeddYE Feb 1, 2022
9fe0dc0
Merge pull request #2 from TeddYE/branch-Level-8
TeddYE Feb 1, 2022
325bed9
Refactor the code to extract out closely related code as classes
TeddYE Feb 1, 2022
ebfabea
Merge pull request #3 from TeddYE/branch-Level-8
TeddYE Feb 1, 2022
c0f4f9e
Organize the classes into suitable java packages
TeddYE Feb 1, 2022
96e5e0a
Add JUnit tests to test the behavior of the code
TeddYE Feb 1, 2022
3aad3db
Package the app as an executable JAR file
TeddYE Feb 2, 2022
53c09c9
Add JavaDoc comments to the code
TeddYE Feb 2, 2022
3b36a90
Reorganize the directories
TeddYE Feb 2, 2022
76d9ffa
Merge pull request #4 from TeddYE/branch-A-JavaDoc
TeddYE Feb 2, 2022
b4ab6bc
Merge branch 'master' of https://github.com/TeddYE/ip
TeddYE Feb 2, 2022
4c48792
Implement Level-9 functionalities
TeddYE Feb 2, 2022
f4e7989
Merge pull request #6 from TeddYE/branch-Level-9
TeddYE Feb 2, 2022
fb5007d
Use Gradle to automate some of the build tasks of the project
TeddYE Feb 5, 2022
91075bd
Merge pull request #7 from TeddYE/add-gradle-support
TeddYE Feb 5, 2022
746eb08
Implement Level-10 functionalities
TeddYE Feb 9, 2022
7cae665
Merge pull request #8 from TeddYE/branch-Level-10
TeddYE Feb 9, 2022
eecd61c
Improve code quality based on Code Quality topics
TeddYE Feb 11, 2022
d1ed7b3
Merge pull request #9 from TeddYE/branch-A-CodeQuality
TeddYE Feb 11, 2022
8ad414d
Use Assertions
TeddYE Feb 11, 2022
28b855f
Merge pull request #10 from TeddYE/branch-A-Assertions
TeddYE Feb 11, 2022
c8a15da
Implement undo command for users
TeddYE Feb 12, 2022
1bd155d
Add user guide
TeddYE Feb 21, 2022
108359b
Merge pull request #12 from TeddYE/branch-UserGuide
TeddYE Feb 21, 2022
c488e8e
Set theme jekyll-theme-minimal
TeddYE Feb 21, 2022
ce71260
Set theme jekyll-theme-dinky
TeddYE Feb 21, 2022
4aad472
Update comments in accordance to coding standards
TeddYE Feb 21, 2022
13a66ce
Add ui picture
TeddYE Feb 21, 2022
67f7f67
Set theme jekyll-theme-dinky
TeddYE Feb 21, 2022
befb8c4
Change ui picture file name
TeddYE Feb 21, 2022
61216bf
Merge branch 'master' of https://github.com/TeddYE/ip
TeddYE Feb 21, 2022
13f4072
Update main class name in build.gradle
TeddYE Feb 21, 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
1 change: 1 addition & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
D~0~1~1111-11-11 1111
1 change: 1 addition & 0 deletions duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
T|0|1
3 changes: 3 additions & 0 deletions src/main/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: main.duke.Duke

3 changes: 3 additions & 0 deletions src/main/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: main.duke.Duke

42 changes: 42 additions & 0 deletions src/main/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package main.duke;

import main.duke.commands.Command;
import main.duke.io.Parser;
import main.duke.io.Storage;

import java.util.Scanner;

public class Duke {
private static final String WELCOME_MESSAGE = "Hello! I'm Duke \n" + "What can I do for you";

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

public Duke(String dirname, String filename) {
this.storage = new Storage(dirname, filename);
this.taskList = new TaskList();
this.ui = new Ui();
this.parser = new Parser();
}

public void run() throws DukeException{

Choose a reason for hiding this comment

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

I think it should be a white space before the open curly bracket. I noticed the same issue in several other places too.

Scanner sc = new Scanner(System.in);

this.storage.readFile(this.taskList);

System.out.println(WELCOME_MESSAGE);

while (!Command.getIsExit()) {
Command newCommand = this.parser.parse(sc.nextLine());
newCommand.runCommand(this.ui, this.taskList);
}

storage.writeFile(this.taskList);
}

public static void main(String[] args) throws DukeException {
new Duke("data", "duke.txt").run();
}
}
7 changes: 7 additions & 0 deletions src/main/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main.duke;

public class DukeException extends Exception{
public DukeException (String errorMessage){
super(errorMessage);
}
}
33 changes: 33 additions & 0 deletions src/main/duke/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main.duke;

import main.duke.tasks.Task;

import java.util.ArrayList;

public class TaskList {
private ArrayList<Task> Tasks;

Choose a reason for hiding this comment

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

I think the variable name should be in camelCase. I suggest it should be tasks


public TaskList() {
this.Tasks = new ArrayList<>();
}

public Task getTask(int taskIndex) {
return this.Tasks.get(taskIndex);
}

public void addTask(Task newTask) {
this.Tasks.add(newTask);
}

public void deleteTask(int taskIndex) {
this.Tasks.remove(taskIndex);
}

public int getTasksCount() {
return this.Tasks.size();
}

public String taskCountToString() {
return String.format("Now you have %d task(s) in the list.", this.getTasksCount());
}
}
82 changes: 82 additions & 0 deletions src/main/duke/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package main.duke;

import main.duke.tasks.Task;

import java.util.ArrayList;

public class Ui {
private static final String GOODBYE_MESSAGE = "Bye. Hope to see you again soon!";

public void respondBye() {
System.out.println(Ui.GOODBYE_MESSAGE);
}

/**
* prints out all the tasks in the current list
* @param taskList the current list of tasks
*/
public void respondList(TaskList taskList) {
int n = taskList.getTasksCount();
if (n == 0) {
System.out.println("The list is currently empty.");
} else {
for (int i = 0; i < n; i++) {
System.out.printf("%d.%s%n", i + 1, taskList.getTask(i));
}
}
}

/**
* prints out the task that has been marked
* @param markTask the targeted task to mark
*/
public void respondMark(Task markTask) {
System.out.printf("Nice! I've marked this task as done: \n"
+ " %s\n", markTask);
}

/**
* prints out the task that has been unmarked
* @param unmarkTask the targeted task to unmark
*/
public void respondUnmark(Task unmarkTask) {
System.out.printf("Nice! I've marked this task as done: \n"
+ " %s\n", unmarkTask);
}

/**
* prints out the task that has been added as well as the current number of tasks after adding
* @param newTask the targeted task to add
* @param taskList the current list of tasks
*/
public void respondAddTask(Task newTask, TaskList taskList) {
System.out.printf("Got it. I've added this task:\n" + "%s\n" + "%s\n",
newTask, taskList.taskCountToString());
}

/**
* prints out the task that has been added as well as the current number of tasks after removing
* @param deleteTask the targeted task to add
* @param taskList the current list of tasks
*/
public void respondDeleteTask(Task deleteTask, TaskList taskList) {
System.out.printf("Noted. I've removed this task: \n" + " %s\n"
+ "%s\n", deleteTask, taskList.taskCountToString());
}

/**
* prints out the task that was filtered by the user
* @param foundTasks the targeted task to add
*/
public void respondFindTask(ArrayList<Task> foundTasks) {
int n = foundTasks.size();
if (n == 0) {
System.out.println("Cannot find any related tasks.");
} else {
System.out.println("Here are the matching tasks in your list:");
for (int i = 0; i < n; i++) {
System.out.printf("%d.%s%n", i + 1, foundTasks.get(i));
}
}
}
}
18 changes: 18 additions & 0 deletions src/main/duke/commands/CBye.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main.duke.commands;

import main.duke.TaskList;
import main.duke.Ui;
import main.duke.enums.CommandType;

public class CBye extends Command{

Choose a reason for hiding this comment

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

Should the name of class be CommandBye? I think it is more meaningful. Similar with other command names.


public CBye() {
super(CommandType.BYE);
}

@Override
public void runCommand(Ui ui, TaskList taskList) {
Command.exitDuke();
ui.respondBye();
}
}
33 changes: 33 additions & 0 deletions src/main/duke/commands/CDeadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main.duke.commands;

import main.duke.TaskList;
import main.duke.Ui;
import main.duke.enums.CommandType;
import main.duke.tasks.Deadline;
import main.duke.tasks.Task;

public class CDeadline extends Command {
protected String description;
protected String dueDate;

public CDeadline(String description, String dueDate) {
super(CommandType.DEADLINE);
this.description = description;
this.dueDate = dueDate;
}

public String getDueDate() {
return this.dueDate;
}

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

@Override
public void runCommand(Ui ui, TaskList taskList) {
Task newDeadline = new Deadline(this.getDescription(), this.getDueDate());
taskList.addTask(newDeadline);
ui.respondAddTask(newDeadline, taskList);
}
}
31 changes: 31 additions & 0 deletions src/main/duke/commands/CDelete.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main.duke.commands;

import main.duke.DukeException;
import main.duke.TaskList;
import main.duke.Ui;
import main.duke.enums.CommandType;
import main.duke.tasks.Task;

public class CDelete extends Command{
protected int deleteIndex;

public CDelete(int deleteIndex) {
super(CommandType.DELETE);
this.deleteIndex = deleteIndex;
}

public int getDeleteIndex() {
return this.deleteIndex;
}

@Override
public void runCommand(Ui ui, TaskList taskList) throws DukeException {
try {
Task deleteTask = taskList.getTask(this.getDeleteIndex());
taskList.deleteTask(this.getDeleteIndex());
ui.respondDeleteTask(deleteTask, taskList);
} catch (IndexOutOfBoundsException e) {
throw new DukeException("Please check that you have entered the correct index.");
}
}
}
34 changes: 34 additions & 0 deletions src/main/duke/commands/CEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main.duke.commands;

import main.duke.TaskList;
import main.duke.Ui;
import main.duke.enums.CommandType;
import main.duke.tasks.Event;
import main.duke.tasks.Task;

public class CEvent extends Command {
protected String description;
protected String dateTime;

public CEvent(String description, String dateTime) {
super(CommandType.EVENT);
this.description = description;
this.dateTime = dateTime;
}

public String getDateTime() {
return this.dateTime;
}

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


@Override
public void runCommand(Ui ui, TaskList taskList) {
Task newEvent = new Event(this.getDescription(), this.getDateTime());
taskList.addTask(newEvent);
ui.respondAddTask(newEvent, taskList);
}
}
32 changes: 32 additions & 0 deletions src/main/duke/commands/CFind.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main.duke.commands;

import main.duke.DukeException;
import main.duke.TaskList;
import main.duke.Ui;
import main.duke.enums.CommandType;
import main.duke.tasks.Task;

import java.util.ArrayList;

public class CFind extends Command{
protected String findString;

public CFind(String findString) {
super(CommandType.FIND);
this.findString = findString;
}

public String getFindString() { return this.findString; }

Choose a reason for hiding this comment

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

I suggest follow EgyptianStyle when we make a function which has one line only. I noticed the same issue in several other places too.


@Override
public void runCommand(Ui ui, TaskList taskList) throws DukeException {
ArrayList<Task> foundTasks = new ArrayList<>();
for (int i = 0; i < taskList.getTasksCount(); i++) {
Task curTask = taskList.getTask(i);
if (curTask.getDescription().contains(this.getFindString())) {
foundTasks.add(curTask);
}
}
ui.respondFindTask(foundTasks);
}
}
16 changes: 16 additions & 0 deletions src/main/duke/commands/CList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main.duke.commands;

import main.duke.TaskList;
import main.duke.Ui;
import main.duke.enums.CommandType;

public class CList extends Command {
public CList() {
super(CommandType.LIST);
}

@Override
public void runCommand(Ui ui, TaskList taskList) {
ui.respondList(taskList);
}
}
31 changes: 31 additions & 0 deletions src/main/duke/commands/CMark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main.duke.commands;

import main.duke.DukeException;
import main.duke.TaskList;
import main.duke.Ui;
import main.duke.enums.CommandType;
import main.duke.tasks.Task;

public class CMark extends Command{
protected int markIndex;

public CMark(int markIndex) {
super(CommandType.MARK);
this.markIndex = markIndex;
}

public int getMarkIndex() {
return this.markIndex;
}

@Override
public void runCommand(Ui ui, TaskList taskList) throws DukeException {
try {
Task markTask = taskList.getTask(this.getMarkIndex());
markTask.setIsDone(true);
ui.respondMark(markTask);
} catch (IndexOutOfBoundsException e) {
throw new DukeException("Please check that you have entered the correct index.");
}
}
}
Loading