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

[Zoebelle Pang] iP #470

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
58 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
4abe831
original
zoebelle-pang Feb 1, 2024
9fd519f
Merge branch 'nus-cs2103-AY2324S2:master' into master
zoebelle-pang Feb 1, 2024
4f9805f
Level-0
zoebelle-pang Feb 1, 2024
f76e20a
Level-1
zoebelle-pang Feb 1, 2024
23f0151
Level-2
zoebelle-pang Feb 1, 2024
bf00c0d
Level-3
zoebelle-pang Feb 1, 2024
d42cf5f
Level-4
zoebelle-pang Feb 1, 2024
ce111a4
Level-5
zoebelle-pang Feb 1, 2024
b957fc9
Revert "Level-5"
zoebelle-pang Feb 1, 2024
fda81d8
A-TextUiTesting
zoebelle-pang Feb 1, 2024
c3c4b8d
Level-5
zoebelle-pang Feb 2, 2024
f61db8c
Level-6
zoebelle-pang Feb 2, 2024
1dda06a
Level-7
zoebelle-pang Feb 9, 2024
4a85b91
Merge branch 'branch-Level-7'
zoebelle-pang Feb 9, 2024
c0bd29b
Level 8
zoebelle-pang Feb 22, 2024
4e3d1c4
level 8.1
zoebelle-pang Feb 22, 2024
29f9d66
level 8.2
zoebelle-pang Feb 22, 2024
94df8a9
A-MoreOOP
zoebelle-pang Feb 22, 2024
cbf8106
Revert "A-MoreOOP"
zoebelle-pang Feb 22, 2024
1f309a6
Revert "level 8.2"
zoebelle-pang Feb 22, 2024
235599e
remove class file
zoebelle-pang Feb 22, 2024
341f3ef
level 8.3
zoebelle-pang Feb 22, 2024
7286517
level 8.4
zoebelle-pang Feb 22, 2024
5be57a7
A-MoreOOP
zoebelle-pang Feb 22, 2024
b107abc
A-Packages
zoebelle-pang Feb 22, 2024
ee6642a
Merge branch 'add-gradle-support'
zoebelle-pang Feb 22, 2024
44bbf68
A-JUnit
zoebelle-pang Feb 22, 2024
6e2f711
A-JavaDoc
zoebelle-pang Feb 23, 2024
9ed10ba
A-JavaDoc all
zoebelle-pang Feb 23, 2024
db2313f
Revert "A-JavaDoc all"
zoebelle-pang Feb 23, 2024
84c0386
Revert "Revert "A-JavaDoc all""
zoebelle-pang Feb 23, 2024
020e951
A-CodingStandard
zoebelle-pang Feb 23, 2024
92432c2
Level-9 Add 'find' command
zoebelle-pang Feb 23, 2024
8aec68d
inc
zoebelle-pang Feb 23, 2024
dcf8f47
update package name
zoebelle-pang Feb 23, 2024
0aa73e2
Add GUI
zoebelle-pang Feb 23, 2024
eb9f02b
Implement GUI
zoebelle-pang Feb 25, 2024
a8afb71
fix conflict error
zoebelle-pang Feb 25, 2024
6f8b889
fix conflict error
zoebelle-pang Feb 25, 2024
7c3cbc2
update readme
zoebelle-pang Feb 25, 2024
3f29f12
Improve file open handling in Storage by introducing a fileIsOpen fla…
zoebelle-pang Feb 25, 2024
0512cb1
A-codeQuality
zoebelle-pang Feb 25, 2024
9e1104f
update
zoebelle-pang Feb 25, 2024
eef2934
edit listTask() to make spacing consistent
zoebelle-pang Feb 25, 2024
2360d62
Merge pull request #2 from zoebelle-pang/branch-A-Assertions
zoebelle-pang Feb 25, 2024
9871801
Revert "edit listTask() to make spacing consistent"
zoebelle-pang Feb 25, 2024
218b8cc
Merge pull request #3 from zoebelle-pang/branch-A-CodeQuality
zoebelle-pang Feb 25, 2024
fefb08a
BCD-Extension
zoebelle-pang Feb 25, 2024
337580b
Merge branch 'master' of https://github.com/zoebelle-pang/ip
zoebelle-pang Feb 25, 2024
555392f
A-UserGuide
zoebelle-pang Feb 26, 2024
1900564
final changes
zoebelle-pang Feb 26, 2024
5163f4a
DukeException
zoebelle-pang Feb 29, 2024
0840c85
minor indentation changes
zoebelle-pang Feb 29, 2024
8330255
Revert "minor indentation changes"
zoebelle-pang Feb 29, 2024
59064ef
Fix Jar file
zoebelle-pang Mar 14, 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
4 changes: 4 additions & 0 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
T || 1 | borrow book
D || 0 | return book | June 6th
E || 0 | project meeting | Mon 2-4pm
T || 1 | join sports club
230 changes: 224 additions & 6 deletions src/main/java/Duke.java

