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

[Jiayan Ben] iP #76

Open
wants to merge 87 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
aa5ed3d
add file "Hello.txt"
J-Y-Yan Sep 5, 2023
28f7f8f
add new file "HelloAgain.txt"
J-Y-Yan Sep 5, 2023
1a006be
remove the file "Hello.txt" and "HelloAgain.txt"
J-Y-Yan Sep 6, 2023
f963203
add new file "Deadline.java" as subclass of Tast
J-Y-Yan Sep 6, 2023
ce21c8c
implement the main function Duke to finish the required tasks from lv…
J-Y-Yan Sep 6, 2023
d6f4537
add new file "Event.java" as subclass of Task
J-Y-Yan Sep 6, 2023
22f7501
add new file "Task.java" as parent class of task objects
J-Y-Yan Sep 6, 2023
a151504
add new file "Todo.java" as subclass of Task
J-Y-Yan Sep 6, 2023
752b8bf
add file "EXPECTED.txt" to test the output. ***content not yet initia…
J-Y-Yan Sep 6, 2023
abd1548
add "input.txt" containing the input commands
J-Y-Yan Sep 6, 2023
677d91b
add "runtest.bat" to compile the file. ***main class location is not …
J-Y-Yan Sep 6, 2023
6617431
rename a few variables and methods to aviod confusion
J-Y-Yan Sep 10, 2023
0c932c0
create more methods to different classes by code extraction to become…
J-Y-Yan Sep 10, 2023
4024b7f
initialise the content of input and expected output txt to conduct a …
J-Y-Yan Sep 10, 2023
e01ca3e
- add task object creation methods for all kind of task to improve re…
J-Y-Yan Sep 15, 2023
888d9c5
remove unused variable spaceIndex
J-Y-Yan Sep 15, 2023
ec736b8
- Implement exception to catch some main error caused by user inputs
J-Y-Yan Sep 15, 2023
f87152b
add the delete method and some exception handling for the method
J-Y-Yan Sep 15, 2023
eabd967
-implement file input ouput methods to sava the tasks data
J-Y-Yan Sep 21, 2023
73d4714
create directory 'data' and taskList.txt and corresponding backup fil…
J-Y-Yan Sep 21, 2023
12e33ab
output jar file to release ver. 1.0 application
J-Y-Yan Sep 22, 2023
e49be03
modify the clearData method so that it only clear data in the beginni…
J-Y-Yan Sep 24, 2023
0e0d08a
fixed a bug of inputting consecutive space
J-Y-Yan Sep 24, 2023
346d4bf
add command class to take care of command format issue
J-Y-Yan Sep 24, 2023
5908426
introduce command class and make large update to more OO implementation
J-Y-Yan Oct 6, 2023
8c9a743
add time praser functionality
J-Y-Yan Oct 6, 2023
73a6403
correct bugs on time praser
J-Y-Yan Oct 6, 2023
851801e
add find functionality
J-Y-Yan Oct 6, 2023
156c911
add more decumentations
J-Y-Yan Oct 6, 2023
00c05b9
add more documentations
J-Y-Yan Oct 6, 2023
2c00b17
launch jar
J-Y-Yan Oct 7, 2023
85b7029
correct some bugs
J-Y-Yan Oct 7, 2023
efa64fe
correct some issues on running the program over Linux system
J-Y-Yan Oct 8, 2023
da1aa7c
Add more documentation
J-Y-Yan Oct 21, 2023
34cd429
Update README.md
J-Y-Yan Oct 21, 2023
b9e9816
Update README.md
J-Y-Yan Oct 21, 2023
30fa3f2
Update README.md
J-Y-Yan Oct 21, 2023
85591e4
Update README.md
J-Y-Yan Oct 21, 2023
8a84838
Update README.md
J-Y-Yan Oct 21, 2023
3a3c454
Update README.md
J-Y-Yan Oct 21, 2023
3ba847c
Update README.md
J-Y-Yan Oct 21, 2023
c268b0b
Update README.md
J-Y-Yan Oct 21, 2023
54da8eb
Update README.md
J-Y-Yan Oct 21, 2023
00f58b5
Update README.md
J-Y-Yan Oct 21, 2023
bef8a97
Update README.md
J-Y-Yan Oct 21, 2023
80570c9
Update README.md
J-Y-Yan Oct 21, 2023
dbc9bc6
Update README.md
J-Y-Yan Oct 21, 2023
aa1cba6
Update README.md
J-Y-Yan Oct 21, 2023
27038e5
Update README.md
J-Y-Yan Oct 21, 2023
4bd199b
Update README.md
J-Y-Yan Oct 21, 2023
fb1402f
Update README.md
J-Y-Yan Oct 21, 2023
3b83a3a
Update README.md
J-Y-Yan Oct 21, 2023
8ced34e
Update README.md
J-Y-Yan Oct 21, 2023
1cb1fbc
Update README.md
J-Y-Yan Oct 21, 2023
abef09a
Update README.md
J-Y-Yan Oct 21, 2023
c47970e
Update README.md
J-Y-Yan Oct 21, 2023
a55d901
Update README.md
J-Y-Yan Oct 21, 2023
076e890
Update README.md
J-Y-Yan Oct 21, 2023
e74a144
Update README.md
J-Y-Yan Oct 21, 2023
89afba9
Update README.md
J-Y-Yan Oct 21, 2023
6554b32
Update README.md
J-Y-Yan Oct 21, 2023
c9771ed
Update README.md
J-Y-Yan Oct 21, 2023
f98e169
Update README.md
J-Y-Yan Oct 21, 2023
05c9b9e
Update README.md
J-Y-Yan Oct 21, 2023
194de5e
Update README.md
J-Y-Yan Oct 21, 2023
a8bd915
Update README.md
J-Y-Yan Oct 21, 2023
88d20d2
Update README.md
J-Y-Yan Oct 21, 2023
d89c626
Update README.md
J-Y-Yan Oct 21, 2023
70f7f2b
Update README.md
J-Y-Yan Oct 21, 2023
6d96bf2
Update README.md
J-Y-Yan Oct 21, 2023
a1d77ec
Update README.md
J-Y-Yan Oct 21, 2023
2313371
Update README.md
J-Y-Yan Oct 21, 2023
52df463
Update README.md
J-Y-Yan Oct 21, 2023
20bc921
Bugs fixed in using empty find command and mulfunctions of validating…
J-Y-Yan Oct 21, 2023
c25848c
Update README.md
J-Y-Yan Oct 21, 2023
7e8712d
Update README.md
J-Y-Yan Oct 21, 2023
564d7d8
Update README.md
J-Y-Yan Oct 21, 2023
aa8a38c
Update README.md
J-Y-Yan Oct 21, 2023
dc6e648
Update README.md
J-Y-Yan Oct 21, 2023
303fd3d
Add more documentations
J-Y-Yan Oct 21, 2023
dbb5b0b
Update README.md
J-Y-Yan Oct 21, 2023
2a2d9a1
Update README.md
J-Y-Yan Oct 21, 2023
9dd679e
Update README.md
J-Y-Yan Oct 21, 2023
8b13eb1
Update README.md
J-Y-Yan Oct 21, 2023
815481e
Update README.md
J-Y-Yan Oct 21, 2023
5996557
Update README.md
J-Y-Yan Oct 21, 2023
f57a735
Merge pull request #3 from J-Y-Yan/A-JavaDoc2.0
J-Y-Yan Oct 21, 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
14 changes: 14 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Deadline extends Task {

protected String byDeadline;

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

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + this.byDeadline + ")";
}
}
98 changes: 92 additions & 6 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,96 @@
import java.util.Scanner;

