-
Notifications
You must be signed in to change notification settings - Fork 78
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
[Barbaracwx] iP #67
base: master
Are you sure you want to change the base?
[Barbaracwx] iP #67
Changes from 6 commits
999081b
c129070
23d1e0e
182f0f5
69a4ae4
8842184
f824dfe
70ba578
0894d39
a0f798a
2987979
9beff6f
786c27b
327d3d4
5fe3f31
9e14e1d
d2ed96a
6425ae4
2423d8a
ef461a8
36a4072
36a6f2b
98a143a
87b9da0
4df8bd3
6d2c93b
139e288
dd53bc2
b073a6f
b913271
a58e292
c03627a
8b10039
fc929e4
2976ed5
2bc67ee
3f173b3
7437537
64ef5a1
a1a8f04
3f61c50
f7d6c25
b2c8537
a480276
db152b1
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,2 @@ | ||
package PACKAGE_NAME;public class DeadlineTask { | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,61 @@ | ||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
System.out.println("____________________________________________________________"); | ||
System.out.println("Hello! I'm Calebra\nWhat can I do for you?"); | ||
System.out.println("____________________________________________________________"); | ||
|
||
Scanner input = new Scanner(System.in); | ||
Task[] tasks = new Task[100]; | ||
int taskCount = 0; | ||
|
||
String line = input.nextLine(); | ||
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. Consider changing your variable name to something more appropriate such as userInput. |
||
while (!line.equals("bye")) { | ||
|
||
System.out.println("____________________________________________________________"); | ||
if (line.equals("list")) { | ||
System.out.println("Here are the tasks in your list:"); | ||
for (int i = 0; i < taskCount; i++) { | ||
System.out.println((i + 1) + ". " + tasks[i]); | ||
} | ||
} else if (line.startsWith("mark")) { | ||
int taskIndex = Integer.parseInt(line.substring(5)) - 1; | ||
if (taskIndex >= 0 && taskIndex < taskCount) { | ||
tasks[taskIndex].markAsDone(); | ||
System.out.println("Nice! I've marked this task as done:\n" + tasks[taskIndex].toString()); | ||
} | ||
} else { | ||
String[] parts = line.split(" ", 2); | ||
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. Good use of plurality for naming "parts" |
||
String command = parts[0]; | ||
String taskDescription = parts.length > 1 ? parts[1] : ""; | ||
|
||
switch (command) { | ||
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. Right use of indentation for switch case 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 could consider creating a separate method for the switch case |
||
case "todo": | ||
tasks[taskCount] = new TodoTask(taskDescription); | ||
break; | ||
case "deadline": | ||
tasks[taskCount] = new DeadlineTask(taskDescription); | ||
break; | ||
case "event": | ||
tasks[taskCount] = new EventTask(taskDescription); | ||
break; | ||
default: | ||
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. I like how you handle invalid inputs for the switch case. |
||
System.out.println("Invalid command. Please use 'todo', 'deadline', 'event', or 'list'."); | ||
} | ||
taskCount++; | ||
System.out.println("Got it. I've added this task: "); | ||
System.out.println(tasks[taskCount - 1].toString()); | ||
System.out.println("Now you have " + taskCount + " tasks in the list."); | ||
} | ||
|
||
System.out.println("____________________________________________________________\n"); | ||
line = input.nextLine(); | ||
} | ||
|
||
// When the user types "bye," exit the loop and display the goodbye message | ||
System.out.println("____________________________________________________________"); | ||
System.out.println("Bye! Hope to see you again soon!"); | ||
System.out.println("____________________________________________________________"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package PACKAGE_NAME;public class EventTask { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class Task { | ||
private String description; | ||
private boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public void markAsDone() { | ||
isDone = true; | ||
} | ||
|
||
public void markAsNotDone() { | ||
isDone = false; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public String getStatusIcon() { | ||
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. Good use of camelCase for method |
||
return (isDone ? "X" : " "); | ||
} | ||
|
||
@Override | ||
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. Good use of @OverRide to show overriding of parent's method |
||
public String toString() { | ||
return "[" + getStatusIcon() + "] " + description; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package PACKAGE_NAME;public class TodoTask { | ||
} |
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.
You might want to add some spaces between the package and the class.