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

[Lin Weilin] iP #368

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
da98b2d
add level 1
weilin1202 Jan 24, 2023
f1267e3
add level 2
weilin1202 Jan 25, 2023
6dadf28
Add level 3
weilin1202 Jan 25, 2023
464bf09
Add level 4
weilin1202 Jan 25, 2023
a03b4ff
Add UI test
weilin1202 Jan 25, 2023
93bcdaa
Add level 5
weilin1202 Jan 25, 2023
4e46cba
Add level 6
weilin1202 Jan 25, 2023
2a0d657
Add level 7
weilin1202 Jan 31, 2023
38c70c8
Add level 8
weilin1202 Feb 1, 2023
5fa18f0
add A-MoreOOP and A-Packages
weilin1202 Feb 7, 2023
fede33d
Merge branch 'add-gradle-support' of https://github.com/weilin1202/ip
weilin1202 Feb 7, 2023
0875429
Add A-JUnit
weilin1202 Feb 7, 2023
446b67b
Add A-JavaDoc
weilin1202 Feb 7, 2023
cc040c0
Add A-CodingStandard
weilin1202 Feb 7, 2023
ac9f6fa
Add Level-9
weilin1202 Feb 7, 2023
e209948
Add Level-10
weilin1202 Feb 13, 2023
d64c6e2
Add A-CheckStyle
weilin1202 Feb 13, 2023
c837839
Completed A-Jar
weilin1202 Feb 13, 2023
7b1c7c8
Implemented A-Jar using Gradle again
weilin1202 Feb 13, 2023
6cfe59e
Update Jar file
weilin1202 Feb 13, 2023
7dd4bf2
Add A-Assertions
weilin1202 Feb 13, 2023
efd490e
Improve Code Quality an OOP
weilin1202 Feb 14, 2023
4dd86d6
New message
weilin1202 Feb 14, 2023
63a7e15
Merge pull request #2 from weilin1202/branch-A-Assertions
weilin1202 Feb 15, 2023
a1e008c
Merge branch 'master' of https://github.com/weilin1202/ip
weilin1202 Feb 15, 2023
0aa85b9
Merge pull request #3 from weilin1202/branch-A-CodeQuality
weilin1202 Feb 15, 2023
9d0d3ad
Merge branch 'branch-A-CodeQuality'
weilin1202 Feb 15, 2023
0e677a9
Merge branch 'master' of https://github.com/weilin1202/ip
weilin1202 Feb 15, 2023
8dd634a
Storage class: create file and is stored locally with a specific cust…
weilin1202 Feb 15, 2023
30fe297
Classes that handle separate commands in Parser folder: The checking …
weilin1202 Feb 15, 2023
08739db
Cannot detect duplicates in the addition of tasks
weilin1202 Feb 15, 2023
c3c9b23
Moved the printing of String from Parser class to Ui class as Ui settles
weilin1202 Feb 15, 2023
fc08d66
Resolved the bugs discovered in Storage class after testing
weilin1202 Feb 15, 2023
05d2448
Improved the existing GUI
weilin1202 Feb 15, 2023
86e1c0b
Add A-Personality to Duke
weilin1202 Feb 15, 2023
f499929
Add the javadocs for newly implemented methods and classes
weilin1202 Feb 16, 2023
098bc19
Added assertions and improve code quality of storage
weilin1202 Feb 16, 2023
017ad98
A-UserGuide implementation
weilin1202 Feb 16, 2023
4bad7ab
Completed version 1.0
weilin1202 Feb 16, 2023
4eb813f
Updated user guide
weilin1202 Feb 17, 2023
d826e7d
Update User Guide
weilin1202 Feb 17, 2023
e245b55
Updated Storage file
weilin1202 Feb 17, 2023
04c97d2
Resolved background issue
weilin1202 Feb 17, 2023
58d0416
Update User Guide
weilin1202 Feb 17, 2023
071a988
Update user guide
weilin1202 Feb 17, 2023
5e9baa0
Updated comment in Storage class
weilin1202 Feb 17, 2023
e3827ec
Updated User guide
weilin1202 Feb 17, 2023
04b33d7
Updated the date checking when handling deadline and event timeline
weilin1202 Feb 17, 2023
3a0362a
Updated User Guide
weilin1202 Feb 17, 2023
cad8c22
Update user guide
weilin1202 Feb 17, 2023
92764d1
Improved implementation of checking input for adding of tasks.
weilin1202 Feb 17, 2023
8df56e7
Resolved checkstyle issues
weilin1202 Feb 17, 2023
f41a5fe
Re-uploaded Ui and corrected an extra space in the exception message
weilin1202 Feb 17, 2023
df0211b
Update User Guide
weilin1202 Feb 17, 2023
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
28 changes: 28 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Deadline extends Task{

String taskDescription;
LocalDate deadLine;
Copy link

Choose a reason for hiding this comment

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

Since these class fields have corresponding getters and setters, it might be better to make them private to prevent any unintended modifications.


public Deadline(String taskString, LocalDate deadline) {
super (taskString.substring(9, taskString.indexOf("/") - 1));

taskDescription = taskString.substring(9, taskString.indexOf("/") - 1);
deadLine = deadline;
}
@Override
public String getTask() {
return this.taskDescription;
}

public String getDeadline() {
return this.deadLine.format(DateTimeFormatter.ofPattern("MMM d yyyy"));
}

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

Choose a reason for hiding this comment

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

This is a good way to separate the different display behaviors of different task types 👍

}
114 changes: 108 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,112 @@
import java.io.BufferedWriter;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Duke {
public static void addTaskToFile(String fileName, String task) {
try {
BufferedWriter temp = new BufferedWriter(new FileWriter(fileName, true));
temp.write(task);
temp.close();
} catch (IOException e) {
System.out.println("There is an error in saving tasks.");
}
}
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);

