Skip to content
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
28ad2b8
Add Gradle support
May 24, 2020
ed6d4d2
Bump gradle and lib version
Eclipse-Dominator Aug 5, 2023
376c1ce
Level-0
SinhaVedant Aug 24, 2023
0732b2b
Level-1
SinhaVedant Aug 24, 2023
f68b343
Level-2
SinhaVedant Aug 24, 2023
27b6769
Level-3
SinhaVedant Aug 24, 2023
5893c75
Level-4
SinhaVedant Aug 24, 2023
c36b93a
A-TextUiTesting
SinhaVedant Aug 24, 2023
a5b63ad
Level-5
SinhaVedant Aug 24, 2023
7574be3
Level-6
SinhaVedant Aug 24, 2023
a6c3d8e
Improve text UI
SinhaVedant Sep 7, 2023
fc4e137
Level-7
SinhaVedant Sep 7, 2023
6277d7a
Merge branch 'branch-Level-7'
SinhaVedant Sep 7, 2023
a942795
Level-8
SinhaVedant Sep 7, 2023
d9b68b9
Merge branch 'branch-Level-8'
SinhaVedant Sep 7, 2023
d4fd725
A-MoreOOP
SinhaVedant Sep 7, 2023
2c11281
A-Packages
SinhaVedant Sep 7, 2023
3ef321f
A-Gradle
SinhaVedant Sep 7, 2023
2570bf9
A-JUnit
SinhaVedant Sep 7, 2023
5794d91
A-Jar
SinhaVedant Sep 7, 2023
1cc9b66
A-JavaDoc
SinhaVedant Sep 7, 2023
296495b
A-CodingStandard
SinhaVedant Sep 7, 2023
d673212
Level-9
SinhaVedant Sep 7, 2023
cdb5f1a
Merge branch 'branch-A-JavaDoc'
SinhaVedant Sep 7, 2023
7d946a4
Resolve A-CodingStandard Conflict
SinhaVedant Sep 7, 2023
9d019e5
Resolve Level-9 Conflict
SinhaVedant Sep 7, 2023
ceecb31
Level-10
SinhaVedant Sep 8, 2023
ace54d8
Merge branch 'branch-Level-10'
SinhaVedant Sep 8, 2023
eb44458
Add full commit message
SinhaVedant Sep 15, 2023
e6cc044
Use assert feature
SinhaVedant Sep 15, 2023
33deb12
Improve code quality
SinhaVedant Sep 15, 2023
095f541
Merge pull request #1 from SinhaVedant/branch-A-Assertions
SinhaVedant Sep 15, 2023
0bd78ca
Resolve merge conflict
SinhaVedant Sep 15, 2023
7d9ea7a
Merge pull request #2 from SinhaVedant/branch-A-CodeQuality
SinhaVedant Sep 22, 2023
026c221
Commit changes in duke txt file
SinhaVedant Sep 22, 2023
37ad6dd
Merge branch 'master' into branch-A-CodeQuality
SinhaVedant Sep 22, 2023
32e34a6
Add a brief User Guide (UG)
SinhaVedant Sep 22, 2023
0865487
Merge branch 'master' into branch-Level-8
SinhaVedant Sep 24, 2023
9939560
Update deadline date format
SinhaVedant Sep 24, 2023
a8d5455
Merge branch 'branch-Level-8'
SinhaVedant Sep 24, 2023
756f992
Test the latest update in master branch
SinhaVedant Sep 24, 2023
e887e87
Update Ui.java file
SinhaVedant Sep 24, 2023
2776539
Update Storage.java file
SinhaVedant Sep 24, 2023
9f74420
Update parser class
SinhaVedant Sep 24, 2023
ef7f6fb
Implement better OOP
SinhaVedant Sep 24, 2023
e1a8c5d
Merge branch 'branch-A-MoreOOP'
SinhaVedant Sep 24, 2023
3045fb4
Merge branch 'add-gradle-support'
SinhaVedant Sep 24, 2023
dac21a2
Add test-cases for Storage and Parser classes
SinhaVedant Sep 25, 2023
b3a9246
Create a jar file
SinhaVedant Sep 25, 2023
ff5848c
Complete tutorial of GUI
SinhaVedant Sep 25, 2023
d648e07
Complete GUI for the project
SinhaVedant Sep 25, 2023
9d6be40
Merge branch 'GUI'
SinhaVedant Sep 25, 2023
a7ba89a
Add assertions to the code
SinhaVedant Sep 25, 2023
aee1430
Add JavaDoc to some classes and methods
SinhaVedant Sep 25, 2023
aaabd4b
Add screenshot of ip project
SinhaVedant Sep 25, 2023
a0078c7
Update the user guide
SinhaVedant Sep 25, 2023
5c9b926
Create final jar file
SinhaVedant Sep 25, 2023
2c0fc4c
Set mainClass to duke.Launcher
SinhaVedant Sep 28, 2023
69cedb8
Improve code quality
SinhaVedant Sep 28, 2023
9609ab4
Merge branch 'improve'
SinhaVedant Sep 28, 2023
fb64bd2
Improve Ui
SinhaVedant Sep 28, 2023
9803c2b
Update Storage class to create a new file
SinhaVedant Sep 28, 2023
1e3472f
Merge branch 'improve'
SinhaVedant Sep 28, 2023
f9eb6b9
Update JavaDocs
SinhaVedant Sep 28, 2023
87520d1
Improve GUI of Sivraj
SinhaVedant Sep 28, 2023
ed11395
Merge branch 'gui2'
SinhaVedant Sep 28, 2023
125f802
Resolve merge conflict
SinhaVedant Sep 28, 2023
ec30bc1
Merge pull request #4 from SinhaVedant/branch-A-CodeQuality
SinhaVedant Sep 28, 2023
7987ed9
Improve JavaDoc
SinhaVedant Sep 28, 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:
Copy link

