Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chashaobao] iP #640

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
68c58c1
Add Gradle support
May 24, 2020
03523ec
Bump gradle and lib version
Eclipse-Dominator Aug 5, 2023
81a9c53
build.gradle: Prevent generating a second JAR file
aureliony Jul 16, 2024
60e495d
ip_wk2_level-0
Aug 26, 2024
fddb9e9
ip wk2 level-1
Aug 26, 2024
48f9b91
ip wk2 level-2
Aug 26, 2024
064c6c3
wk2 ip level-3
Aug 31, 2024
97639d6
wk2 level-4
Aug 31, 2024
4f01857
wk2 ip level-5
Aug 31, 2024
1df1350
wk2 ip level-6
Aug 31, 2024
55989ae
add automated-text-ui-testing
Aug 31, 2024
957bf55
add Level-7 changes
Sep 3, 2024
dfae243
update reading and writing of saved tasks
Sep 4, 2024
0dea61f
add date and time for deadline and event
Sep 4, 2024
cd8b26e
abstract more classes
Sep 5, 2024
421974d
abstract out classes
Sep 5, 2024
08746c5
Merge remote-tracking branch 'origin/add-gradle-support'
Sep 5, 2024
ba6a7ef
correct packages
Sep 5, 2024
91afd9e
correctly add packages
Sep 5, 2024
3da8d0b
add JUnit: TaskListTest and UiTest
Sep 5, 2024
fb664fa
add headers
Sep 6, 2024
991b22f
add search function
Sep 6, 2024
6df0184
resolve merge conflicts
Sep 6, 2024
c7862f4
merge branches
Sep 6, 2024
1ee7602
add gui
Sep 6, 2024
5f50efb
add gui
Sep 6, 2024
e73a476
Add assertions
Sep 14, 2024
b01a403
Update packages to follow convention
Sep 14, 2024
5656a9d
Update packages
Sep 14, 2024
620f3de
Merge pull request #2 from chashaobao123/branch-A-Assertions
chashaobao123 Sep 14, 2024
20e7261
Resolve import errors
Sep 14, 2024
e543672
Merge with master
Sep 14, 2024
668af35
Merge pull request #3 from chashaobao123/branch-A-CodeQuality
chashaobao123 Sep 14, 2024
c088340
Add assertions
Sep 14, 2024
78d3987
Merge branch 'master' of github.com:chashaobao123/ip
Sep 14, 2024
1c02284
Merge Level-8 to master
Sep 17, 2024
ac340f4
Merge pull request #4 from chashaobao123/branch-Level-8
chashaobao123 Sep 17, 2024
55d7ca0
Resolved merge conflicts from pull-request
Sep 17, 2024
cd35b95
Add proper headings
Sep 17, 2024
b6f266c
Edit error messages to fit personality
Sep 17, 2024
a0b1e69
Add JUnit tests
Sep 17, 2024
6bf7a93
Update README
Sep 17, 2024
6f02cc0
Update README
Sep 17, 2024
e4dc31b
Add Ui.png to docs folder
Sep 22, 2024
dabdb0b
Update README
Sep 22, 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
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
6 changes: 6 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
Binary file not shown.
Binary file added .vs/ip/v17/.wsuo
Binary file not shown.
12 changes: 12 additions & 0 deletions .vs/ip/v17/DocumentLayout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Version": 1,
"WorkspaceRootPath": "C:\\Users\\65814\\OneDrive\\NUSY2S1\\CS2103T\\IP\\ip\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
3 changes: 3 additions & 0 deletions src/main/java/.vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
6 changes: 6 additions & 0 deletions src/main/java/.vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
Binary file not shown.
Binary file added src/main/java/.vs/java/v17/.wsuo
Binary file not shown.
12 changes: 12 additions & 0 deletions src/main/java/.vs/java/v17/DocumentLayout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Version": 1,
"WorkspaceRootPath": "C:\\Users\\65814\\OneDrive\\NUSY2S1\\CS2103T\\IP\\ip\\src\\main\\java\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}
Binary file added src/main/java/.vs/slnx.sqlite
Binary file not shown.
18 changes: 18 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Deadline extends Task {
protected String by;
Copy link

Choose a reason for hiding this comment

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

Would it make sense to save the string as Java Datetime instead?


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

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

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

This file was deleted.

22 changes: 22 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
public class Event extends Task {
protected String from;
protected String to;

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

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

@Override
public String toString() {
return "E | " + super.toString() + " | " + this.from + " | " + this.to;
}

}
5 changes: 5 additions & 0 deletions src/main/java/InvalidCommandException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class InvalidCommandException extends Exception {
public InvalidCommandException(String message) {
super(message);
}
}
5 changes: 5 additions & 0 deletions src/main/java/InvalidTaskFormatException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class InvalidTaskFormatException extends Exception {
public InvalidTaskFormatException(String message) {
super(message);
}
}
241 changes: 241 additions & 0 deletions src/main/java/LittleMissHelpful.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;

public class LittleMissHelpful {
private static final String FILE_PATH = "./data/LittleMissHelpfullist.txt";
public static void main(String[] args) {
/**

Choose a reason for hiding this comment

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

Maybe you can add this comment in the header instead? (i.e. before the public class in Line 10) It may help others to understand your code purpose better!

* Simulates a chatbot
* Reads input and provides a reply
*/

String name = "Ah Bang Mang";
String lineBreak = "---------------------------------";
String greeting = "Hello! I'm " + name + ".\nWhat you want sia?";
String exitLine = "Ok, I zao first then!";

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

// Print greeting
System.out.println(lineBreak);
System.out.println(greeting);
System.out.println(lineBreak);

ArrayList<Task> list = new ArrayList<Task>();

// Load tasks from file
loadTasks(list);

int counter = list.size();;
while (true) { // Continuous input
Copy link

Choose a reason for hiding this comment

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

Would it be better to refactor this part into the the Parse class as suggested in the project brief week 3?

Choose a reason for hiding this comment

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

agreed! Separating all the parsing commands into a separate parse class could make the code look neater

Copy link
Author

Choose a reason for hiding this comment

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

Yes, thank you! I have abstracted out the classes now

try {
String input = br.readLine();

// Split into command and description/arguments
String[] inputList = input.split(" ", 2);
String command = inputList[0];

if (inputList.length < 2) {
// Check if the user command is "bye" -> exit
if (command.equalsIgnoreCase("bye")) {

Choose a reason for hiding this comment

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

Maybe you could separate the UI related code to a UI class?

System.out.println(lineBreak);
System.out.println(exitLine);
System.out.println(lineBreak);
saveTasks(list);
break; // Exit the loop
}

// Check if the user command is "list" -> print list
if (command.equalsIgnoreCase("list")) {
System.out.println(lineBreak);

if (counter == 0) {
System.out.println("Wah shiok! No tasks at the moment leh.");
} else {
System.out.println("Siao liao! This your current task list leh...");
for (int i = 0; i < counter; i++) {
int listNumber = i + 1;
Task listItem = list.get(i);
System.out.println(listNumber + ". " + listItem.toString());
}
}
System.out.println(lineBreak);
continue;
}

// Invalid command --> throw exception
System.out.println(lineBreak);
System.out.println("Alamak! Format salah already. Please provide a valid command.");
System.out.println(lineBreak);
continue;
}

String item = inputList[1];

// Check if user command is "mark" / "unmark" -> mark / unmark task
if (command.equalsIgnoreCase("mark")) {
try {
int listIndex = Integer.parseInt(item) - 1;
if (listIndex < 0 || listIndex >= counter) {
throw new TaskNotFoundException(lineBreak + "\nHai-ya, task number out of range lah.\n" + lineBreak);
}
Task curTask = list.get(listIndex);
list.set(listIndex, curTask.markTask());
System.out.println(lineBreak);
System.out.println("Wah upz! You have marked this task as done: " + curTask.toString());
System.out.println(lineBreak);
} catch (NumberFormatException e) {
System.out.println(lineBreak + "\nHai-yo, task number must be an integer lah.\n" + lineBreak);
} catch (TaskNotFoundException e) {
System.out.println(e.getMessage());
}
continue;

} else if (command.equalsIgnoreCase("unmark")) {
try {
int listIndex = Integer.parseInt(item) - 1;
if (listIndex < 0 || listIndex >= counter) {
throw new TaskNotFoundException(lineBreak + "Hai-ya, task number out of range lah.\n" + lineBreak);
}
Task curTask = list.get(listIndex);
list.set(listIndex, curTask.unmarkTask());
System.out.println(lineBreak);
System.out.println("Ok, I see you laze. You have marked this task as not done yet: " + curTask.toString());
System.out.println(lineBreak);
} catch (NumberFormatException e) {
System.out.println(lineBreak + "\nHai-yo, task number must be an integer lah.\n" + lineBreak);
Copy link

Choose a reason for hiding this comment

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

This check looks the same as the check for the "mark" command, perhaps can refactor to reduce repetition?

} catch (TaskNotFoundException e) {
System.out.println(e.getMessage());
}
continue;
}

//deletes task from list
if (command.equalsIgnoreCase("delete")) {
try {
int listIndex = Integer.parseInt(item) - 1;
if (listIndex < 0 || listIndex >= counter) {
throw new TaskNotFoundException(lineBreak + "\nHai-ya, task number out of range lah.\n" + lineBreak);
}
Task curTask = list.get(listIndex);
list.remove(listIndex);
counter--;

System.out.println(lineBreak);
System.out.println("Wah shiok! This task no more liao: " + curTask.toString());
System.out.println("Now got only " + counter + " tasks left.");
System.out.println(lineBreak);
} catch (NumberFormatException e) {
System.out.println(lineBreak + "\nHai-yo, task number must be an integer lah.\n" + lineBreak);
} catch (TaskNotFoundException e) {
System.out.println(e.getMessage());
}
continue;
}

// Adds tasks to list
if (command.equals("todo") || command.equals("deadline") || command.equals("event")) {
Task newTask = null;

try {
if (command.equalsIgnoreCase("todo")) {
Copy link

Choose a reason for hiding this comment

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

The switch and case statement may come in handy here. (frankly I also never use)

newTask = new Todo(item);

} else if (command.equalsIgnoreCase("deadline")) {
String[] itemList = item.split("/by", 2);
if (itemList.length < 2) {
throw new InvalidTaskFormatException(
lineBreak + "\nAlamak! Deadline format salah already. Use 'deadline description /by date'.\n" + lineBreak);
}
String desc = itemList[0].trim();
String by = itemList[1].trim();

newTask = new Deadline(desc, by);

} else if (command.equalsIgnoreCase("event")) {
String[] itemList = item.split("/from | /to", 3);
if (itemList.length < 3) {
throw new InvalidTaskFormatException(
lineBreak + "\nAlamak! Event format salah already. Use 'event description /from start /to end'.\n" + lineBreak);
}
String desc = itemList[0].trim();
String from = itemList[1].trim();
String to = itemList[2].trim();

newTask = new Event(desc, from, to);
}

list.add(newTask);
System.out.println(lineBreak);
System.out.println("Added to list liao: " + newTask.toString());
System.out.println("Sian, now got " + (counter + 1) + " tasks in your list.");
System.out.println(lineBreak);
counter++;

} catch (InvalidTaskFormatException e) {
System.out.println(e.getMessage());
}
continue;

} else {
// Invalid command --> throw exception
System.out.println(
lineBreak + "\nAlamak! Format salah already... Please provide a valid command and description.\n" + lineBreak);
Copy link

Choose a reason for hiding this comment

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

Perhaps can provide some descriptions of what are valid commands

}
} catch (IOException e) {
System.out.println("Aiyo salah! Try again lor...");
e.printStackTrace();
}
}
}

private static void loadTasks(ArrayList<Task> list) {
/**
* Loads tasks from a txt file from harddrive to generate initial list
*
* Creates a new file with a new path if the file does not currently exist
*/
File dataFile = new File(FILE_PATH);
if (!dataFile.getParentFile().exists()) {
dataFile.getParentFile().mkdirs();
}
if (dataFile.exists()) {
try (BufferedReader br = new BufferedReader(new FileReader(dataFile))) {
String line;
while ((line = br.readLine()) != null) {
try {
Task task = Task.fromStringToTask(line);
list.add(task);
} catch (InvalidTaskFormatException e) {
System.out.println("Warning: Skipping invalid task format: " + line);
}
}
} catch (IOException e) {
System.out.println("Error reading the file: " + e.getMessage());
}
}
}

private static void saveTasks(ArrayList<Task> list) {
/**
* Saves tasks to a txt file on harddrive
*/
File dataFile = new File(FILE_PATH);
try (BufferedWriter bw = new BufferedWriter(new FileWriter(dataFile))) {
for (Task task : list) {
bw.write(task.toString());
bw.newLine();
}
} catch (IOException e) {
System.out.println("Error writing to the file: " + e.getMessage());
}
}
}


Loading