Choose a reason for hiding this comment

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

perhaps it should be while the input is not equal to "bye", rather than while(true)?

Original file line number Diff line number Diff line change
@@ -1,10 +1,228 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.io.FileWriter;
import java.io.IOException;

class Task {
private String taskDescription;
private boolean isDone;

public Task(String taskDescription) {
this.taskDescription = taskDescription;
this.isDone = false;
Copy link

@tsulim tsulim Feb 8, 2024

Choose a reason for hiding this comment

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

I noticed the same issue in other places too.

}

public void markAsDone() {
this.isDone = true;
Copy link

@tsulim tsulim Feb 8, 2024

Choose a reason for hiding this comment

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

Should the this keyword be used here? Perhaps you could refer to the Java Coding Standard under the variables section?

}

public void markAsUndone() {
this.isDone = false;
Copy link

@tsulim tsulim Feb 8, 2024

Choose a reason for hiding this comment

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

Similar to the previous comment, should the this keyword be used here?

}

public String toString() {
return "|" + (isDone ? " 1 " : " 0 ") + "| " + taskDescription;
}
}

class Todo extends Task {
public Todo(String description) {
super(description);
}

@Override
public String toString() {
return "T |" + super.toString();
}
}

class Deadline extends Task {
protected String by;

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

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

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;
}

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

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.

Perhaps you could change the class name to your bot's name?

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
File file = new File("data/duke.txt");
try {
if (!file.exists()) {
file.createNewFile();
}
} catch (IOException e) {
System.out.println("Error creating file: " + e.getMessage());
}

Scanner scanner = new Scanner(System.in);
ArrayList<Task> tasks = new ArrayList<>();

// Load existing tasks from file
loadTasksFromFile("data/duke.txt", tasks);

System.out.println("Hello! I'm Bentley\n" + "What can I do for you?\n");

