Skip to content

Commit

Permalink
Second week work
Browse files Browse the repository at this point in the history
  • Loading branch information
yulonglim committed Aug 25, 2021
1 parent c6600c4 commit ec68756
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 135 deletions.
Binary file added src/JarFolder/Duke.jar
Binary file not shown.
7 changes: 0 additions & 7 deletions src/main/java/DukeException.java

This file was deleted.

45 changes: 0 additions & 45 deletions src/main/java/TaskList.java

This file was deleted.

26 changes: 0 additions & 26 deletions src/main/java/Ui.java

This file was deleted.

15 changes: 12 additions & 3 deletions src/main/java/Deadline.java → src/main/java/duke/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package duke;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Deadline extends Task{
/**
* class that extends task
* labelled with an extra [D] when called
* stores the date which task should be done by
*/
public class Deadline extends Task {
protected LocalDate date;

public Deadline(String description, String by) {
super(description);
if(by.contains("/")) {
date = LocalDate.parse(by.split("/")[2] + "-" + by.split("/")[1] + "-" + (Integer.parseInt(by.split("/")[0]) < 10 ? "0" + by.split("/")[0] : by.split("/")[0]));
if (by.contains("/")) {
date = LocalDate.parse(by.split("/")[2] + "-" + by.split("/")[1] + "-"
+ (Integer.parseInt(by.split("/")[0]) < 10 ? "0" + by.split("/")[0] :
by.split("/")[0]));
} else {
date = LocalDate.parse(by);
}
Expand Down
31 changes: 21 additions & 10 deletions src/main/java/Duke.java → src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import java.io.IOException;
import java.util.*;
package duke;

import java.io.IOException;
import java.util.Scanner;

/**
* Duke class
* Uses storage class to gather data from text file
* When run, parses input into parser class which utilizes ui class to give an output
* After each command it saves to the storage text file
*/
public class Duke {


private Storage storage;
private final Storage storage;
private final Ui ui;
private TaskList tasks;
private Ui ui;

public Duke(String filePath) {
ui = new Ui();
Expand All @@ -21,12 +28,20 @@ public Duke(String filePath) {
}
}

public static void main(String[] args) throws IOException {
new Duke("C:\\Users\\65906\\IdeaProjects\\ip\\duke.txt").run();
}

/**
* Starts the duke bot
*
* @throws IOException
*/
private void run() throws IOException {
ui.showWelcome();
Parser duke = new Parser(this.tasks);
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()) {
while (sc.hasNextLine()) {
ui.showLine();
String str = sc.nextLine();
duke.parse(str);
Expand All @@ -37,9 +52,5 @@ private void run() throws IOException {

}

public static void main(String[] args) throws IOException {
new Duke("C:\\Users\\65906\\IdeaProjects\\ip\\duke.txt").run();
}


}
9 changes: 9 additions & 0 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package duke;

public class DukeException extends Exception {
private final String description;

DukeException(String description) {
this.description = description;
}
}
33 changes: 33 additions & 0 deletions src/main/java/duke/DukeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package duke;

import org.junit.jupiter.api.Assertions;
import org.testng.annotations.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class DukeTest {
@Test
public void dummyTest() {
Assertions.assertEquals(2, 2);
}

@Test
public void toDoTest() {
Task test = new Todo("return book");
assertEquals("[T][ ] return book", test.toString());
}

@Test
public void toDoTest2() {
Task test = new Todo("return book");
test.markAsDone();
assertEquals("[T][X] return book", test.toString());
}

@Test
public void EventTest() {
Task test = new Event("bomb world trade center", "11/09/2001");
test.markAsDone();
assertEquals("[E][X] bomb world trade center (at:Sep 11 2001)", test.toString());
}
}
15 changes: 12 additions & 3 deletions src/main/java/Event.java → src/main/java/duke/Event.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package duke;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Event extends Task{
/**
* class that extends task
* labelled with an extra [E] when called
* stores the date which task should occur
*/
public class Event extends Task {
protected LocalDate date;

public Event(String description, String at) {
super(description);
if(at.contains("/")) {
date = LocalDate.parse(at.split("/")[2] + "-" + at.split("/")[1] + "-" + (Integer.parseInt(at.split("/")[0]) < 10 ? "0" + at.split("/")[0] : at.split("/")[0]));
if (at.contains("/")) {
date = LocalDate.parse(at.split("/")[2] + "-" + at.split("/")[1] + "-" +
(Integer.parseInt(at.split("/")[0]) < 10 ? "0" + at.split("/")[0] :
at.split("/")[0]));
} else {
date = LocalDate.parse(at);
}
Expand Down
46 changes: 24 additions & 22 deletions src/main/java/Parser.java → src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package duke;

/**
* Class which converts user command to functions
*/
public class Parser {

final private TaskList taskList;
Expand All @@ -6,53 +11,50 @@ public Parser(TaskList taskList) {
this.taskList = taskList;
}

public void parse(String input){
/**
* Takes in the user input and run functions that are associated with the input
*
* @param input String which the user inputs
*/
public void parse(String input) {
if (input.equalsIgnoreCase("bye")) {
System.out.println("Bye. Hope to see you again soon!");

}

else if (input.equalsIgnoreCase("list")){
} else if (input.equalsIgnoreCase("list")) {
taskList.showTasks();
}

else if (input.contains("done")){
} else if (input.contains("done")) {
int index = Integer.parseInt(input.split(" ")[1]) - 1;
taskList.markAsDone(index);
System.out.println("Nice! I've marked this task as done:\n" + taskList.getTask(index).description);
}

else if(input.contains("delete")){
} else if (input.contains("delete")) {
int index = Integer.parseInt(input.split(" ")[1]) - 1;
Task removedTask = taskList.getTask(index);
System.out.println("Noted. I've removed this task:\n" + removedTask.toString() + "\nNow you have " + taskList.size() + " tasks in the list.");
taskList.removeTask(index);
}

else if (input.contains("todo") || input.contains("deadline") || input.contains("event")){
} else if (input.contains("todo") || input.contains("deadline") || input.contains("event")) {
Task newTask = new Task("null");
try {
if(input.contains("todo")){
newTask = new Todo(input.split(" ",2)[1]);
if (input.contains("todo")) {
newTask = new Todo(input.split(" ", 2)[1]);
}
if(input.contains("deadline")) {
newTask = new Deadline(input.split("/by")[0].split(" ",2)[1],input.split("/by ")[1]);
if (input.contains("deadline")) {
newTask = new Deadline(input.split("/by")[0].split(" ", 2)[1], input.split("/by ")[1]);
}
if (input.contains("event")) {
newTask = new Event(input.split("/at")[0].split(" ",2)[1],input.split("/at ")[1]);
newTask = new Event(input.split("/at")[0].split(" ", 2)[1], input.split("/at ")[1]);
}
taskList.addTask(newTask);
System.out.println("Got it. I've added this task:\n" + newTask + "\nNow you have " + taskList.size() + " tasks in the list.");

} catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) {
System.out.println("OOPS!!! your description is not complete or is in a wrong format");
}
}
else {
System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-(" );
} else if(input.split(" ")[0].equalsIgnoreCase("find")) {
taskList.findTask(input.split(" ")[1]);
} else {
System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-(");
}
}



}
Loading

0 comments on commit ec68756

Please sign in to comment.