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

[T1duS] ip #680

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 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
6aa0869
Renamed Bot
T1duS Aug 27, 2024
9aa95e9
Level-1
T1duS Aug 27, 2024
8d7ef61
Level-1
T1duS Aug 27, 2024
26a4f78
Level-2
T1duS Aug 28, 2024
742b278
Level-3
T1duS Aug 28, 2024
8921f9d
Level-4
T1duS Sep 8, 2024
41419f3
A-TextUiTesting
T1duS Sep 8, 2024
791ceff
Level-5
T1duS Sep 8, 2024
eb2be1d
Level-6
T1duS Sep 8, 2024
02d84a8
Level-7
T1duS Sep 8, 2024
7689960
Merge pull request #1 from T1duS/branch-Level-7
T1duS Sep 8, 2024
2fe4354
Improve code quality
T1duS Sep 8, 2024
f3dff1a
Implement Level-8
T1duS Sep 8, 2024
1bfdf9e
Merge branch 'branch-Level-8'
T1duS Sep 8, 2024
98329b9
Improve OOP quality
T1duS Sep 8, 2024
7f11c22
Make Package
T1duS Sep 8, 2024
4b4e23e
Merge remote-tracking branch 'origin/add-gradle-support'
T1duS Sep 8, 2024
be97f49
Add Gradle
T1duS Sep 8, 2024
5d93574
Add JUnit Tests
T1duS Sep 8, 2024
ad05bc5
Add AI-generated Javadoc documentation
T1duS Sep 8, 2024
27a30a9
Improve Coding Standard
T1duS Sep 8, 2024
29a1931
Add functionality for finding tasks
T1duS Sep 8, 2024
b479ae6
Merge branch 'branch-A-CodingStandard'
T1duS Sep 8, 2024
97b281f
Merge branch 'branch-Level-9'
T1duS Sep 8, 2024
39871e8
GUI
T1duS Sep 14, 2024
fe1682a
Merge pull request #2 from T1duS/branch-level-10
T1duS Sep 14, 2024
0e3f9d3
checkstyle
T1duS Sep 14, 2024
cc1bbc6
Merge pull request #4 from T1duS/A-Checkstyle
T1duS Sep 14, 2024
2359427
added assertions
T1duS Sep 14, 2024
825a679
Merge pull request #5 from T1duS/branch-A-Assertions
T1duS Sep 14, 2024
d0c45b5
updated docs
T1duS Sep 16, 2024
c221350
Merge pull request #6 from T1duS/branch-A-Userguide
T1duS Sep 16, 2024
09d31e7
finished userguide
T1duS Sep 16, 2024
4007c2c
Merge pull request #7 from T1duS/branch-A-Userguide
T1duS Sep 16, 2024
10d6d49
extension
T1duS Sep 16, 2024
616bbc5
Merge pull request #8 from T1duS/BCD-Extension
T1duS Sep 16, 2024
1d1452e
A-CodeQuality
T1duS Sep 16, 2024
38ee534
Merge pull request #9 from T1duS/branch-A-CodeQuality
T1duS Sep 16, 2024
e8af505
What this commit does:
T1duS Sep 16, 2024
3669b82
Merge pull request #10 from T1duS/branch-A-CodeQuality
T1duS Sep 16, 2024
daebd82
UI
T1duS Sep 19, 2024
38ae099
Merge pull request #11 from T1duS/branch-A-CodeQuality
T1duS Sep 19, 2024
e89275f
Add commit with correct git standard
T1duS Sep 28, 2024
b96c5e1
Add commit with correct git standard
T1duS Sep 28, 2024
9c8fa68
Add commit with correct git standard
T1duS Sep 28, 2024
98b29a4
Add commit with correct git standard
T1duS Sep 28, 2024
e732e25
Add commit with correct git standard
T1duS Sep 28, 2024
4661936
Add commit with correct git standard
T1duS Sep 28, 2024
cb3b0a4
exit application when bye is given as input
T1duS Oct 18, 2024
a40616a
code quality and exception changes
T1duS Oct 18, 2024
f57ad05
Merge pull request #13 from T1duS/Fixes
T1duS Oct 18, 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
11 changes: 8 additions & 3 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
public class Deadline extends Task {
protected String by;
private String by;

Choose a reason for hiding this comment

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

Perhaps can give the deadline date a clearer name? Right now the name "by" may not be clear to other programmers.


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

@Override
public String toSaveFormat() {
return "D|" + (isDone ? "1" : "0") + "|" + description + "|" + by;
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + by + ")";
return "[D]" + (isDone ? "[X] " : "[ ] ") + description + " (by: " + by + ")";
}
}
}
17 changes: 11 additions & 6 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
public class Event extends Task {
protected String to;
protected String from;
private String from;
private String to;

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

@Override
public String toSaveFormat() {
return "E|" + (isDone ? "1" : "0") + "|" + description + "|" + from + "|" + to;
}

@Override
public String toString() {
return "[E]" + super.toString() + " (from: " + from + " to: " + to + ")";
return "[E]" + (isDone ? "[X] " : "[ ] ") + description + " (from: " + from + " to: " + to + ")";
}
}
}
74 changes: 40 additions & 34 deletions src/main/java/Opus.java
Original file line number Diff line number Diff line change
@@ -1,70 +1,76 @@
import java.util.Scanner;

