-
Notifications
You must be signed in to change notification settings - Fork 484
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
base: master
Are you sure you want to change the base?
[Luah Jun Yang} iP #571
Changes from 10 commits
28ad2b8
ed6d4d2
8f211eb
c442a23
e26ad60
2826c8b
c163e3f
6880516
9502380
6403c3d
f8faf33
59151ce
76c74cf
efa2cac
cf2306e
3a10e8d
c59c708
1435a48
fb9f638
2ac3943
e8b0d86
eae69dd
04310fd
68fc1cb
4364715
c59a6cf
43a2dd1
4806d6d
8633cba
3f79e97
7b1615e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 + ")"; | ||
} | ||
} | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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 + ")"; | ||
} | ||
} |
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please follow the camelCase convention for methods, i.e. |
||
} | ||
|
||
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" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When breaking up a statement into multiple lines, the |
||
" 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't check if the input is either |
||
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" + | ||
"____________________________________________________________"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} 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()); | ||
} | ||
} | ||
} | ||
} |
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); | ||
} | ||
} |
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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class ToDo extends Task { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps you should add the |
||
|
||
ToDo(String name) { | ||
this.task_name = name; | ||
this.isCompleted = false; | ||
} | ||
@Override | ||
public String toString() { | ||
return "[T]" + super.toString(); | ||
} | ||
} |
There was a problem hiding this comment.
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 {