Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
98b0b8b
Level 1 complete
Jan 19, 2023
b286d41
Level 2 complete
Jan 19, 2023
29e0afb
Level 2 complete
Jan 19, 2023
1f85f96
Level 3 complete
Jan 19, 2023
0e983da
Level 4 complete
Jan 20, 2023
9039f8e
Level 5 complete
Jan 20, 2023
58c0f95
Level 5 complete
Jan 20, 2023
0c4a800
Level 6 complete
Jan 20, 2023
a3d3477
Complete Level 7
Feb 1, 2023
9b818a7
Complete Level 8
Feb 3, 2023
f6fda6f
Merge branch 'branch-level-7'
Feb 3, 2023
24786a7
Complete Level 8
Feb 3, 2023
4f67fd1
Resolve conflict between level 8 and master
Feb 3, 2023
cfb9c77
Complete A-MoreOOP
Feb 4, 2023
b678e36
Complete A-Packages
Feb 4, 2023
e7dbf2d
Merge branch 'add-gradle-support'
Feb 4, 2023
a5dd3ce
Complete A-Gradle
Feb 6, 2023
b16ac23
Complete A-JUnit
Feb 6, 2023
04c4fe7
Complete A-Jar
Feb 6, 2023
e18d496
Complete A-JavaDoc
Feb 6, 2023
217c71b
Complete A-CodingStandard
Feb 6, 2023
9846241
Complete Level-9
Feb 6, 2023
0f0592c
Complete level 10
Feb 19, 2023
7a5165e
Complete level 10
Feb 19, 2023
35f3de5
Complete A-Varargs
Feb 19, 2023
a3698bd
Add images
Feb 20, 2023
94aa96a
Complete A-Assertions
Feb 20, 2023
6fdfd7e
Complete A-CodeQuality
Feb 20, 2023
b0a88ed
Merge pull request #2 from Zhongli5712/branch-A-Assertions
Zhongli5712 Feb 20, 2023
10e8b1e
Merge branch 'master' into branch-A-CodeQuality
Feb 20, 2023
9ec8791
Merge pull request #3 from Zhongli5712/branch-A-CodeQuality
Zhongli5712 Feb 20, 2023
a352bac
Complete BCD-Exetension
Feb 20, 2023
c5c2081
Merge pull request #4 from Zhongli5712/branch-BCD-Extension
Zhongli5712 Feb 20, 2023
4ba6b4d
Fix some error
Feb 20, 2023
7db313a
Complete A-UserGuide
Feb 20, 2023
2e7d8bc
Trigger rebuild
Feb 20, 2023
68dc253
Fix Readme
Feb 20, 2023
f4f17f8
Make Duke compatible with Linux
Feb 28, 2023
4a64ff0
Update Readme.md
Mar 2, 2023
1a8a463
Update README.md
Zhongli5712 Mar 2, 2023
4692bc5
Update README.md
Zhongli5712 Mar 7, 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
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.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 @@ -13,7 +13,7 @@ Prerequisites: JDK 11, update Intellij to the most recent version.
1. If there are any further prompts, accept the defaults.
1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).<br>
In the same dialog, set the **Project language level** field to the `SDK default` option.
3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output:
3. After that, locate the `src/main/java/duke.Duke.java` file, right-click it, and choose `Run duke.Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output:
```
Hello from
____ _
Expand Down
Binary file added src/main/ToDoListCS2103.txt
Binary file not shown.
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

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

import duke.command.Command;

public class Duke {
private Ui ui;

public Duke() {
this.ui = new Ui();
}

private void run() {
ui.begin();

Storage storage = new Storage();
TodoList todoList = storage.load();

Parser bot = new Parser(todoList);

String input = ui.readCommand();

while (!input.equals("bye")) {
try {
Command command = bot.parse(input);
command.execute();
} catch (DukeExceptions error) {
System.out.println(error.getErrorMessage());
}
ui.showLine();
input = ui.readCommand();; //ready for next input
}
storage.save(todoList);
ui.bye();
}

public static void main(String[] args) {
new Duke().run();
}
}
12 changes: 12 additions & 0 deletions src/main/java/duke/DukeExceptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package duke;

