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

[Luah Jun Yang} iP #571

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
31 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
8f211eb
Level 0
LuahJunYang Aug 26, 2023
c442a23
Finished Level 1, renamed bot to Frenchie
LuahJunYang Aug 26, 2023
e26ad60
Added functionality to store user input as list and print out all inp…
LuahJunYang Aug 28, 2023
2826c8b
Created Task class to be used for Frenchie
LuahJunYang Aug 28, 2023
c163e3f
Added addTask and listTask methods and a constructor to Frenchie.java
LuahJunYang Aug 30, 2023
6880516
Added mark as incomplete method to Task.java and complete and uncompl…
LuahJunYang Aug 30, 2023
9502380
Created new Task subclasses
LuahJunYang Aug 30, 2023
6403c3d
Added if-else statements and updated toString() methods for checking…
LuahJunYang Aug 30, 2023
f8faf33
Created new FrenchieException class to handle basic exceptions for no…
LuahJunYang Sep 4, 2023
59151ce
Added delete function to frenchie, changed tasks attribute to ArrayLi…
LuahJunYang Sep 4, 2023
76c74cf
Added functions saveTasksToFile and readTasksFromFile
LuahJunYang Sep 9, 2023
efa2cac
Added LocalDateTime and DateTimeFormatter functionalities to construc…
LuahJunYang Sep 10, 2023
cf2306e
Implemented enum for Commands, abstracted UI, Parser, Storage, and Ta…
LuahJunYang Sep 17, 2023
3a10e8d
Bug fixing for bye command, causing an illegal state exception when t…
LuahJunYang Sep 17, 2023
c59c708
Packaged all classes into package.frenchie
LuahJunYang Sep 18, 2023
1435a48
Merge branch 'add-gradle-support' for 'A-Gradle'
LuahJunYang Sep 18, 2023
fb9f638
Updated build.gradle file, wrote J-unit tests ToDoTest and TaskTest
LuahJunYang Sep 21, 2023
2ac3943
Added JavaDoc comments for Task, ToDo, Deadline, Event, Ui, Parser cl…
LuahJunYang Sep 21, 2023
e8b0d86
Added findMessage() method to Ui.java, find enum to Command, and retu…
LuahJunYang Sep 21, 2023
eae69dd
Resolved merge conflict in Ui.java
LuahJunYang Sep 21, 2023
04310fd
Edited void functions to return String for the GUI. Implemented GUI s…
LuahJunYang Sep 22, 2023
68fc1cb
Improving on Code Quality
LuahJunYang Sep 22, 2023
4364715
Merge pull request #3 from LuahJunYang/branch-A-CodeQuality
LuahJunYang Sep 22, 2023
c59a6cf
Add help function
LuahJunYang Sep 22, 2023
43a2dd1
Merge pull request #4 from LuahJunYang/branch-C-Help
LuahJunYang Sep 22, 2023
4806d6d
Added User Guide in README.md
LuahJunYang Sep 23, 2023
8633cba
Updating README for github page
LuahJunYang Sep 23, 2023
3f79e97
Added Screenshot of UI
LuahJunYang Sep 23, 2023
7b1615e
Updated mainClass in build.gradle to fix the jar file not running
LuahJunYang Sep 23, 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
17 changes: 17 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Deadline extends Task {
String deadline;

//Constructor
public Deadline(String name, String deadline) {
super(name);
this.isCompleted = false;
this.deadline = deadline;
}

@Override
public String toString() {
return "[D]" + super.toString() + "(" + this.deadline + ")";
}
}


10 changes: 0 additions & 10 deletions src/main/java/Duke.java

This file was deleted.

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

Choose a reason for hiding this comment

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

Should leave a whitespace between your definition and the curly braces, as in
public class Event extends Task {

String startTime;
String endTime;

public Event(String name, String startTime, String endTime) {
this.task_name = name;
this.startTime = startTime;
this.endTime = endTime;
this.isCompleted = false;
}

@Override
public String toString() {
return "[E]" + super.toString() + "(" + this.startTime + this.endTime + ")";
}
}
144 changes: 144 additions & 0 deletions src/main/java/Frenchie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import java.util.ArrayList;
import java.util.Scanner;

