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

[ryanchua00] iP #363

Open
wants to merge 52 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
6be16cb
level-1:
ryanchua00 Jan 13, 2023
5cc2b61
Level-2
ryanchua00 Jan 16, 2023
7a9ce73
Level-2: Fix
ryanchua00 Jan 16, 2023
e485de4
Level-3
ryanchua00 Jan 17, 2023
fac3a48
Level-3
ryanchua00 Jan 17, 2023
0d39797
Level-4
ryanchua00 Jan 17, 2023
3afcf4b
Level-4
ryanchua00 Jan 18, 2023
bc36003
A-TextUiTesting
ryanchua00 Jan 18, 2023
cb91a1a
Level-5
ryanchua00 Jan 18, 2023
38a71b7
Level-5
ryanchua00 Jan 18, 2023
862223e
Level-6:
ryanchua00 Jan 18, 2023
573fa47
Level-7
ryanchua00 Feb 2, 2023
8bd4863
Level-8
ryanchua00 Feb 2, 2023
0a197fe
Merge branch 'branch-Level-7'
ryanchua00 Feb 3, 2023
b263cba
Merge branch 'branch-Level-8'
ryanchua00 Feb 3, 2023
a8f772e
A-MoreOOP v1.0
ryanchua00 Feb 3, 2023
557669b
A-MoreOOP v2.0
ryanchua00 Feb 4, 2023
1340468
A-Packages
ryanchua00 Feb 4, 2023
3977717
Merge branch 'add-gradle-support'
ryanchua00 Feb 4, 2023
285a66e
A-Gradle
ryanchua00 Feb 4, 2023
2be4706
A-JUnit
ryanchua00 Feb 4, 2023
f1a96fa
A-Jar
ryanchua00 Feb 4, 2023
39f5232
A-Javadoc
ryanchua00 Feb 4, 2023
7bbafde
A-CodingStandard
ryanchua00 Feb 4, 2023
904c901
Level-9
ryanchua00 Feb 5, 2023
85ef6db
Merge branch 'branch-A-JavaDoc'
ryanchua00 Feb 5, 2023
7c2e668
Merge branch 'branch-A-CodingStandard'
ryanchua00 Feb 5, 2023
35b2606
Merge branch 'branch-Level-9'
ryanchua00 Feb 5, 2023
70d1d24
Level-10 Base
ryanchua00 Feb 6, 2023
2ba864a
Added Graphic User Interface(GUI) functionality
ryanchua00 Feb 8, 2023
48f46fe
Improve Exception handling
ryanchua00 Feb 8, 2023
21157cf
A-Assertions
ryanchua00 Feb 8, 2023
87ec5cb
Add custom commands
ryanchua00 Feb 9, 2023
72cf26c
Merge pull request #1 from ryanchua00/branch-A-CodeQuality
ryanchua00 Feb 9, 2023
6ad870f
Merge branch 'master' into branch-A-Assertions
ryanchua00 Feb 9, 2023
746e73a
Merge pull request #3 from ryanchua00/branch-A-Assertions
ryanchua00 Feb 9, 2023
ede39f9
Create gradle.yml
ryanchua00 Feb 9, 2023
3bb378f
Update gradle.yml
ryanchua00 Feb 9, 2023
07f31ec
Update Storage.java
ryanchua00 Feb 9, 2023
8390888
Fixing according to CI
ryanchua00 Feb 9, 2023
ded1829
Fix for Ci
ryanchua00 Feb 9, 2023
1ffffbc
Add help functionality
ryanchua00 Feb 9, 2023
3a858a6
Merge pull request #4 from ryanchua00/branch-C-Help
ryanchua00 Feb 10, 2023
0da28ad
Improve Code Quality
ryanchua00 Feb 15, 2023
bf3d7ea
Improve GUI
ryanchua00 Feb 15, 2023
57debaa
Add User Guide
ryanchua00 Feb 15, 2023
2d5afcd
Change photo in README
ryanchua00 Feb 15, 2023
6fa3281
Changed UI picture file name
ryanchua00 Feb 16, 2023
90d31b4
Changing name pt1
ryanchua00 Feb 16, 2023
d7d659b
Change Ui.png
ryanchua00 Feb 16, 2023
070aed0
Added picture to Docs folder
ryanchua00 Mar 4, 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
22 changes: 22 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Deadline extends Task{
private String deadline;
private char type = 'D';
public Deadline(String description, String date){
super(description);
this.deadline = date;
}
public void setDeadline(String date){
this.deadline = date;
}
public String getDeadline(){
return this.deadline;
}
@Override
public char getType() {
return type;
}
@Override
public String toString(){
return super.toString() + "(by: "+ deadline + ")";
}
}
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 @@
public class Event extends Task {
private String start;
private String end;
private char type = 'E';
public Event(String description, String start, String end) {
super(description);
this.start = start;
this.end = end;
}
public void setStart(String time){
this.start = time;
}
public void setEnd(String time){
this.end = time;
}
public String getStart(){
return this.start;
}
public String getEnd(){
return this.end;
}
@Override
public char getType() {
return type;
}
@Override
public String toString(){
return super.toString() + "(from: " + start + "to: " + end + ")";
}
}
192 changes: 192 additions & 0 deletions src/main/java/Roody.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
ryanchua00 marked this conversation as resolved.
Show resolved Hide resolved

