Skip to content
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
55f9f9f
docs/README.md: Tweak document template
Jan 7, 2024
f837ddb
Add Gradle support
May 24, 2020
a6f7324
Bump gradle and lib version
Eclipse-Dominator Aug 5, 2023
acf8fdf
Added name for my chatbot
shawnpong Feb 1, 2024
623f216
Added echo functionality for George
shawnpong Feb 1, 2024
46afd35
Added list tracking functionality
shawnpong Feb 2, 2024
66efd52
Added mark, unmark functionality
shawnpong Feb 2, 2024
8cb1b88
Changed bot name, abide by coding standard
shawnpong Feb 2, 2024
a37a35f
Add Task class
shawnpong Feb 8, 2024
5195542
Add Task,ToDo, Deadline class
shawnpong Feb 8, 2024
118c2de
Follow coding standard
shawnpong Feb 8, 2024
0e1e695
Add methods to handle different tasks
shawnpong Feb 14, 2024
ea1adcb
Add exception handling
shawnpong Feb 15, 2024
2d89f52
Fix bugs
shawnpong Feb 15, 2024
190535f
Merge remote-tracking branch 'origin/add-gradle-support' into branch-…
shawnpong Feb 15, 2024
14cbebb
Revert "Bump gradle and lib version"
shawnpong Feb 15, 2024
f6e276f
Merge remote-tracking branch 'origin/add-gradle-support'
shawnpong Feb 15, 2024
a2c95c2
Revert "Bump gradle and lib version"
shawnpong Feb 15, 2024
3fd63f3
Merge branch 'master' into branch-Level-5
shawnpong Feb 15, 2024
52ab77b
Remove files
shawnpong Feb 15, 2024
4894ef2
Level-5
shawnpong Feb 16, 2024
3992ded
Merge branch 'branch-Level-5'
shawnpong Feb 16, 2024
4293c01
Add more exception handling
shawnpong Feb 20, 2024
a67bf9b
Implement ArrayList for dynamic array handling
shawnpong Feb 20, 2024
46d6cc1
Add save functionality, gitignore list data
shawnpong Feb 21, 2024
d3003ef
Add gitignore
shawnpong Feb 21, 2024
0c702d7
Merge branch 'branch-Level-7'
shawnpong Feb 21, 2024
aa38640
Merge branch 'branch-Level-6'
shawnpong Feb 21, 2024
2288a85
Fix bugs with regard to using ArrayList
shawnpong Feb 21, 2024
db336b4
Add Parser, Storage, TaskList, Ui classes
shawnpong Feb 29, 2024
c8b6a97
Add Find functionality
shawnpong Feb 29, 2024
c6a0097
Merge branch 'branch-Level-9'
shawnpong Feb 29, 2024
e7bc46d
Add JavaDoc to code
shawnpong Feb 29, 2024
19e3ebf
Add branch
shawnpong Mar 4, 2024
f45955d
Merge branch 'master' into branch-Level-9
shawnpong Mar 4, 2024
02ec784
Merge pull request #1 from shawnpong/branch-Level-9
shawnpong Mar 4, 2024
6f0f9e7
Testing README
shawnpong Mar 5, 2024
00aadd0
Testing README
shawnpong Mar 5, 2024
8d5f63a
Add README user guide
shawnpong Mar 5, 2024
c7abf86
Update README with colours!
shawnpong Mar 5, 2024
bb716bf
Change README colours
shawnpong Mar 5, 2024
8dc40dc
Add javadoc for ToDo
shawnpong Mar 7, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ bin/

/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT

/data/
33 changes: 17 additions & 16 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
# User Guide
# Duke User Guide

## Features
// Update the title above to match the actual product name

### Feature-ABC
// Product screenshot goes here

Description of the feature.
// Product intro goes here

### Feature-XYZ
## Adding deadlines

Description of the feature.
// Describe the action and its outcome.

## Usage
// Give examples of usage

### `Keyword` - Describe action
Example: `keyword (optional arguments)`

Describe the action and its outcome.
// A description of the expected outcome goes here

Example of usage:
```
expected output
```

`keyword (optional arguments)`
## Feature ABC

Expected outcome:
// Feature details

Description of the outcome.

```
expected output
```
## Feature XYZ