public class DukeExceptions extends Exception{

Choose a reason for hiding this comment

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

While the class name is valid according to coding standards, perhaps it would be more intuitive if it was named DukeException instead since it only represents an instance of 1 Exception

private String error;
public DukeExceptions(String error) {
this.error = error;
}

public String getErrorMessage() {
return this.error;
}
}
88 changes: 88 additions & 0 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package duke;

import duke.command.*;

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

/**
* Parse the command
*
*/
public class Parser {
private TodoList todoList;

private enum Instructions {todo, deadline, event, mark, unmark, delete}

public Parser(TodoList todoList) {
this.todoList = todoList;
}

public Command parse(String command) throws DukeExceptions {
String[] split_command = command.split(" ", 2);
String instruction = split_command[0];

if (instruction.equals("list")) {
if (split_command.length == 1) {
return new ListCommand(todoList);
} else {
throw new DukeExceptions("OOPS!!! The description of a list cannot have other parameters");
}
}

//check for valid instructions
for (Instructions validInstruction : Instructions.values()) {
if (validInstruction.name().equals(instruction)) {
if (split_command.length == 1) {
throw new DukeExceptions(String.format("OOPS!!! The description of a %s cannot be empty.", instruction));
} else if (instruction.equals("mark")) {
int digit = Integer.parseInt(split_command[1]);
return new MarkCommand(todoList, digit);
} else if (instruction.equals("unmark")) {
int digit = Integer.parseInt(split_command[1]);
return new UnmarkCommand(todoList, digit);
} else if (instruction.equals("delete")) {
int digit = Integer.parseInt(split_command[1]);
return new DeleteCommand(todoList, digit);
} else {
return new AddTaskCommand(todoList, instruction, split_command[1]);
}
}
}
throw new DukeExceptions("OOPS!!! I'm sorry, but I don't know what that means.");
}

public static LocalDate parseDate(String[] possibleDateTime) throws DateTimeParseException {
try {
//parse date
LocalDate possibleDeadlineDate = LocalDate.parse(possibleDateTime[0]);
return possibleDeadlineDate;
} catch (DateTimeParseException ex) {
//can not parse date
return null;
}
}

public static String parseStringDate(LocalDate possibleDeadlineDate) {
return possibleDeadlineDate.format(DateTimeFormatter.ofPattern("MMM d yyyy"));
}

public static LocalTime parseTime(String[] possibleDateTime) throws DateTimeParseException {
try {
//parse date
LocalTime possibleDeadlineTime = (possibleDateTime.length == 1)
? LocalTime.parse(possibleDateTime[0])
: LocalTime.parse(possibleDateTime[1]);
return possibleDeadlineTime;
} catch (DateTimeParseException ex) {
//can not parse date
return null;
}
}

public static String parseStringTime(LocalTime possibleDeadlineTime) {
return possibleDeadlineTime.format(DateTimeFormatter.ofPattern("hh:mm a"));
}
}
52 changes: 52 additions & 0 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package duke;

import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* Represents a storage that load previous to do list and save current to do list.
*/

public class Storage {
private Path path;
private boolean doesDirectoryExist;

public Storage() {
this.path = Paths.get(".", "src", "main", "ToDoListCS2103.txt");
this.doesDirectoryExist = java.nio.file.Files.exists(path);
}

public TodoList load() {
try {
File previousToDoList = new File(path.toString());
if (doesDirectoryExist) {
FileInputStream fis = new FileInputStream(previousToDoList);
ObjectInputStream ois = new ObjectInputStream(fis);
TodoList savedTodoList = (TodoList) ois.readObject();
ois.close();
fis.close();
return savedTodoList;
} else {
previousToDoList.createNewFile();
return new TodoList();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return new TodoList();
}

public void save(TodoList todoList) {
try{
FileOutputStream fos = new FileOutputStream(path.toFile());
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(todoList);
oos.flush();
oos.close();
fos.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Loading