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

[KristopherPTaslim] iP #287

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
5406049
Level-1
KristopherPTaslim Jan 21, 2022
0dd972e
Finish Level-2
KristopherPTaslim Jan 21, 2022
1812262
Finish Level-3
KristopherPTaslim Jan 21, 2022
277c43f
Finish Level-4
KristopherPTaslim Jan 21, 2022
73b1d1c
Finish Level-5
KristopherPTaslim Jan 22, 2022
d619a83
Finish Level-6
KristopherPTaslim Jan 22, 2022
318b3aa
Finish Testing
KristopherPTaslim Jan 23, 2022
32bb23a
Finish Branch-Level-7
KristopherPTaslim Jan 29, 2022
bc9608c
Finish branch-Level-8
KristopherPTaslim Jan 29, 2022
e754bcb
Merge branch 'branch-Level-8'
KristopherPTaslim Jan 29, 2022
b37f27b
Debug Branch Level-7
KristopherPTaslim Jan 29, 2022
83bb0f3
Finish A-MOREOOP
KristopherPTaslim Feb 6, 2022
27fc406
Finish A-Packages
KristopherPTaslim Feb 6, 2022
589b161
Finish A-JUnit
KristopherPTaslim Feb 7, 2022
e8b6b2a
Debug A-JUnit
KristopherPTaslim Feb 7, 2022
28a85db
Delete the wrong folder test:java:duke
KristopherPTaslim Feb 7, 2022
7bbe7be
Finish A-Javadoc
KristopherPTaslim Feb 8, 2022
7b43639
Added missing JavaDoc in the branch-A-JavaDoc
KristopherPTaslim Feb 8, 2022
bbc3057
Finish A-CodingStandard
KristopherPTaslim Feb 9, 2022
6ea1b8c
Finish branch-Level-9
KristopherPTaslim Feb 9, 2022
3d551ba
Merge tag 'branch-A-CodingStandard'
KristopherPTaslim Feb 9, 2022
452a916
Merge tag 'branch-Level-9'
KristopherPTaslim Feb 9, 2022
aa60d80
Merging all the three branches(JavaDoc, Coding Standard and Level 9)
KristopherPTaslim Feb 9, 2022
6b75a3c
Merge commit 'd8398594b7bc43da5eb865321c5a50cec4b3923d' into branch-A…
KristopherPTaslim Feb 10, 2022
725a458
Finish running branch-A-Gradle
KristopherPTaslim Feb 10, 2022
fd68d86
Finish Level-10
KristopherPTaslim Feb 14, 2022
80a985b
Fix Minor Bug
KristopherPTaslim Feb 14, 2022
4524860
Edit execute() method in Parser class to follow coding standard.
KristopherPTaslim Feb 15, 2022
adc7846
Add assertions in some various points in code
KristopherPTaslim Feb 16, 2022
c3d28a2
Merge pull request #2 from KristopherPTaslim/branch-A-Assertions
KristopherPTaslim Feb 16, 2022
97d12b1
Merge branch 'master' into branch-A-CodeQuality
KristopherPTaslim Feb 16, 2022
1dfa71f
Merge pull request #3 from KristopherPTaslim/branch-A-CodeQuality
KristopherPTaslim Feb 16, 2022
c96d62b
Edit minor feature in Parser class
KristopherPTaslim Feb 16, 2022
36ccfcc
Finish branch-BCD-Extension
KristopherPTaslim Feb 18, 2022
99300b0
Add Ui.png under the docs folder
KristopherPTaslim Feb 18, 2022
7e5a187
Update ReadME.md
KristopherPTaslim Feb 18, 2022
cc38eb8
Update ReadME.md
KristopherPTaslim Feb 18, 2022
1a329c8
Edit some parts in build.gradle
KristopherPTaslim Feb 19, 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
12 changes: 12 additions & 0 deletions src/main/java/ChatBot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class ChatBot {
private final String input;

ChatBot(String input) {
this.input = input;
}

public String toString() {
return "added: " + this.input;
}

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

protected String by;

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

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

@Override
public String getInitial() {
return "[D]";
}
}
172 changes: 164 additions & 8 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,166 @@
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.util.ArrayList;
import java.util.Scanner;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

Choose a reason for hiding this comment

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

Following the coding standards, you might need to arrange the import statements into alphabetical order! :)
Same for some of the other classes that includes import statements.