System.out.println("Hello! I'm Happie \nWhat can I do for you?");
try {
File taskSaved = new File("C:/Users/linwe/Documents/TaskSaved.txt");
FileWriter myWriter = new FileWriter("C:/Users/linwe/Documents/TaskSaved.txt");
myWriter.write("");
} catch (IOException e) {
System.out.println("There is an error in saving tasks.");
}
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
ArrayList<Task> taskList = new ArrayList<>();



while(!input.equals("bye")) {

if (input.equals("list")) {
System.out.println("Here are some tasks in your list:");
for (int i = 1; i < taskList.size() + 1; i++) {
System.out.println(i + "." + (taskList.get(i - 1)).toString());
}

} else if(input.length() > 4 && (input.substring(0, 4)).equals("mark")) {
String taskStr = input.substring(5);
int taskNum = Integer.parseInt(taskStr) - 1;
Task originalTask = taskList.get(taskNum);
originalTask.markTask();
System.out.println("Nice! I've marked this task as done: \n " + originalTask);

} else if(input.length() > 6 && (input.substring(0, 6)).equals("unmark")) {
String taskStr = input.substring(7);
int taskNum = Integer.parseInt(taskStr) - 1;
Task originalTask = taskList.get(taskNum);
originalTask.unmarkTask();
System.out.println("Ok, I've marked this task as not done yet: \n " + originalTask);

} else if(input.length() > 4 && (input.substring(0, 4)).equals("todo")) {
ToDo task = new ToDo(input);
taskList.add(task);
addTaskToFile("C:/Users/linwe/Documents/TaskSaved.txt", task.getTaskType() + " | "
+ task.currentTaskStatus() + " | " + task.getTask() + "\n");

System.out.println("Got it. I've added this task: \n " + task +
"\nNow you have " + taskList.size() + " tasks in the list.");

} else if(input.length() > 8 &&(input.substring(0, 8)).equals("deadline")) {
LocalDate deadline = LocalDate.parse(input.substring(input.indexOf("/") + 4));
Deadline task = new Deadline(input, deadline);
taskList.add(task);
addTaskToFile("C:/Users/linwe/Documents/TaskSaved.txt", task.getTaskType() + " | "
+ task.currentTaskStatus() + " | " + task.getTask() + " | " + task.getDeadline() + "\n");

System.out.println("Got it. I've added this task: \n " + task +
"\nNow you have " + taskList.size() + " tasks in the list.");

} else if(input.length() > 5 && (input.substring(0, 5)).equals("event")) {
Copy link

Choose a reason for hiding this comment

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

Try to surround reserved words with a whitespace for consistency

LocalDate startDate = LocalDate.parse(input.substring(input.indexOf("/") + 6, input.lastIndexOf("/") - 1));
LocalDate endDate = LocalDate.parse(input.substring(input.lastIndexOf("/") + 4));
Event task = new Event(input, startDate, endDate);
taskList.add(task);
addTaskToFile("C:/Users/linwe/Documents/TaskSaved.txt", task.getTaskType() + " | "
+ task.currentTaskStatus() + " | " + task.getTask() + " | " + task.getTimeline() + "\n");

System.out.println("Got it. I've added this task: \n " + task +
"\nNow you have " + taskList.size() + " tasks in the list.");

} else if(input.length() > 6 && (input.substring(0, 6)).equals("delete")) {
String taskStr = input.substring(7);
int taskNum = Integer.parseInt(taskStr) - 1;
Task taskToRemove = taskList.get(taskNum);
String removedTaskStr = taskToRemove.toString();
taskList.remove(taskNum);
System.out.println("Noted. I've removed this task: \n " + removedTaskStr +
"\nNow you have " + taskList.size() + " tasks in the list.");
}
else {
try {
if ((input.equals("todo")) || (input.equals("deadline")) || (input.equals("event"))) {
throw new EmptyDescriptionException();
} else {
throw new WrongCommandException();
}
} catch (EmptyDescriptionException | WrongCommandException e){
System.out.println(e.getMessage());
}
}
input = sc.nextLine();
}
System.out.println("Bye. Hope to see you again soon!");
}
}
6 changes: 6 additions & 0 deletions src/main/java/EmptyDescriptionException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class EmptyDescriptionException extends Exception{
public EmptyDescriptionException() {
super("☹ OOPS!!! The description of a task cannot be empty.");
}

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

public class Event extends Task{
String taskDescription;
LocalDate startDate;
LocalDate endDate;
Copy link

Choose a reason for hiding this comment

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

Same goes for this, regarding making class fields private


public Event(String taskString, LocalDate startDateInput, LocalDate endDateInput) {
super(taskString.substring(6, taskString.indexOf("/") - 1));

taskDescription = taskString.substring(6, taskString.indexOf("/") - 1);
startDate = startDateInput;
endDate = endDateInput;
}

@Override
public String getTask() {
return this.taskDescription;
}

public String getTimeline() {
return this.startDate.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + " to " + this.endDate.format(DateTimeFormatter.ofPattern("MMM d yyyy"));
}

@Override
public String toString() {
return "[E]" + super.toString() + " (" + this.getTimeline() + ")";
}
}
37 changes: 37 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
public class Task {
public String taskString;
public boolean isCompleted;

public Task(String taskString) {
this.taskString = taskString;
this.isCompleted = false;
}

public String currentTaskStatus() {
if(this.isCompleted) {
return "[X]";
} else {
return "[ ]";
}
}

public void markTask() {
this.isCompleted = true;
}

public void unmarkTask() {
this.isCompleted = false;
}

public String getTaskType() {
return this.toString().substring(1, 2);
}

public String getTask() {
return " ";
}

public String toString() {
return this.currentTaskStatus() + " " + this.taskString;
}
}
22 changes: 22 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class ToDo extends Task {

String taskDescription;

public ToDo(String taskString) {
super(taskString.substring(5));

taskDescription = taskString.substring(5);
}

@Override
public String getTask() {
return this.taskDescription;
}


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

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

}
30 changes: 23 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

Hello! I'm Happie
What can I do for you?
Got it. I've added this task:
[T][ ] cook
Now you have 1 tasks in the list.
Got it. I've added this task:
[E][ ] pay (from: 4pm to: 7pm)
Now you have 2 tasks in the list.
Got it. I've added this task:
[D][ ] code (by: no idea :-p)
Now you have 3 tasks in the list.
Nice! I've marked this task as done:
[T][X] cook
Here are the tasks in your list:
1.[T][X] cook
2.[E][ ] pay (from: 4pm to: 7pm)
3.[D][ ] code (by: no idea :-p)
Ok, I've marked this task as not done yet:
[T][ ] cook
Here are the tasks in your list:
1.[T][ ] cook
2.[E][ ] pay (from: 4pm to: 7pm)
3.[D][ ] code (by: no idea :-p)
7 changes: 7 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
todo cook
event pay /from 4am /to 7pm
deadline code /by no idea :-p
mark 1
list
unmark 1
list