Choose a reason for hiding this comment

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

I believe this is a typo that might've been introduced by IntelliJ's auto-refactoring process?

```
Hello from
____ _
Expand Down
6 changes: 6 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
T | 1 | jog
D | 0 | return book | Sunday
E | 0 | project meeting | Mon 2pm-4pm
T | 0 | fly
E | 0 | project meeting | Mon 2pm-4pm
T | 0 | sleep
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

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

public class Deadline extends Task {
protected String by;

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

@Override
public String toFileString() {
return super.toFileString() + " | " + by;
}

@Override
public String toString() {
return super.toString() + " (by: " + by + ")";
}
}
218 changes: 218 additions & 0 deletions src/main/java/duke/Duke.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
package duke;


import java.util.Scanner;
import java.util.ArrayList;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;


public class Duke {
Copy link

Choose a reason for hiding this comment

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

It would be good to add header comments to public classes

private static final String FILE_PATH = "./data/duke.txt";
private static final ArrayList<Task> taskList = new ArrayList<>();

public static void main(String[] args) {

try {
loadPreviousTasks(FILE_PATH);
} catch (FileNotFoundException e) {
System.out.println("File not found");
}

Scanner scanner = new Scanner(System.in);

// Greeting message
System.out.println("Hello! I'm Sivraj");
System.out.println("What can I do for you?");

while (true) {
String echo = scanner.nextLine();
String dashLine = "----------------------------------------";

try {

if (echo.equals("bye")) {
// Farewell message
System.out.println("Bye. Hope to see you again soon!");
try {
appendTasksToFile(taskList, FILE_PATH);
} catch (IOException e) {
System.out.println("Something went wrong: " + e.getMessage());
}
break;
} else if (echo.equals("list")) {
System.out.println(dashLine);
System.out.println(" Here are the tasks in your list:");
for (int i = 0; i < taskList.size(); i++) {
System.out.println(" " + (i + 1) + "." + taskList.get(i));
}
System.out.println(dashLine);
} else if (echo.startsWith("todo")) {
if (echo.length() <= 5) {
throw new DukeException("The description of a todo cannot be empty.");
}
String description = echo.substring(5).trim();
taskList.add(new ToDo(description, 'T'));

System.out.println(dashLine);
System.out.println(" Got it. I've added this task:");
System.out.println(" " + taskList.get(taskList.size() - 1));
System.out.println(" Now you have " + taskList.size() + " tasks in the list.");
System.out.println(dashLine);

Choose a reason for hiding this comment

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

Some unnecessary indentation here


} else if (echo.startsWith("deadline")) {
int byIndex = echo.indexOf("/by");
String description = echo.substring(9, byIndex).trim();
String by = echo.substring(byIndex + 3).trim();
taskList.add(new Deadline(description, by, 'D'));
System.out.println(dashLine);
System.out.println(" Got it. I've added this task:");
System.out.println(" " + taskList.get(taskList.size() - 1));
System.out.println(" Now you have " + taskList.size() + " tasks in the list.");
System.out.println(dashLine);
} else if (echo.startsWith("event")) {
int fromIndex = echo.indexOf("/from");
int toIndex = echo.indexOf("/to");
String description = echo.substring(6, fromIndex).trim();
String from = echo.substring(fromIndex + 5, toIndex).trim();
String to = echo.substring(toIndex + 3).trim();
taskList.add(new Event(description, from, to, 'E'));
System.out.println(dashLine);
System.out.println(" Got it. I've added this task:");
System.out.println(" " + taskList.get(taskList.size() - 1));
System.out.println(" Now you have " + taskList.size() + " tasks in the list.");
System.out.println(dashLine);
} else if (echo.startsWith("mark")) {
int taskIndex = Integer.parseInt(echo.substring(5).trim()) - 1;
if (taskIndex >= 0 && taskIndex < taskList.size()) {
taskList.get(taskIndex).markAsDone();
System.out.println(dashLine);
System.out.println(" Nice! I've marked this task as done:");
System.out.println(" " + taskList.get(taskIndex));
System.out.println(dashLine);
} else {
System.out.println("Invalid task index.");
}
} else if (echo.startsWith("unmark")) {
int taskIndex = Integer.parseInt(echo.substring(7).trim()) - 1;
if (taskIndex >= 0 && taskIndex < taskList.size()) {
taskList.get(taskIndex).markAsNotDone();
System.out.println(dashLine);
System.out.println(" OK, I've marked this task as not done yet:");
System.out.println(" " + taskList.get(taskIndex));
System.out.println(dashLine);
} else {
System.out.println("Invalid task index.");
}
} else if (echo.startsWith("delete")) {
int taskIndex = Integer.parseInt(echo.substring(7).trim()) - 1;
if (taskIndex >= 0 && taskIndex < taskList.size()) {
Task removedTask = taskList.remove(taskIndex);
System.out.println(dashLine);
System.out.println(" Noted. I've removed this task:");
System.out.println(" " + removedTask);
System.out.println(" Now you have " + taskList.size() + " tasks in the list.");
System.out.println(dashLine);
} else {
System.out.println("Invalid task index.");
}
} else {
throw new DukeException("I'm sorry, but I don't know what that means :-(");
}
} catch (DukeException e) {
System.out.println(dashLine);
System.out.println(" OOPS " + e.getMessage());
System.out.println(dashLine);
}
}

scanner.close();

}

public static void appendTasksToFile(ArrayList<Task> taskList, String filePath)
throws IOException {
FileWriter fw = new FileWriter(filePath);
for (Task task: taskList) {
fw.write(task.toFileString() + System.lineSeparator());
}
fw.close();
}

public static void loadPreviousTasks(String filePath) throws FileNotFoundException {
File f = new File(filePath);
Scanner s = new Scanner(f);
while (s.hasNext()) {
String line = s.nextLine();
try {
Task task = parseTaskFromLine(line);
taskList.add(task);
} catch (DukeException e) {
System.err.println("Error parsing task from file: " + e.getMessage());
}

}
s.close();
}

public static Task parseTaskFromLine(String line) throws DukeException {
String[] parts = line.split(" \\| ");
if (parts.length < 3) {
throw new DukeException("Invalid data format in the file.");
}
char taskType = parts[0].charAt(0);
boolean isDone = parts[1].equals("1");
String description = parts[2];

switch (taskType) {
case 'T':
ToDo toDoTask = new ToDo(description, taskType);
if (isDone) {
toDoTask.markAsDone();
} else {
toDoTask.markAsNotDone();
}
return toDoTask;

Choose a reason for hiding this comment

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

Suggested change
switch (taskType) {
case 'T':
ToDo toDoTask = new ToDo(description, taskType);
if (isDone) {
toDoTask.markAsDone();
} else {
toDoTask.markAsNotDone();
}
return toDoTask;
switch (taskType) {
case 'T':

If i'm not wrong, the 'case' line should not have indentation

case 'D':
if (parts.length < 4) {
throw new DukeException("Invalid data format for a deadline task");
}
String deadlineBy = parts[3];
Deadline deadlineTask = new Deadline(description, deadlineBy, taskType);
if (isDone) {
deadlineTask.markAsDone();
} else {
deadlineTask.markAsNotDone();
}
return deadlineTask;

case 'E':
if (parts.length < 4) {
throw new DukeException("Invalid data format for an event task.");
}
String[] eventParts = parts[3].split("-");
String eventFrom = eventParts[0];
String eventTo = eventParts[1];
Event eventTask = new Event(description, eventFrom, eventTo, taskType);
if (isDone) {
eventTask.markAsDone();
} else {
eventTask.markAsNotDone();
}
return eventTask;

default:
throw new DukeException("Invalid task type in data file.");
}
}
}
// A-Gradle
// A-JUnit
// A-Jar
// A-JavaDoc
// A-CodingStandard
// Level-9
// Level-10
7 changes: 7 additions & 0 deletions src/main/java/duke/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package duke;

public class DukeException extends Exception {
public DukeException(String message) {
super(message);
}
}
22 changes: 22 additions & 0 deletions src/main/java/duke/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package duke;

public class Event extends Task {
protected String from;
protected String to;

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

@Override
public String toFileString() {
return super.toFileString() + " | " + from + "-" + to;
}

@Override
public String toString() {
return super.toString() + " (from: " + from + " to: " + to + ")";
}
}
5 changes: 5 additions & 0 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package duke;

public class Parser {
}

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

public class Storage {
}

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

public class Task {
protected String description;
protected boolean isDone;
protected char taskType;

public Task(String description, char taskType) {
this.description = description;
this.isDone = false;
this.taskType = taskType;
}

public void markAsDone() {
isDone = true;
}

public void markAsNotDone() {
isDone = false;
}

public String getStatusIcon() {
return (isDone ? "[X]" : "[ ]");
}

public String toFileString() {
return taskType + " | " + (isDone ? "1" : "0") + " | " + description;
}

@Override
public String toString() {
return "[" + taskType + "]" + getStatusIcon() + " " + description;
}
}
5 changes: 5 additions & 0 deletions src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package duke;

public class TaskList {
}

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


public class ToDo extends Task {
public ToDo(String description, char taskType) {
super(description, taskType);
}
}
5 changes: 5 additions & 0 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package duke;

public class Ui {
}

Loading