Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bc8574a
Added greeting and bye print
wgzesg Aug 19, 2020
f069a86
Complete Level 1 requirement
wgzesg Aug 22, 2020
31cc798
Complete Level 2
wgzesg Aug 22, 2020
69b2449
Complete Level 3
wgzesg Aug 22, 2020
d0797b2
Updated Level 3
wgzesg Aug 28, 2020
a9bc85c
Updated Level 3
wgzesg Aug 29, 2020
1b47ef3
Complete Level-4
wgzesg Aug 29, 2020
52dbb5b
Complete testing and improve code quality
wgzesg Aug 29, 2020
9516fee
Complete testing and improve code quality
wgzesg Sep 4, 2020
d3ce565
Rename the classes so it makes more sense
wgzesg Sep 4, 2020
69aa960
Repackage classes to enhance readability
wgzesg Sep 5, 2020
6df6e68
Add error handling to resolve invalid user inputs
wgzesg Sep 6, 2020
65b00e5
Repackage the classes. Run testing with updated source address.
wgzesg Sep 6, 2020
e769120
Formatted all script to follow coding standard
wgzesg Sep 6, 2020
9f7c1db
Merge branch 'branch-Level-5'
wgzesg Sep 6, 2020
0b97510
Add "delete" command to duke
wgzesg Sep 12, 2020
2fabfbd
Create local storage. Allow save and load.
wgzesg Sep 14, 2020
4b08fa3
Merge branch 'branch-Level-6'
wgzesg Sep 14, 2020
fbe3b0d
Redo merge
wgzesg Sep 14, 2020
aad39f4
Merge conflict Level-6
wgzesg Sep 14, 2020
3e9e56f
Merge conflict Level-6
wgzesg Sep 14, 2020
666409c
Merge with Level-7
wgzesg Sep 14, 2020
5fbe171
fixing format
wgzesg Sep 16, 2020
00e0cdb
Clean up based on pull request feedback
wgzesg Sep 20, 2020
180ef7a
Complete date parser
wgzesg Sep 21, 2020
c6c6fc9
Complete "find" and "doneby" command which allows simple search base…
wgzesg Sep 21, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ bin/

/text-ui-test/ACTUAL.txt
text-ui-test/EXPECTED-UNIX.TXT
*.json
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Duke project template
# duke.core.Duke project template

This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it.

Expand All @@ -15,7 +15,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version.
1. Click `Open or Import`.
1. Select the project directory, and click `OK`
1. If there are any further prompts, accept the defaults.
1. After the importing is complete, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()`. If the setup is correct, you should see something like the below:
1. After the importing is complete, locate the `src/main/java/duke.core.Duke.java` file, right-click it, and choose `Run duke.core.Duke.main()`. If the setup is correct, you should see something like the below:
```
Hello from
____ _
Expand Down
8 changes: 8 additions & 0 deletions data/storage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"at": "sss",
"type": "Events",
"taskName": "aa",
"isDone": false
}
]
Binary file added lib/gson-2.8.6.jar
Binary file not shown.
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

3 changes: 3 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: duke.core.Duke

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

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class DateParser {

private static final List<DateTimeFormatter> dtformaters = Arrays.asList(
DateTimeFormatter.ofPattern("yyyyMMdd HH:mm"),
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"),
DateTimeFormatter.ofPattern("yyyy MM dd HH:mm"),
DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm"),
DateTimeFormatter.ofPattern("yyyyMMdd HHmm"),
DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm"),
DateTimeFormatter.ofPattern("yyyy MM dd HHmm"),
DateTimeFormatter.ofPattern("yyyy/MM/dd HHmm"));

private static final List<DateTimeFormatter> dformaters = Arrays.asList(
DateTimeFormatter.ofPattern("yyyyMMdd"),
DateTimeFormatter.ofPattern("yyyy/MM/dd"),
DateTimeFormatter.ofPattern("yyyy-MM-dd"),
DateTimeFormatter.ofPattern("yyyy MM dd"));

public static LocalDateTime parseDate(String command) throws DateTimeParseException {
for(DateTimeFormatter dtf : dtformaters) {
try {
return LocalDateTime.parse(command, dtf);
} catch (DateTimeParseException e) {
}
}

for(DateTimeFormatter dtf : dformaters) {
try {
return LocalDate.parse(command, dtf).atStartOfDay();
} catch (DateTimeParseException e) {
}
}

return null;
}
}
12 changes: 12 additions & 0 deletions src/main/java/duke/commands/AddDeadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package duke.commands;

import duke.storage.Database;

public class AddDeadline extends Command {
@Override
public int execute() {
Database.addDeadline(args);
clearArgs();
return 0;
}
}
12 changes: 12 additions & 0 deletions src/main/java/duke/commands/AddEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package duke.commands;

import duke.storage.Database;