while (true) {
try {
String userInput = scanner.nextLine();

if (userInput.equals("Bye")) {
System.out.println("Bye. Hope to see you again soon!");
break;
} else if (userInput.equals("List")) {

for (int i = 0; i < tasks.size(); i++) {
System.out.println((i + 1) + ". " + tasks.get(i));
}

} else if (userInput.startsWith("todo")) {
Copy link

Choose a reason for hiding this comment

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

I have only highlighted a small portion but good job on using K&R style brackets (aka Egyptian style) throughout your code.

if (userInput.length() <= 5) {
throw new IllegalArgumentException("looks like something is missing (description/ Deadline)");
}
String description = userInput.substring(5).trim();
if (description.isEmpty()) {
throw new IllegalArgumentException("looks like the description is missing");
}
tasks.add(new Todo(description));
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println("Now you have " + tasks.size() + " tasks in the list.");

} else if (userInput.startsWith("deadline")) {
if (userInput.length() <= 9) {
throw new IllegalArgumentException("looks like something is missing (description/ Deadline)");
}
String[] parts = userInput.substring(9).split("/by");
String description = parts[0].trim();
String by = parts[1].trim();
if (description.isEmpty() || by.isEmpty()) {
throw new IllegalArgumentException("looks like something is missing (description/ Deadline)");
}
tasks.add(new Deadline(description, by));
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println("Now you have " + tasks.size() + " tasks in the list.");

} else if (userInput.startsWith("event")) {
if (userInput.length() <= 6) {
throw new IllegalArgumentException("looks like something is missing (description/ Deadline)");
}
String[] parts = userInput.substring(6).split("/from");
String description = parts[0].trim();
String[] eventParts = parts[1].trim().split("/to");
String from = eventParts[0].trim();
String to = eventParts[1].trim();
if (description.isEmpty() || from.isEmpty() || to.isEmpty()) {
throw new IllegalArgumentException(
"looks like something is missing (description/ start date/ end date)");
}
tasks.add(new Event(description, from, to));
System.out.println("Got it. I've added this task:");
System.out.println(" " + tasks.get(tasks.size() - 1));
System.out.println("Now you have " + tasks.size() + " tasks in the list.");

} else if (userInput.startsWith("mark")) {
System.out.println(" Nice! I've marked this task as done:");
int taskNumber = Integer.parseInt(userInput.split(" ")[1]);
tasks.get(taskNumber - 1).markAsDone();

for (int i = 0; i < tasks.size(); i++) {
System.out.println((i + 1) + ". " + tasks.get(i));
Copy link

Choose a reason for hiding this comment

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

I liked how you have added white spaces within the statements according to the Java Coding Standard.

}

} else if (userInput.startsWith("unmark")) {
System.out.println(" OK, I've marked this task as not done yet:");
int taskNumber = Integer.parseInt(userInput.split(" ")[1]);
tasks.get(taskNumber - 1).markAsUndone();

for (int i = 0; i < tasks.size(); i++) {
System.out.println((i + 1) + ". " + tasks.get(i));
}

} else if (userInput.startsWith("delete")) {
int taskNumber = Integer.parseInt(userInput.split(" ")[1]);
if (taskNumber > 0 && taskNumber <= tasks.size()) {
Task removedTask = tasks.remove(taskNumber - 1);
System.out.println("Noted. I've removed this task:");
System.out.println(" " + removedTask);
System.out.println("Now you have " + tasks.size() + " tasks in the list.");
} else {
System.out.println("Invalid task number. Please provide a valid task number.");
}

} else {
System.out.println("please input a valid task code");
}
writeTasksToFile("data/duke.txt", tasks);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}

try {
FileWriter writer = new FileWriter("data/duke.txt");
for (Task task : tasks) {
writer.write(task.toString() + "\n");
}
writer.close();
System.out.println("Tasks written to file successfully!");
} catch (IOException e) {
e.printStackTrace();
}

scanner.close();
}
// Method to load tasks from file
private static void loadTasksFromFile(String fileName, ArrayList<Task> tasks) {
try {
File file = new File(fileName);
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String taskDescription = scanner.nextLine();
tasks.add(new Task(taskDescription));
}
scanner.close();
} catch (FileNotFoundException e) {
System.out.println("File not found: " + e.getMessage());
}
}

// Method to write tasks to file
private static void writeTasksToFile(String fileName, ArrayList<Task> tasks) {
try {
FileWriter writer = new FileWriter(fileName);
for (Task task : tasks) {
writer.write(task.toString() + "\n");
}
writer.close();
System.out.println("Tasks written to file successfully!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
1 change: 1 addition & 0 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Hello from
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|


11 changes: 11 additions & 0 deletions text-ui-test/EXPECTED.TXT.rej
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT (rejected hunks)
@@ -1,7 +1,3 @@
-Hello from
- ____ _
-| _ \ _ _| | _____
-| | | | | | | |/ / _ \
-| |_| | |_| | < __/
-|____/ \__,_|_|\_\___|
+Hello! I'm Bentley
+What can I do for you?