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

[brvndonkoh] iP #308

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
10 changes: 10 additions & 0 deletions src/main/java/BigBoy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class BigBoy {
public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
}
}
97 changes: 97 additions & 0 deletions src/main/java/Clarawr.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import java.util.Scanner;
import java.util.ArrayList;

public class Clarawr {
static ArrayList<Task> tasks = new ArrayList<>();

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

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

String instruction = scanner.nextLine();

while (!instruction.equalsIgnoreCase("bye")) {
try {
if (instruction.equalsIgnoreCase("list")) {
if (tasks.isEmpty()) {
System.out.println("No tasks in your list.");
} else {
System.out.println("Here are the tasks in your list:");
for (int i = 0; i < tasks.size(); i++) {
System.out.println((i + 1) + "." + tasks.get(i));
}
}
} else if (instruction.startsWith("todo")) {
String description = instruction.substring(4).trim();
if (description.isEmpty()) {
throw new ClarawrException("The description of a todo task cannot be empty.");
}
tasks.add(new Todo(description));
System.out.println("Got it, I've added this task: ");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
} else if (instruction.startsWith("deadline")) {
String[] parts = instruction.substring(8).split(" /by ");
if (parts.length < 2 || parts[0].isEmpty() || parts[1].isEmpty()) {
throw new ClarawrException("The description and deadline of a task cannot be empty.");
}
tasks.add(new Deadline(parts[0], parts[1]));
System.out.println("Got it, I've added this task: ");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
} else if (instruction.startsWith("event")) {
String[] parts = instruction.substring(5).split(" /from ");
if (parts.length < 2) {
throw new ClarawrException("The description and timing of an event cannot be empty.");
}
String[] times = parts[1].split(" /to ");
if (times.length < 2 || parts[0].isEmpty() || times[0].isEmpty() || times[1].isEmpty()) {
throw new ClarawrException("The description and both event times cannot be empty.");
}
tasks.add(new Event(parts[0], times[0], times[1]));
System.out.println("Got it, I've added this task: ");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
} else if (instruction.startsWith("mark ")) {
int index = Integer.parseInt(instruction.split(" ")[1]) - 1;
if (index >= 0 && index < tasks.size()) {
tasks.get(index).markAsDone();
System.out.println("Nice! I've marked this task as done:");
System.out.println(" " + tasks.get(index));
} else {
System.out.println("Invalid task number! Please try again.");
}
} else if (instruction.startsWith("unmark ")) {
int index = Integer.parseInt(instruction.split(" ")[1]) - 1;
if (index >= 0 && index < tasks.size()) {
tasks.get(index).markUndone();
System.out.println("OK, I've marked this task as not done yet:");
System.out.println(" " + tasks.get(index));
} else {
System.out.println("Invalid task number! Please try again.");
}
} else if (instruction.startsWith("delete ") || instruction.startsWith("remove ")) {
int index = Integer.parseInt(instruction.split(" ")[1]) - 1;
if (index >= 0 && index < tasks.size()) {
Task taskToDelete = tasks.remove(index);
System.out.println("Noted. I've removed this task: ");
System.out.println(" " + taskToDelete);
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
} else {
System.out.println("Invalid task number! Please try again.");
}
} else {
System.out.println("Sorry I do not understand your instruction :(");
}
} catch (ClarawrException e) {
System.out.println(e.getMessage());
}
instruction = scanner.nextLine();
}

System.out.println("Bye. Hope to see you again soon!");
scanner.close();
}
}
6 changes: 6 additions & 0 deletions src/main/java/ClarawrException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class ClarawrException extends Exception {

public ClarawrException(String message) {
super(message);
}
}
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 by;

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

@Override
public String toString() {
return " [D]" + super.toString() + " (by: " + by + ")";
}
}
16 changes: 16 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
public class Event extends Task {

protected String from;
protected String to;

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

@Override
public String toString() {
return " [E]" + super.toString() + " (from: " + from + " to: " + to + ")";
}
}
20 changes: 20 additions & 0 deletions src/main/java/Level_1/Clarawr.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package Level_1;
import java.util.Scanner;