public class AddEvent extends Command {
@Override
public int execute() {
Database.addEvent(args);
clearArgs();
return 0;
}
}
12 changes: 12 additions & 0 deletions src/main/java/duke/commands/AddTodo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package duke.commands;

import duke.storage.Database;

public class AddTodo extends Command {
@Override
public int execute() {
Database.addToDo(args);
clearArgs();
return 0;
}
}
13 changes: 13 additions & 0 deletions src/main/java/duke/commands/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package duke.commands;

abstract public class Command {
public String args;

public int execute() {
return 0;
}

public void clearArgs() {
args = null;
}
}
13 changes: 13 additions & 0 deletions src/main/java/duke/commands/Delete.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package duke.commands;

import duke.storage.Database;

public class Delete extends Command{

@Override
public int execute() {
Database.delete(args);
clearArgs();
return 0;
}
}
13 changes: 13 additions & 0 deletions src/main/java/duke/commands/DoneBy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package duke.commands;

import duke.storage.Database;

public class DoneBy extends Command{

@Override
public int execute() {
Database.doneBy(args);
clearArgs();
return 0;
}
}
13 changes: 13 additions & 0 deletions src/main/java/duke/commands/Find.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package duke.commands;

import duke.storage.Database;

public class Find extends Command{

@Override
public int execute() {
Database.find(args);
clearArgs();
return 0;
}
}
13 changes: 13 additions & 0 deletions src/main/java/duke/commands/ListAll.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package duke.commands;


import duke.storage.Database;

public class ListAll extends Command {
@Override
public int execute() {
Database.listAll();
clearArgs();
return 0;
}
}
18 changes: 18 additions & 0 deletions src/main/java/duke/commands/MarkDone.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package duke.commands;

import duke.storage.Database;

public class MarkDone extends Command {
@Override
public int execute() {
try {
Database.markDone(args);
clearArgs();
} catch (NumberFormatException e) {
System.out.println("The index given is not a number.");
} catch (IndexOutOfBoundsException e) {
System.out.println("The index is out of range. You don't have a task at that number.");
}
return 0;
}
}
14 changes: 14 additions & 0 deletions src/main/java/duke/commands/PrintBye.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package duke.commands;

import duke.storage.Database;

public class PrintBye extends Command {
@Override
public int execute() {

Database.handleBye();

clearArgs();
return -1;
}
}
62 changes: 62 additions & 0 deletions src/main/java/duke/core/CommandLib.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package duke.core;

import duke.commands.*;
import duke.exceptions.NullArgumentException;

import java.util.HashMap;

public class CommandLib {
private final HashMap<String, Command> commandMap = new HashMap<>();

public CommandLib() {
// Initialise the map with all possible duke.commands
MarkDone markDone = new MarkDone();
this.register(Constants.DONE_CMD, markDone);
AddTodo addTodo = new AddTodo();
this.register(Constants.TODO_CMD, addTodo);
AddDeadline addDeadline = new AddDeadline();
this.register(Constants.DEADLINE_CMD, addDeadline);
AddEvent addEvent = new AddEvent();
this.register(Constants.EVENT_CMD, addEvent);
ListAll listAll = new ListAll();
this.register(Constants.LIST_CMD, listAll);
PrintBye printBye = new PrintBye();
this.register(Constants.BYE_CMD, printBye);
Delete delete = new Delete();
this.register(Constants.DELETE_CMD, delete);
Find find = new Find();
this.register(Constants.FIND_CMD , find);
DoneBy doneBy = new DoneBy();
this.register(Constants.DONEBY_CMD , doneBy);
}

public void register(String commandName, Command command) {
commandMap.put(commandName, command);
}

public int execute(String cmd) {

String[] args = cmd.split(" ", 2);
Command command = commandMap.get(args[0]);

try {
command.args = args[1];
} catch (NullPointerException e) {
System.out.println("Oops, the command is not recognised!");
return 0;
} catch (ArrayIndexOutOfBoundsException e) {}

int result = 0;
try {
result = command.execute();
} catch (NullArgumentException e) {
System.out.println(e.getMessage());
} catch (NullPointerException e) {
System.out.println("Oops, the command is not recognised!");
}

return result;
}
}


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

public class Constants {
public static final String DONE_CMD = "done";
public static final String TODO_CMD = "todo";
public static final String DEADLINE_CMD = "deadline";
public static final String EVENT_CMD = "event";
public static final String LIST_CMD = "list";
public static final String BYE_CMD = "bye";
public static final String DELETE_CMD = "delete";
public static final String FIND_CMD = "find";
public static final String DONEBY_CMD = "doneby";

public static final String BY_PARSER = " /by ";
public static final String AT_PARSER = " /at ";

public static final String SEPLINE = "------------------------------------------";
public static final String TICK = "\u2713";
public static final String CROSS = "\u2718";
public static final String FILEPATH = "data/storage.json";

public static final String LOGO = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";

public static final int DESCRIPTION = 0;
public static final int TIME = 1;
}
Loading