-
Notifications
You must be signed in to change notification settings - Fork 114
[AdiMangalam] ip #111
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
base: master
Are you sure you want to change the base?
[AdiMangalam] ip #111
Changes from 6 commits
eeda7cd
3dbc7ed
3545f8f
c5937a0
a7ed3ec
3c2e5a2
f0acaa3
cc00e52
8e5f97c
fad3efb
2316c0b
456b24b
811769c
d05b803
9024ae5
febbce1
8514320
63d3acc
0d4b146
4ca10de
e340a54
bbb61c9
94d3b6e
60e059c
a91164f
2ef672d
9474427
d246758
07ca321
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 |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| # Ignore all class files | ||
| *.class | ||
|
|
||
| # IDEA files | ||
| /.idea/ | ||
| /out/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| public 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: " + by + ")" ; | ||
|
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. proper use of overiding and with clear comments |
||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| 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; | ||
| } | ||
|
|
||
|
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. proper use of overiding and with clear comments |
||
| @Override | ||
| public String toString() { | ||
| return "[E]" + super.toString() + "(from: " + from + " to: " + to + ")"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import java.sql.Array; | ||
| import java.util.Scanner; | ||
|
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. well done. code functionality is implemented with well organized methods and with naming that describes the purpose well, and is in camelCase. if else statement is also in egyptian format |
||
| import java.util.List; | ||
| import java.util.ArrayList; | ||
|
|
||
| public class Flash { | ||
|
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. To improve abstraction, you can refactor the code by separating task-related logic from the main control flow. One class can handle the application's control logic (user interaction, commands) while another class can be responsible for managing tasks (adding, deleting, marking, saving, etc.). |
||
|
|
||
| private static final List<Task> tasks = new ArrayList<>(); | ||
|
|
||
| public static void displayTasks() { | ||
| System.out.println("____________________________________________________________"); | ||
| for(int i = 0; i < tasks.size(); i++) { | ||
| System.out.println(i+1 + "." + tasks.get(i)); | ||
| } | ||
| System.out.println("____________________________________________________________"); | ||
| } | ||
|
|
||
| public static void markTask(String input) { | ||
| int taskNumber = Integer.parseInt(input.split(" ")[1]) - 1; | ||
| Task task = tasks.get(taskNumber); | ||
| task.markDone(); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Nice! I've marked this task as done:"); | ||
| System.out.println(" " + task); | ||
| System.out.println("____________________________________________________________"); | ||
| } | ||
|
|
||
| public static void unMarkTask(String input) { | ||
| int taskNumber = Integer.parseInt(input.split(" ")[1]) - 1; | ||
| Task task = tasks.get(taskNumber); | ||
| task.markNotDone(); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Ok, I've marked this task as not done yet:"); | ||
| System.out.println(" " + task); | ||
| System.out.println("____________________________________________________________"); | ||
| } | ||
|
|
||
| public static void todo(String input){ | ||
| String description = input.substring(5).trim(); | ||
| Task task = new ToDo(description); | ||
| tasks.add(task); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" " + task); | ||
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
| System.out.println("____________________________________________________________"); | ||
| } | ||
|
|
||
| public static void deadline(String input) { | ||
| String[] parts = input.substring(8).split(" /by "); | ||
| String description = parts[0].trim(); | ||
| String by = parts[1].trim(); | ||
| Task task = new Deadline(description, by); | ||
| tasks.add(task); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + task); | ||
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
| System.out.println("____________________________________________________________"); | ||
| } | ||
|
|
||
| public static void event(String input) { | ||
| String[] parts = input.substring(6).split(" /from | /to"); | ||
|
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. Avoid using magic numbers like substring(6).split. Used named constants for these numbers instead. |
||
| String description = parts[0].trim(); | ||
| String from = parts[1].trim(); | ||
| String to = parts[2].trim(); | ||
| Task task = new Event(description, from, to); | ||
| tasks.add(task); | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Got it. I've added this task:"); | ||
| System.out.println(" " + task); | ||
| System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
| System.out.println("____________________________________________________________"); | ||
|
|
||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| Scanner in = new Scanner(System.in); | ||
|
|
||
| System.out.println("____________________________________________________________"); | ||
| System.out.println(" Hello! I'm Flash"); | ||
| System.out.println(" What can I do for you?"); | ||
| System.out.println("____________________________________________________________"); | ||
|
|
||
| String input; | ||
| while(true) { | ||
| input = in.nextLine(); | ||
| if (input.equalsIgnoreCase("bye")) { | ||
| System.out.println("____________________________________________________________"); | ||
| System.out.println("Bye. Hope to see you again soon!"); | ||
| System.out.println("____________________________________________________________"); | ||
| break; | ||
| } else if (input.equalsIgnoreCase("list")) { | ||
| displayTasks(); | ||
| } else if (input.startsWith("mark")) { | ||
| markTask(input); | ||
| } else if (input.startsWith("unmark")){ | ||
| unMarkTask(input); | ||
| } else if (input.startsWith("todo")) { | ||
| todo(input); | ||
| } else if (input.startsWith("deadline")) { | ||
| deadline(input); | ||
| } else if (input.startsWith("event")) { | ||
| event(input); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| public class Task { | ||
| protected String description; | ||
| protected boolean isDone; | ||
|
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. well done. code has proper and regular formatting and is easily understood |
||
|
|
||
| public Task(String description) { | ||
| this.description = description; | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| public String getIcon() { | ||
| if (isDone) { | ||
| return "X"; | ||
| } else { | ||
| return " "; | ||
| } | ||
| } | ||
|
|
||
| public void markDone() { | ||
| this.isDone = true; | ||
| } | ||
|
|
||
| public void markNotDone() { | ||
| this.isDone = false; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "[" + getIcon() + "]" + description; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| public class ToDo extends Task{ | ||
|
|
||
| public ToDo(String description) { | ||
| super(description); | ||
| } | ||
|
|
||
| @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.
has proper use of inheritance and no noticeable formatting issues.