public class Roody {
private ArrayList<Task> list;
private List<String> printBuffer;

public Roody(){
// Assumed no more than 100 tasks
this.list = new ArrayList<Task>();
this.printBuffer = new ArrayList<String>();
}

// Provides basic line
private void line() {
System.out.println("____________________________________________________________");
}

// Repeats the input
private void speak(String input) {
line();
System.out.println(input);
line();
}
private void speak(List<String> inputs) {
line();
inputs.forEach(x -> System.out.println(x));
line();
inputs.clear();
}

// Initial Greeting
public void greet() {
this.printBuffer.add("Hello, I'm Roody!");
this.printBuffer.add("What can I do for you?");
speak(this.printBuffer);
}

// final greeting
public void bye() {
speak("Bye. Hope to see you again soon!");
}

// Stores input to string
private void addToList(String input) {
String[] inputs = input.split("/");
Task task = new Todo(input.substring("todo ".length()));
char type = input.charAt(0);
if (type == 't') {
} else if (type == 'd') {
// more than one / detected,
if (inputs.length > 2) {
new RoodyException("I don't understand that. Don't use additonal \"/\" for deadlines.");
return;
} else {
task = new Deadline(inputs[0].substring("deadline ".length()), inputs[1].substring("by ".length()));
}
} else if (type == 'e') {
// more or less than two / detected,
if (inputs.length != 3) {
new RoodyException("I don't understand that. Don't use additonal \"/\" for events.");
return;
} else {
task = new Event(inputs[0].substring("event ".length()), inputs[1].substring("from ".length()), inputs[2].substring("to ".length()));
}
} else {
new RoodyException("Error, wrong input detected");
return;
}
list.add(task);
printBuffer.add("Got it. I've added this task:");
printBuffer.add(" [" + task.getType() +"][ ] " + task.toString());
printBuffer.add("Now you have " + list.size() + " tasks in the list.");
speak(printBuffer);
}

// Prints entire list in this.list
private void printList() {
int count = 0;
int listIndex = 0;
StringBuilder stringBuilder = new StringBuilder();
if (!list.isEmpty()) {
printBuffer.add("Here are the tasks in your list:");
while (count < list.size()) {

listIndex = count + 1;
stringBuilder.append(listIndex);
stringBuilder.append(".[");
// get type
stringBuilder.append(list.get(count).getType());
stringBuilder.append("][");
// if is done, set as 'X'
if (list.get(count).isDone()) {
stringBuilder.append("X] ");
// not done, set as ' '
} else {
stringBuilder.append(" ] ");
}
stringBuilder.append(list.get(count).toString());
printBuffer.add(stringBuilder.toString());

// Clears and updates values
stringBuilder.setLength(0);
count++;
}
speak(printBuffer);
} else {
new RoodyException("There doesn't seem to be any tasks in your list.");
}
}

// toggles completion status of tasks
private void complete(String index, boolean complete){
int taskIndex = Integer.parseInt(index) - 1;
if (taskIndex > list.size() - 1 || list.get(taskIndex) == null) {
new RoodyException("Sorry, that task doesn't exist");
} else {
Task task = list.get(taskIndex);
if (complete) {
task.setDone();
printBuffer.add("Nice! I've marked this task as done:");
printBuffer.add("["+ task.getType()+"][X] " + task.toString());
} else {
task.setUnDone();
printBuffer.add("OK, I've marked this task as not done yet:");
printBuffer.add("["+ task.getType()+"][ ] " + task.toString());
}
speak(printBuffer);
}
}

private void delete(String index) {
int taskIndex = Integer.parseInt(index) - 1;
if (taskIndex > list.size() - 1 || list.get(taskIndex) == null) {
new RoodyException("Sorry, that task doesn't exist");
} else {
Task task = list.get(taskIndex);
printBuffer.add("Noted. I've removed this task:");
printBuffer.add(" [" + task.getType() + "][ ] " + task.toString());
printBuffer.add("Now you have " + (list.size()-1) + " tasks in the list.");
speak(printBuffer);
list.remove(Integer.parseInt(index) - 1);
}
}

public static void main(String[] args){
Roody roody = new Roody();
// Sends initial greeting
roody.greet();
String input = "";
String[] inputs;
Scanner scanner = new Scanner(System.in);
// Loops until "bye" is input
while (true) {
System.out.print("=> ");
// Read input
input = scanner.nextLine();
inputs = input.toLowerCase().split("\\s", 0);
// If bye, break and print end message
if (inputs[0].equals("bye")) {
break;
// else, repeat
} else if (inputs[0].equals("list")) {
roody.printList();
} else if (inputs[0].equals("delete")) {
if (inputs.length == 2) {
roody.delete(inputs[1]);
} else {
new RoodyException("Please enter a index number to be deleted");
ryanchua00 marked this conversation as resolved.
Show resolved Hide resolved
}
// Checks for second input
} else if (inputs[0].equals("mark") || inputs[0].equals("unmark")) {
if (inputs.length == 2) {
roody.complete(inputs[1], inputs[0].equals("mark"));
} else {
new RoodyException("Please enter a index number to be marked/unmarked");
}
} else if (inputs[0].equals("todo") || inputs[0].equals("deadline") || inputs[0].equals("event")) {
if (inputs.length > 1) {
roody.addToList(input);
} else {
new RoodyException("Tasks require a description");
}
} else {
new RoodyException("I don't quite understand that.");
}
}
scanner.close();
roody.bye();
}
}
13 changes: 13 additions & 0 deletions src/main/java/RoodyException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class RoodyException{
private String message = "Oh no :( ";
public RoodyException(String s) {
this.message += s;
line();
System.out.println(this.message);
line();
}
// Provides basic line
private void line() {
System.out.println("____________________________________________________________");
}
}
24 changes: 24 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public abstract class Task {
private boolean done;
private String description;
public Task(String description) {
this.done = false;
this.description = description;
}
public boolean isDone() {
return this.done;
}
public void setDone() {
this.done = true;
}
public void setUnDone() {
this.done = false;
}
public char getType() {
return 'a';
}
@Override
public String toString(){
return this.description;
}
}
14 changes: 14 additions & 0 deletions src/main/java/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Todo extends Task {
private char type = 'T';
public Todo(String description){
super(description);
}
@Override
public char getType() {
return type;
}
@Override
public String toString(){
return super.toString() + "";
}
}
72 changes: 65 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,65 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