public class Duke {

public static int taskCount = 0;
private static Task[] list = new Task[100];

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
printWelcomeMessage();
Scanner keyboard = new Scanner(System.in);

while (true) {
String command = keyboard.nextLine();
String[] commendSplits = command.split(" ");

Choose a reason for hiding this comment

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

Small typo on "commendSplits"

int spaceIndex, taskNo;

switch (commendSplits[0]) {
case "bye":
printByeMessage();
keyboard.close();
return;

case "list":
printList(taskCount, list);
break;

case "mark":
// command format e.g. mark 1
taskNo = Integer.parseInt(commendSplits[1]); //assume saved in part[1], need further improve
list[taskNo - 1].setDone(taskNo, taskCount, list);
break;

case "unmark":
taskNo = Integer.parseInt(commendSplits[1]); //assume saved in part[1], need further improve
list[taskNo - 1].setNotDone(taskNo, taskCount, list);
break;

case "todo":
// command format e.g. todo borrow book
String[] todoSplit = command.split(" ", 2);
list[taskCount] = new Todo(todoSplit[1]);
createTaskSuccessMsg();
break;

case "deadline":
// command e.g. deadline return book /by Sunday
String[] ddlSplit = command.split("/");

Choose a reason for hiding this comment

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

Avoid using short forms as variable names as it might confuse readers with different backgrounds.

spaceIndex = ddlSplit[0].indexOf(" ");
String ddlTask = ddlSplit[0].substring(spaceIndex + 1).trim();
list[taskCount] = new Deadline(ddlTask, ddlSplit[1].substring(3));
createTaskSuccessMsg();
break;

case "event":
//command e.g. event project meeting /from Mon 2pm /to 4pm
String[] eventSplit = command.split("/");
spaceIndex = eventSplit[0].indexOf(" ");
String eventTask = eventSplit[0].substring(spaceIndex + 1).trim();
String start = eventSplit[1].trim().substring(5); // Remove "/from " prefix
String end = eventSplit[2].trim().substring(3); // Remove "/to " prefix
list[taskCount] = new Event(eventTask, start, end);
createTaskSuccessMsg();
break;

default:
System.out.println("Sorry. This is not expected.");
System.out.println("Please type in \"help\" to look for command format");
}
}

}