public class Opus {
public static void main(String[] args) {

private Storage storage;
private TaskList taskList;
// private Ui ui;

public Opus(String filePath) {
// ui = new Ui();
storage = new Storage(filePath);
taskList = new TaskList(storage.load());
}

public void run() {

Choose a reason for hiding this comment

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

Could this method be refactored into smaller methods to handle the different scenarios more effectively?

Scanner scanner = new Scanner(System.in);

System.out.println(" Hello! I'm Opus");
System.out.println(" What can I do for you?");

Task[] tasks = new Task[101];
int taskCount = 0;

while(true) {
while (true) {
String s = scanner.nextLine();
String[] words = s.split(" ");

try{
try {
if (s.equals("bye")) {
storage.save(taskList.getTasks());
break;
} else if (s.equals("list")) {
for (int i = 1; i <= taskCount; i++) {
System.out.println(i + ". " + tasks[i]);
}
}
else if (words[0].equals("mark")) {
int i = Integer.parseInt(words[1]);
tasks[i].markAsDone();
taskList.listTasks();
} else if (words[0].equals("mark")) {
int i = Integer.parseInt(words[1]) - 1;
taskList.getTask(i).markAsDone();
System.out.println("Nice! I've marked this task as done:");
System.out.println(tasks[i]);
}
else if (words[0].equals("delete")) {
int i = Integer.parseInt(words[1]);
System.out.println(taskList.getTask(i));
} else if (words[0].equals("delete")) {
int i = Integer.parseInt(words[1]) - 1;
System.out.println("Noted. I've removed this task:");
System.out.println(" " + tasks[i]);
for (int j = i; j < taskCount; j++) {
tasks[j] = tasks[j + 1];
}
taskCount--;
System.out.println(" Now you have " + taskCount + " tasks in the list.");
}
else {
System.out.println(" " + taskList.getTask(i));
taskList.removeTask(i);
System.out.println(" Now you have " + taskList.getSize() + " tasks in the list.");
} else {
if (words[0].equals("todo")) {
if (words.length <= 1) {
throw new OpusEmptyDescriptionException("The description of a todo cannot be empty.");
}
tasks[++taskCount] = new ToDo(s.substring(5));
Task todo = new ToDo(s.substring(5));
taskList.addTask(todo);
} else if (words[0].equals("deadline")) {
String[] parts = s.substring(9).split(" /by ");
tasks[++taskCount] = new Deadline(parts[0], parts[1]);
Task deadline = new Deadline(parts[0], parts[1]);
taskList.addTask(deadline);
} else if (words[0].equals("event")) {
String[] parts = s.substring(6).split(" /from ");
String[] parts2 = parts[1].split(" /to ");
Copy link

Choose a reason for hiding this comment

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

Perhaps a more intuitive variable name here?

tasks[++taskCount] = new Event(parts[0], parts2[1], parts2[0]);
}
else{
Task event = new Event(parts[0], parts2[0], parts2[1]);
taskList.addTask(event);
} else {
throw new OpusUnknownCommandException("I'm sorry, but I don't know what that means.");
}
System.out.println(" Got it. I've added this task:");
System.out.println(" " + tasks[taskCount]);
System.out.println(" Now you have " + taskCount + " tasks in the list.");
System.out.println(" " + taskList.getTask(taskList.getSize() - 1));
System.out.println(" Now you have " + taskList.getSize() + " tasks in the list.");
}
}
catch (OpusException e) {
} catch (OpusException e) {
System.out.println(e.getMessage());
}
}
System.out.println(" Bye. Hope to see you again soon!");
scanner.close();
}

public static void main(String[] args) {
new Opus("data/tasks.txt").run();
}
}
3 changes: 3 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class Parser{

Choose a reason for hiding this comment

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

This is nitpicking but don't forget the space to follow coding standards. In the future can check through.


}
67 changes: 67 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Storage {
private String filePath;

public Storage(String filePath) {
this.filePath = filePath;
}

public ArrayList<Task> load(){
ArrayList<Task> tasks = new ArrayList<>();
File file = new File(filePath);

try{
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] parts = line.split("\\|");
String taskType = parts[0];
boolean isDone = parts[1].equals("1");
switch (taskType) {
case "T":
tasks.add(new ToDo(parts[2]));
break;
case "D":
tasks.add(new Deadline(parts[2], parts[3]));
break;
case "E":
tasks.add(new Event(parts[2], parts[3], parts[4]));
break;
}
if (isDone) {
tasks.get(tasks.size() - 1).markAsDone();
}
}
scanner.close();
return tasks;
}
catch (IOException e) {
return tasks;
}
}

public void save(ArrayList<Task> tasks){
File file = new File(filePath);

File parentDir = file.getParentFile();
if (parentDir != null && !parentDir.exists()) {
parentDir.mkdirs();
}

try{
FileWriter writer = new FileWriter(filePath);
for (Task task : tasks) {
writer.write(task.toSaveFormat() + "\n");
}
writer.close();
}
catch (IOException e){
return;

Choose a reason for hiding this comment

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

Perhaps logging or printing an error message could be helpful for diagnosing the exceptions here?

}
}
}
13 changes: 5 additions & 8 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ public Task(String description) {
this.isDone = false;
}

public String getStatusIcon() {
return (isDone ? "X" : " "); // mark done task with X
}

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

@Override
public String toString() {
return "[" + this.getStatusIcon() + "] " + this.description;
public boolean isDone() {
return isDone;
}
}

public abstract String toSaveFormat();
}
39 changes: 39 additions & 0 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.util.ArrayList;