public class Frenchie {
public ArrayList<Task> tasks;

//constructor
public Frenchie() {
this.tasks = new ArrayList<>();
}

public void addTask(Task NEW_TASK) {
Copy link

Choose a reason for hiding this comment

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

The Task parameter is a variable, not a constant. So it should be in camelCase instead, i.e. newTask.

tasks.add(NEW_TASK);
}

public void listTasks() {
int counter = 1;
for (Task task : tasks) {
System.out.println(counter + ". " + task.toString());
counter += 1;
}
}

public void completeTask(int index) {
tasks.get(index).mark_as_completed();
Copy link

Choose a reason for hiding this comment

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

Please follow the camelCase convention for methods, i.e. markAsCompleted.

}

public void uncompleteTask(int index) {
tasks.get(index).mark_as_incomplete();
}

public int getNumOfTasks() {
return this.tasks.size();
}

public void deleteTask(int index) {
tasks.remove(index);
}
public static void main(String[] args) {
/*String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo); */
Frenchie frenchie = new Frenchie();
String skeleton = "____________________________________________________________\n" +
Copy link

Choose a reason for hiding this comment

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

When breaking up a statement into multiple lines, the + operator should be on a new line.

" Hello! I'm Frenchie\n" +
" What can I do for you?\n" +
"____________________________________________________________"
/* " Bye. Hope to see you again soon!\n" +
"____________________________________________________________\n" */;
System.out.println(skeleton);

Scanner scanner = new Scanner(System.in);
while (true) {
String input = scanner.nextLine();
try {
if (input.equals("bye")) {
System.out.println("____________________________________________________________\n" +
" Bye. Hope to see you again soon!\n" +
"____________________________________________________________");
break;
} else if (input.equals("list")) { //Checking if user is looking to list all tasks
frenchie.listTasks();
} else if (input.contains("mark")) { //Checking if user input is to mark/unmark tasks
Copy link

Choose a reason for hiding this comment

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

This doesn't check if the input is either mark or unmark. If a user inputs markzzzzzz, this will still be treated as unmark even though it is an invalid command, because the input still contains the substring mark. To avoid similar problems like this, perhaps you should use Java Enums to ensure input validity.

String[] parts = input.split(" ");
int index = Integer.parseInt(parts[1]) - 1;
Task target_task = frenchie.tasks.get(index);
//Checking if user is looking to mark task as done or incomplete
if (parts[0].equals("mark")) {
frenchie.completeTask(index);
System.out.println("____________________________________________________________\n" +
" Nice! I've marked this task as done: \n" +
target_task.toString() + "\n" +
"____________________________________________________________");
} else {
frenchie.uncompleteTask(index);
System.out.println("____________________________________________________________\n" +
" OK, I've marked this task as not done yet: \n" +
target_task.toString() + "\n" +
"____________________________________________________________");
}
} else if (input.contains("delete")){
String[] parts = input.split(" ");
int index = Integer.parseInt(parts[1]) - 1;
Task target_task = frenchie.tasks.get(index);
frenchie.deleteTask(index);
System.out.println("____________________________________________________________\n" +
"Noted. I've removed this task: \n" +
target_task.toString() + "\n" +
"Now you have " + frenchie.getNumOfTasks() + " tasks in the list.\n" +
"____________________________________________________________");

Choose a reason for hiding this comment

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

As the number of keywords increase, perhaps you might want to start looking at enums to have a collection of your keywords!

Copy link

Choose a reason for hiding this comment

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

Seconded. In addition, perhaps you may wish to divide all the logic in your main method into several other methods, as the complexity of your program increases.

} else if (input.contains("event") || input.contains("todo") || input.contains("deadline")) {
String[] parts = input.split(" ");
String taskType = parts[0];
if (parts.length <= 1) {
throw new FrenchieException("____________________________________________________________\n" +
"OOPS!!! The description of a " + taskType + " cannot be empty.\n" +
"____________________________________________________________");
} else {
if (taskType.equals("todo")) {
String taskName = input.split("todo")[1];
ToDo currentTask = new ToDo(taskName);
frenchie.addTask(currentTask);
System.out.println("____________________________________________________________\n" +
" Got it! I've added this task: \n" +
currentTask + "\n" +
"Now you have " + frenchie.getNumOfTasks() + " tasks in the list.\n" +
"____________________________________________________________");
} else if (taskType.equals("deadline")) {
String taskName = input.split("/")[0].split("deadline")[1].trim();
String deadline = input.split("/")[1].replace("by ", "by: ");
Deadline currentTask = new Deadline(taskName, deadline);
frenchie.addTask(currentTask);
System.out.println("____________________________________________________________\n" +
" Got it! I've added this task: \n" +
currentTask + "\n" +
"Now you have " + frenchie.getNumOfTasks() + " tasks in the list.\n" +
"____________________________________________________________");
} else {
String taskName = input.split("/")[0].split("event")[1].trim();
String startTime = input.split("/")[1].replace("from ", "from: ");
String endTime = input.split("/")[2].replace("to ", "to: ");
Event currentTask = new Event(taskName, startTime, endTime);
frenchie.addTask(currentTask);
System.out.println("____________________________________________________________\n" +
" Got it! I've added this task: \n" +
currentTask + "\n" +
"Now you have " + frenchie.getNumOfTasks() + " tasks in the list.\n" +
"____________________________________________________________");
}
}
} else {
throw new FrenchieException("____________________________________________________________\n" +
"OOPS!!! I'm sorry but I don't know what that means! :-(\n" +
"____________________________________________________________");
}
} catch (FrenchieException e) {
System.err.println(e.getMessage());
}
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/FrenchieException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class FrenchieException extends Exception{
public FrenchieException(String message) {
super(message);
}
}
29 changes: 29 additions & 0 deletions src/main/java/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class Task {
public boolean isCompleted;
public String task_name;

public Task() {
isCompleted = false;
}
//Constructor
public Task(String name) {
this.task_name = name;
isCompleted = false;
}

public void mark_as_completed() {
isCompleted = true;
}

public void mark_as_incomplete() {
isCompleted = false;
}
@Override
public String toString() {
String indicator = " ";
if(isCompleted) {
indicator = "X";
}
return "[" + indicator + "] " + task_name;
}
}
11 changes: 11 additions & 0 deletions src/main/java/ToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ToDo extends Task {
Copy link

Choose a reason for hiding this comment

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

Perhaps you should add the public access modifier to your class definition?


ToDo(String name) {
this.task_name = name;
this.isCompleted = false;
}
@Override
public String toString() {
return "[T]" + super.toString();
}
}