private static void createTaskSuccessMsg() {
System.out.println("Got it. I've added this task:");
System.out.println(list[taskCount]);
taskCount++;
System.out.println("Now you have " + taskCount + " tasks in the list.");
}

private static void printByeMessage() {
System.out.println("Bye. Hope to see you again soon!");
}

private static void printWelcomeMessage() {
System.out.println("Hello! I'm Oriento.");
System.out.println("What can I do for you?");
}

private static void printList(int count, Task[] list) {
for (int i = 0; i < count; i++) {
//example 1.[T][X] read book
System.out.println((i + 1) + "." + list[i]);
}
}

}
17 changes: 17 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Event extends Task {
protected String start, end;

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


@Override
public String toString() {
//print example: [E][ ] project meeting (from: Aug 6th 2pm to: 4pm)
return "[E]" + super.toString() + " (from: " + this.start + " to: " + this.end + ")";
}

}
43 changes: 43 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
public class Task {
protected String description;
protected boolean isDone;

public Task(String description) {
this.description = description;
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

public void setDone(int taskNo, int taskCount, Task[] list){
if( (taskNo > taskCount ) || (taskNo <1) ){
System.out.println("Oops! You don't have any task in this positions.");
}else if(this.isDone){
System.out.println("You have already completed the task.");
} else{

Choose a reason for hiding this comment

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

Spacing of the if else statements does not follow standards. Similar in other areas

this.isDone = true;
System.out.println(" Nice! I've marked this task as done:\n"
+ " [X] " + list[taskNo - 1].description);
}
}

public void setNotDone(int taskNo, int taskCount, Task[] list){
if( (taskNo > taskCount ) || (taskNo <1) ){
System.out.println("Oops! You don't have any task in this position.");
}else if(!this.isDone){
System.out.println("Oh, you haven't finished this yet.");
} else{
this.isDone = false;
System.out.println("OK, I've marked this task as not done yet:\n"
+ " [ ] " + list[taskNo - 1].description);
}
}

@Override
public String toString() {
return "[" + this.getStatusIcon() + "] " + this.description;
}

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

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

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

Choose a reason for hiding this comment

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

Good use of inheritance in implementation of toString().

22 changes: 22 additions & 0 deletions src/main/java/text-ui-test/EXPECTED.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Hello! I'm Oriento.
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][ ] play piano
Now you have 2 tasks in the list.
Nice! I've marked this task as done:
[X] play piano
Got it. I've added this task:
[D][ ] return book (by: Friday)
Now you have 3 tasks in the list.
Got it. I've added this task:
[E][ ] java lesson (from: Friday 4pm to: 6pm)
Now you have 4 tasks in the list.
Oh, you haven't finished this yet.
1.[T][ ] read book
2.[T][X] play piano
3.[D][ ] return book (by: Friday)
4.[E][ ] java lesson (from: Friday 4pm to: 6pm)
Bye. Hope to see you again soon!
8 changes: 8 additions & 0 deletions src/main/java/text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
todo read book
todo play piano
mark 2
deadline return book /by Friday
event java lesson /from Friday 4pm /to 6pm
unmark 4
list
bye
21 changes: 21 additions & 0 deletions src/main/java/text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@ECHO OFF

REM create bin directory if it doesn't exist
if not exist ..\bin mkdir ..\bin

REM delete output from previous run
del ACTUAL.TXT

REM compile the code into the bin folder
javac -cp ..\src\main\java -Xlint:none -d ..\bin ..\src\main\java\*.java
IF ERRORLEVEL 1 (
echo ********** BUILD FAILURE **********
exit /b 1
)
REM no error here, errorlevel == 0

REM run the program, feed commands from input.txt file and redirect the output to the ACTUAL.TXT
java -classpath ..\bin Duke < input.txt > ACTUAL.TXT

REM compare the output to the expected output
FC ACTUAL.TXT EXPECTED.TXT