Suggested change
import java.util.ArrayList;
import java.util.Scanner;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.io.IOException;
import java.time.format.DateTimeFormatter;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Scanner;


class Duke {

public static void main(String[] args) throws DukeException{

Choose a reason for hiding this comment

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

You might need to leave a space after DukeException

Suggested change
public static void main(String[] args) throws DukeException{
public static void main(String[] args) throws DukeException {

Scanner sc = new Scanner(System.in);
FileClass fc = new FileClass(); //file class
String home = System.getProperty("user.home"); //home directory

Choose a reason for hiding this comment

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

I like how you make comments behind the lines! It makes the logic clear 😄


String filePath = home + "/Desktop/ip/duke.txt";
System.out.println(filePath);
fc.createFile(filePath);

ArrayList<Task> taskArray = new ArrayList<Task>();
ArrayList<String> stringArray = new ArrayList<String>();

String beginning = "Hello! I'm Duke\n" +
"What can I do for you?";
System.out.println(beginning);

String input = sc.nextLine();

while (!input.equals("bye")) {
String[] checkType = input.split(" ");
String messageTask = "Got it. I've added this task: \n";

try {
if (input.equals("list")) {

if (taskArray.isEmpty()) {
System.out.println("The list is empty");
} else {
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < taskArray.size(); i++) {
String index = String.valueOf(i + 1);
System.out.println(index + "." + taskArray.get(i));
}
}
} else if (checkType[0].equals("mark") || checkType[0].equals("unmark")) { //this is to check whether it goes through marking

Choose a reason for hiding this comment

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

I think this line has more than the 120 character line limit allowed by the coding standard. Maybe you could add a line break to improve readability


try {
int index = Integer.parseInt(checkType[1]) - 1;
Task tasks = taskArray.get(index);

Choose a reason for hiding this comment

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

Maybe change the name of this variable to task since it only refers to a single entry

System.out.println(tasks.marking(checkType[0]));
taskArray.set(index, tasks);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("The input is not valid :(");
}


} else if (checkType[0].equals("todo")) { //check todo

String toDoCondition = "todo ";

try {
int indexOfToDo = toDoCondition.length(); //to find todo
String stringSliced = input.substring(indexOfToDo,input.length());
stringArray.add(stringSliced);
Todo todoTask = new Todo(stringSliced);
taskArray.add(todoTask);
String noOfTask = String.valueOf(taskArray.size());
System.out.println(messageTask + todoTask.toString() + "\n"
+ "Now you have " + noOfTask + " tasks in the list.");

} catch (StringIndexOutOfBoundsException e) {
System.out.println("☹ OOPS!!! The description of a todo cannot be empty.");
}


} else if (checkType[0].equals("deadline")) { //check deadline

String deadlineCondition = "/by ";

try {
int indexOfTime = input.indexOf(deadlineCondition); //to find /
String dateTime = input.substring(indexOfTime + deadlineCondition.length(), input.length()); // the date and time for by
//convert to the correct one
LocalDateTime deadlineTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("d/M/y Hmm"));
String convertedTime = deadlineTime.format(DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a"));

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 variables :), it is very clear what they all do 👍

String stringSliced = input.substring(9, indexOfTime); // after deadline
stringArray.add(stringSliced);
Deadline deadlineTask = new Deadline(stringSliced, convertedTime);
taskArray.add(deadlineTask);
String noOfTask = String.valueOf(taskArray.size());
System.out.println(messageTask + deadlineTask.toString() + "\n"
+ "Now you have " + noOfTask + " tasks in the list.");
} catch (StringIndexOutOfBoundsException e) {
System.out.println("☹ OOPS!!! The description of a deadline cannot be empty.");
}

} else if (checkType[0].equals("event")) { // check event

String eventCondition = "/at ";
try {
int indexOfTime = input.indexOf(eventCondition); //to find /
String dateTime = input.substring(indexOfTime + eventCondition.length(), input.length()); // the date and time for by
//convert to the correct one
LocalDateTime eventTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("d/M/y Hmm"));
String convertedTime = eventTime.format(DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a"));
String stringSliced = input.substring(6, indexOfTime); // after deadline
stringArray.add(stringSliced);
Event eventTask = new Event(stringSliced, convertedTime);
taskArray.add(eventTask);
String noOfTask = String.valueOf(taskArray.size());
System.out.println(messageTask + eventTask.toString() + "\n"

Choose a reason for hiding this comment

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

Great use of comments to clarify what each line is doing! Maybe you could also use a few blank lines to separate the code block into logical sections (such as formatting, processing and output.) The coding standard recommends that "Logical units within a block should be separated by one blank line."

+ "Now you have " + noOfTask + " tasks in the list.");
} catch (StringIndexOutOfBoundsException e) {
System.out.println("☹ OOPS!!! The description of a event cannot be empty.");
}
} else if (checkType[0].equals("delete")) {

try {
int index = Integer.parseInt(checkType[1]) - 1;
String toBeRemoved = taskArray.get(index).toString();
taskArray.remove(index);
String noOfTask = String.valueOf(taskArray.size());
String messageDeleted = "Noted. I've removed this task: \n" +
toBeRemoved + "\n" +
"Now you have " + noOfTask + " tasks in the list.";
System.out.println(messageDeleted);

} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("There are no tasks to be deleted!");
}
} else {
throw new DukeException("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}
} catch (DukeException e) {
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}

input = sc.nextLine();

}

// Recording everything in the duke.txt
for (int i = 0; i < taskArray.size(); i++ ) {
Task tasks = taskArray.get(i);

Choose a reason for hiding this comment

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

Since it is referring to just 1 task, will it be better to name this variable as 'task' instead of 'tasks'?

try {
String firstInitial = tasks.getInitial() ; //first initial character
String textToAdd = firstInitial + " | " + tasks.getStatusIcon() + " | "
+ stringArray.get(i);
fc.writeFile(filePath, textToAdd);
} catch (IOException e) {
System.out.println("File not found");
}

}

String ending = "Bye. Hope to see you again soon!";

System.out.println(ending);
sc.close();
}
}







6 changes: 6 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class DukeException extends RuntimeException {

public DukeException(String Message) {
super(Message);
}
}
19 changes: 19 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Event extends Task {

protected String at;

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

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

@Override
public String getInitial() {
return "[E]";
}
}
23 changes: 23 additions & 0 deletions src/main/java/FileClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;

class FileClass {

public void createFile(String filePath) {
File f = new File(filePath); //initialise the file
if (!f.exists()) { //meaning f doesnt exist
try {
f.createNewFile();
} catch (IOException e) {
System.out.println("Path Directory is invalid!");
}
}
}
//taken from W3.3c File Access
public void writeFile(String filePath, String textToAdd) throws IOException {
FileWriter fw = new FileWriter(filePath, true); // initialise the filewriter
fw.write(textToAdd + "\r\n");
fw.close();
}
}
47 changes: 47 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import java.util.ArrayList;

public class Task {
protected String description;
protected ArrayList<Boolean> isDone;

public Task(String description) {
this.description = description;
this.isDone = new ArrayList<Boolean>();
isDone.add(false);
}

public String getStatusIcon() {
return (isDone.get(0) ? "[X]" : "[ ]"); // mark done task with X // if done is "X" then " "
}

public void setAsDone() {
isDone.set(0, true);
}

public void setAsUndone() {
isDone.set(0, false);
}

public String marking(String mark) {
if (mark.equals("mark")) {
setAsDone();
String messageMarked = "Nice! I've marked this task as done: \n" +
this.toString();
return messageMarked;
} else {
setAsUndone();
String messageUnmarked = "OK, I've marked this task as not done yet: \n" +
this.toString();
return messageUnmarked;

}
}

public String toString() {
return getStatusIcon() + " " + this.description;
}

public String getInitial(){
return "Task";
}
}
16 changes: 16 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Todo extends Task {

public Todo(String description) {
super(description);
}

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

@Override
public String getInitial() {
return "[T]";
}
}
23 changes: 16 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

Hello! I'm Duke
What can I do for you?
Got it. I've added this task:
[T][ ] read book
Now you have 1 tasks in the list.
Got it. I've added this task:
[T][ ] buy bread
Now you have 2 tasks in the list.
Got it. I've added this task:
[D][ ] do homework (by: 3rd Jan)
Now you have 3 tasks in the list.
Here are the tasks in your list:
1.[T][ ] read book
2.[T][ ] buy bread
3.[D][ ] do homework (by: 3rd Jan)
Bye. Hope to see you again soon!
5 changes: 5 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
todo read book
todo buy bread
deadline do homework /by 3rd Jan
list
bye
Empty file modified text-ui-test/runtest.sh
100644 → 100755
Empty file.