// Feature details
19 changes: 19 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Deadline extends Task {

protected String by;

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

public String getBy() {
return by;
}

@Override

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great use of Override annotation to signal method overriding

public String toString() {
return "[D] " + super.getStatusIcon() + " " + super.toString() + " (by: " + by + ")";
}
}
10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

26 changes: 26 additions & 0 deletions src/main/java/Events.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class Events extends Task {

protected String from;
protected String to;

public Events(String description, String from, String to, Boolean isDone) {
super(description);
this.from = from;
this.to = to;
this.isDone = isDone;
}

public String getFrom() {
return from;
}

public String getTo() {
return to;
}


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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like how you specified java.util.Scanner instead of java.util.* , this complies with coding standards, well done !

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


public class Floda {
private static ArrayList<Task> list = new ArrayList<>();
private final static String NAME = "Floda";
private static final String FILE_PATH = "./data/tasks.txt";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure why the NAME constant left out the static keyword?



public static void main(String[] args) {
Comment thread
shawnpong marked this conversation as resolved.
System.out.println("Hello! I'm " + NAME);
try {
checkIfFileExists();
readFromFile();
} catch (FileNotFoundException | InvalidInputException e) {
System.out.println("Error: " + e.getMessage());
}
Scanner scanner = new Scanner(System.in);
System.out.println("I can keep track of a to-do list for you! Just type what you want to add to the list.");
while (true) {
try {
String line = scanner.nextLine().trim();
String[] parts = line.split(" ", 2);
String command = parts[0].trim();
switch (command) {
case "bye":
System.out.println("Bye. Hope to see you again soon!");
scanner.close();
saveToFile();
return;
case "list":
if (list.isEmpty()) {
System.out.println("Your to-do list is empty.");
} else {
System.out.println("List so far: ");
for (int i = 0; i < list.size(); i++) {
System.out.println((i + 1) + "." + list.get(i));
}
}
Comment thread
shawnpong marked this conversation as resolved.
Outdated
break;
case "mark":
handleMarkTask(line);
saveToFile();
break;
case "unmark":
handleUnmarkTask(line);
saveToFile();
break;
case "deadline":
handleDeadlineTask(line);
saveToFile();
break;
case "todo":
handleTodoTask(line);
saveToFile();
break;
case "event":
handleEventTask(line);
saveToFile();
break;
case "delete":
handleDeleteTask(line);
saveToFile();
break;
default:
throw new InvalidInputException("Invalid input!");
}
} catch (InvalidInputException | IOException e){
}
Comment thread
shawnpong marked this conversation as resolved.
Outdated
}
}

private static void handleDeleteTask(String line) throws InvalidInputException {
Scanner taskScanner = new Scanner(line);
taskScanner.next();
if (taskScanner.hasNextInt()) {
int taskNumber = taskScanner.nextInt() - 1;
if (isValidTaskNumber(taskNumber)) {
System.out.println("Deleting task: " + list.get(taskNumber));
list.remove(taskNumber);
System.out.println("Task deleted successfully!");
} else {
throw new InvalidInputException("Invalid task number! Please check with 'list'.");
}
}
}

private static void handleMarkTask(String line) throws InvalidInputException {
Scanner taskScanner = new Scanner(line);
taskScanner.next();
if (taskScanner.hasNextInt()) {
int taskNumber = taskScanner.nextInt() - 1;
if (isValidTaskNumber(taskNumber)) {
list.get(taskNumber).setDone(true);
System.out.println("I have marked this task as done:\n" + list.get(taskNumber));
} else {
throw new InvalidInputException("Invalid task number! Please check with 'list'.");
}
} else {
throw new InvalidInputException("Invalid input! Please check with 'list'.");
}
taskScanner.close();
}

private static void handleUnmarkTask(String line) throws InvalidInputException {
Scanner taskScanner = new Scanner(line);
taskScanner.next();
if (taskScanner.hasNextInt()) {
int taskNumber = taskScanner.nextInt() - 1;
if (isValidTaskNumber(taskNumber)) {
list.get(taskNumber).setDone(false);
System.out.println("I have marked this task as not done:\n" + list.get(taskNumber));
} else {
throw new InvalidInputException("Invalid task number! Please check with 'list'.");
}
} else {
throw new InvalidInputException("Invalid input! Please check with 'list'.");
}
taskScanner.close();
}

private static void handleDeadlineTask(String line) throws InvalidInputException {
Scanner taskScanner = new Scanner(line);
taskScanner.next();
String remaining = taskScanner.nextLine().trim();
int byIndex = remaining.indexOf("/by");
if (byIndex == -1 || byIndex == 0) {
throw new InvalidInputException("Invalid input format! Use: 'deadline <description> /by <time>'");
}
String description = remaining.substring(0, byIndex).trim();
String by = remaining.substring(byIndex + 3).trim();
list.add(new Deadline(description, by, false));
System.out.println("Added: " + list.getLast() + "\nNow you have " + list.size() + " items in the list!");
}

private static void handleEventTask(String line) throws InvalidInputException {
Scanner taskScanner = new Scanner(line);
taskScanner.next();
String remaining = taskScanner.nextLine().trim();
int fromIndex = remaining.indexOf("/from");
if (fromIndex == -1 || fromIndex == 0) {
throw new InvalidInputException("Invalid input format! Use: 'event <description> /from <start time> /to <end time>'");
}
int toIndex = remaining.indexOf("/to");
if (toIndex == -1 || toIndex <= fromIndex + 5) {
throw new InvalidInputException("Invalid input format! Use: 'event <description> /from <start time> /to <end time>'");
}
String description = remaining.substring(0, fromIndex).trim();
String from = remaining.substring(fromIndex + 5, toIndex).trim();
String to = remaining.substring(toIndex + 3).trim();
list.add(new Events(description, from, to, false));
System.out.println("Added: " + list.getLast() + "\nNow you have " + list.size() + " items in the list!");
}

private static void handleTodoTask(String line) throws InvalidInputException {
Scanner taskScanner = new Scanner(line);
taskScanner.next();
String remaining = taskScanner.nextLine().trim();
list.add(new ToDo(remaining, false));
System.out.println("Added: " + list.getLast() + "\nNow you have " + list.size() + " items in the list!");
}
Comment thread
shawnpong marked this conversation as resolved.
Outdated



private static boolean isValidTaskNumber(int taskNumber) {
return taskNumber >= 0 && taskNumber < list.size();
}

private static void checkIfFileExists() {
File f = new File(FILE_PATH);
if (!f.exists()) {
try {
f.createNewFile();
System.out.println("File created: " + f.getAbsolutePath());
} catch (IOException e) {
System.out.println("Error creating file: " + e.getMessage());
}
}
}

private static void readFromFile() throws FileNotFoundException, InvalidInputException {
File file = new File(FILE_PATH);
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
parseTask(line);
}
scanner.close();
}

private static void parseTask(String line) throws InvalidInputException {
String[] parts = line.split("\\|");
if (parts.length < 3) {
throw new InvalidInputException("Invalid input format in file");
}
String type = parts[0].trim();
boolean isDone = parts[1].trim().equals("1");
String description = parts[2].trim();

switch (type) {
case "T":
list.add(new ToDo(description, isDone));
break;
case "D":
if (parts.length < 4) {
throw new InvalidInputException("Invalid input format for deadline in file");
}
String by = parts[3].trim();
list.add(new Deadline(description, by, isDone));
break;
case "E":
if (parts.length < 5) {
throw new InvalidInputException("Invalid input format for event in file");
}
String from = parts[3].trim();
String to = parts[4].trim();
list.add(new Events(description, from, to, isDone));
break;
default:
throw new InvalidInputException("Unknown task type in file");
}
}

private static void saveToFile() throws IOException {
FileWriter fw = new FileWriter(FILE_PATH);
for (Task task : list) {
fw.write(taskToLine(task) + "\n");
}
System.out.println("Saved to file");
fw.close();
}

private static String taskToLine(Task task) {
if (task instanceof ToDo todo) {
return "T | " + (todo.isDone() ? "1" : "0") + " | " + todo.getDescription();
} else if (task instanceof Deadline deadline) {
return "D | " + (deadline.isDone() ? "1" : "0") + " | " + deadline.getDescription() + " | " + deadline.getBy();
} else if (task instanceof Events event) {
return "E | " + (event.isDone() ? "1" : "0") + " | " + event.getDescription() + " | " + event.getFrom() + " | " + event.getTo();
}
return "";
}
}
5 changes: 5 additions & 0 deletions src/main/java/InvalidInputException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class InvalidInputException extends Exception {
public InvalidInputException(String errorMessage) {
System.out.println(errorMessage);
}
}
Loading