public class TaskList {
private ArrayList<Task> tasks;

public TaskList() {
this.tasks = new ArrayList<>();
}

public TaskList(ArrayList<Task> tasks) {
this.tasks = tasks;
}

public void addTask(Task task) {
tasks.add(task);
}

public Task getTask(int index) {
return tasks.get(index);
}

public Task removeTask(int index) {
return tasks.remove(index);
}

public int getSize() {
return tasks.size();
}

public ArrayList<Task> getTasks() {
return tasks;
}

public void listTasks() {
for (int i = 0; i < tasks.size(); i++) {
System.out.println((i + 1) + ". " + tasks.get(i));
}
}
}
9 changes: 7 additions & 2 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ public ToDo(String description) {
super(description);
}

@Override
public String toSaveFormat() {
return "T|" + (isDone ? "1" : "0") + "|" + description;
}

@Override
public String toString() {
return "[T]" + super.toString();
return "[T]" + (isDone ? "[X] " : "[ ] ") + description;

Choose a reason for hiding this comment

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

Perhaps you could add a method to Task class that returns a string with (isDone ? "[X] " : "[ ] "). Then you can call super.thisMethod for easier coding?

}
}
}
13 changes: 13 additions & 0 deletions src/main/java/Ui.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Ui {
public void showTaskAdded(Task task, int taskCount) {
System.out.println("Got it. I've added this task:");
System.out.println(" " + task);
System.out.println("Now you have " + taskCount + " tasks in the list.");
}

public void showTaskDeleted(Task task, int taskCount) {
System.out.println("Noted. I've removed this task:");
System.out.println(" " + task);
System.out.println("Now you have " + taskCount + " tasks in the list.");
}
}