____________________________________________________________
Hello, I'm Roody!
What can I do for you?
____________________________________________________________
=> ____________________________________________________________
Got it. I've added this task:
[T][ ] JS2230 readings
Now you have 1 tasks in the list.
____________________________________________________________
=> ____________________________________________________________
Got it. I've added this task:
[E][ ] Japan Trip (from: January 25th to: February 2nd)
Now you have 2 tasks in the list.
____________________________________________________________
=> ____________________________________________________________
Got it. I've added this task:
[D][ ] Japan Admin (Mum) (by: Thursday)
Now you have 3 tasks in the list.
____________________________________________________________
=> ____________________________________________________________
Here are the tasks in your list:
1.[T][ ] JS2230 readings
2.[E][ ] Japan Trip (from: January 25th to: February 2nd)
3.[D][ ] Japan Admin (Mum) (by: Thursday)
____________________________________________________________
=> ____________________________________________________________
Nice! I've marked this task as done:
[E][X] Japan Trip (from: January 25th to: February 2nd)
____________________________________________________________
=> ____________________________________________________________
OK, I've marked this task as not done yet:
[D][ ] Japan Admin (Mum) (by: Thursday)
____________________________________________________________
=> ____________________________________________________________
Oh no :( Sorry, that task doesn't exist
____________________________________________________________
=> ____________________________________________________________
Got it. I've added this task:
[T][ ] Lunch
Now you have 4 tasks in the list.
____________________________________________________________
=> ____________________________________________________________
Here are the tasks in your list:
1.[T][ ] JS2230 readings
2.[E][X] Japan Trip (from: January 25th to: February 2nd)
3.[D][ ] Japan Admin (Mum) (by: Thursday)
4.[T][ ] Lunch
____________________________________________________________
=> ____________________________________________________________
Noted. I've removed this task:
[E][ ] Japan Trip (from: January 25th to: February 2nd)
Now you have 3 tasks in the list.
____________________________________________________________
=> ____________________________________________________________
Oh no :( Sorry, that task doesn't exist
____________________________________________________________
=> ____________________________________________________________
Here are the tasks in your list:
1.[T][ ] JS2230 readings
2.[D][ ] Japan Admin (Mum) (by: Thursday)
3.[T][ ] Lunch
____________________________________________________________
=> ____________________________________________________________
Bye. Hope to see you again soon!
____________________________________________________________
13 changes: 13 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
todo JS2230 readings
event Japan Trip /from January 25th /to February 2nd
deadline Japan Admin (Mum) /by Thursday
list
mark 2
unmark 3
mark 4
todo Lunch
list
delete 2
delete 4
list
bye
4 changes: 3 additions & 1 deletion text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ IF ERRORLEVEL 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
java -classpath ..\bin Roody < input.txt > ACTUAL.TXT

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

CMD /k