public class Clarawr {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Hello! I'm Clarawr\n"
+ "What can I do for you?");

String instruction = scanner.nextLine();

while (!instruction.equalsIgnoreCase("bye")) { // Check for "bye" (case-insensitive)
System.out.println(instruction); // Repeat the input
instruction = scanner.nextLine(); // Read the next input
}

System.out.println("Bye. Hope to see you again soon!");
scanner.close(); // Close the scanner
}
}
25 changes: 25 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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 markAsDone() {
this.isDone = true;
}

public void markUndone() {
this.isDone = false;
}

public String toString() {
return "[" + getStatusIcon() + "] " + 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();
}
}
57 changes: 50 additions & 7 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
Hello from
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|

Hello! I'm Clarawr
What can I do for you?
Got it, I've added this task:
[T][ ] revise CS2106
Now you have 1 tasks in the list.
Got it, I've added this task:
[D][ ] CS2103 (by: Fri 4pm)
Now you have 2 tasks in the list.
Got it, I've added this task:
[E][ ] internship interview (from: Mon 4pm to: Mon 5pm)
Now you have 3 tasks in the list.
Here are the tasks in your list:
1. [T][ ] revise CS2106
2. [D][ ] CS2103 (by: Fri 4pm)
3. [E][ ] internship interview (from: Mon 4pm to: Mon 5pm)
Got it, I've added this task:
[T][ ] dinner with parents
Now you have 4 tasks in the list.
Here are the tasks in your list:
1. [T][ ] revise CS2106
2. [D][ ] CS2103 (by: Fri 4pm)
3. [E][ ] internship interview (from: Mon 4pm to: Mon 5pm)
4. [T][ ] dinner with parents
Nice! I've marked this task as done:
[T][X] dinner with parents
Nice! I've marked this task as done:
[E][X] internship interview (from: Mon 4pm to: Mon 5pm)
Here are the tasks in your list:
1. [T][ ] revise CS2106
2. [D][ ] CS2103 (by: Fri 4pm)
3. [E][X] internship interview (from: Mon 4pm to: Mon 5pm)
4. [T][X] dinner with parents
Invalid task number! Please try again.
Nice! I've marked this task as done:
[T][X] revise CS2106
Nice! I've marked this task as done:
[D][X] CS2103 (by: Fri 4pm)
Here are the tasks in your list:
1. [T][X] revise CS2106
2. [D][X] CS2103 (by: Fri 4pm)
3. [E][X] internship interview (from: Mon 4pm to: Mon 5pm)
4. [T][X] dinner with parents
OK, I've marked this task as not done yet:
[D][ ] CS2103 (by: Fri 4pm)
Here are the tasks in your list:
1. [T][X] revise CS2106
2. [D][ ] CS2103 (by: Fri 4pm)
3. [E][X] internship interview (from: Mon 4pm to: Mon 5pm)
4. [T][X] dinner with parents
Bye. Hope to see you again soon!
16 changes: 16 additions & 0 deletions text-ui-test/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
todo revise CS2106
deadline CS2103 /by Fri 4pm
event internship interview /from Mon 4pm /to Mon 5pm
list
todo dinner with parents
list
mark 4
mark 3
list
mark 5
mark 1
mark 2
list
unmark 2
list
bye
18 changes: 13 additions & 5 deletions text-ui-test/runtest.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ REM create bin directory if it doesn't exist
if not exist ..\bin mkdir ..\bin

REM delete output from previous run
if exist ACTUAL.TXT 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
) ELSE (
echo Build OK!
)
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 Clarawr < input.txt > ACTUAL.TXT

REM compare the output to the expected output, ignoring white space differences
FC /L /W ACTUAL.TXT EXPECTED.TXT

REM compare the output to the expected output
FC ACTUAL.TXT EXPECTED.TXT
REM Check if FC found a difference
IF ERRORLEVEL 1 (
echo Something is wrong! Files do not match.
) ELSE (
echo Yes! All the files are the same. Test passed! :D
)