-
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
CerIsaiah iP #81
base: master
Are you sure you want to change the base?
CerIsaiah iP #81
Changes from 6 commits
8d479f1
9f133c1
d45c1d9
4f0d7d8
23ca335
4718536
7772ed5
aad378b
92b1dcf
3e90ffe
412181f
f4eb8e3
f7403d7
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,14 @@ | ||
public class Deadline extends Task { | ||
|
||
protected String by; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "[D]" + super.getDescription() + " (by: " + by + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,123 @@ | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
//Refactoring methods is helpful for transforming | ||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
|
||
showWelcome(); | ||
|
||
ArrayList<Task> tasks = new ArrayList<>(100); | ||
|
||
Scanner scan = new Scanner( System.in ); | ||
|
||
boolean isEchoing = true; | ||
while (isEchoing){ | ||
String input; | ||
input = scan.nextLine(); | ||
|
||
if (input.equalsIgnoreCase("bye")){ | ||
isEchoing = false; | ||
break; | ||
} | ||
|
||
if (input.equals("list")){ | ||
int numOfTasks = 0; | ||
|
||
for (Task task: tasks){ | ||
numOfTasks++; | ||
System.out.println(numOfTasks + ": " + task.getDescription()); | ||
} | ||
|
||
} else if (input.toLowerCase().startsWith("mark ")){ | ||
String[] parts = input.split(" "); | ||
|
||
int taskNum = Integer.parseInt(parts[1]); | ||
try { | ||
Task markedTask = tasks.get(taskNum - 1); | ||
|
||
markedTask.isDone = true; | ||
System.out.println("Congrats I marked this class as done : " + markedTask.getDescription()); | ||
} catch (Exception ArrayIndexOutOfBoundsException){ | ||
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. should you catch the exception during the input phase? Check if 0 < user input index < num of items + 1 |
||
System.out.println("That task doesnt exist"); | ||
} | ||
|
||
} else if (input.toLowerCase().startsWith("unmark ")) { | ||
String[] parts = input.split(" "); | ||
|
||
int taskNum = Integer.parseInt(parts[1]); | ||
tasks.get(taskNum - 1).isDone = false; | ||
|
||
try { | ||
Task unmarkedTask = tasks.get(taskNum - 1); | ||
|
||
unmarkedTask.isDone = false; | ||
System.out.println("I unmarked this class as done: " + unmarkedTask.getDescription()); | ||
} catch (Exception ArrayIndexOutOfBoundsException){ | ||
System.out.println("That task doesnt exist"); | ||
} | ||
|
||
} else if (input.toLowerCase().startsWith("deadline")){ | ||
try { | ||
String[] toDoSplit = input.split("/"); | ||
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 the variable name to a more suitable plural name. |
||
//First part is task, and last is when by | ||
String desc = toDoSplit[0].substring(9).trim(); // removes "deadline | ||
Deadline deadline = new Deadline(desc, toDoSplit[1].trim()); | ||
System.out.println(deadline.getDescription()); | ||
|
||
tasks.add(deadline); | ||
|
||
} catch (Exception ArrayIndexOutOfBoundsException){ | ||
System.out.println("Put a / after your task if you want to add a todo"); | ||
} | ||
|
||
|
||
|
||
} else if (input.toLowerCase().startsWith("event")){ | ||
try { | ||
String[] toDoSplit = input.split("/"); | ||
//First part is task, and last is when by | ||
String desc = toDoSplit[0].substring(6).trim(); | ||
Event event = new Event(desc, toDoSplit[1].trim(), toDoSplit[2].trim()); | ||
System.out.println(event.getDescription()); | ||
tasks.add(event); | ||
|
||
} catch (ArrayIndexOutOfBoundsException e){ | ||
System.out.println("Put a / after your task if you want to add a todo"); | ||
} catch (NullPointerException e){ | ||
System.out.println("Please enter a input"); | ||
} | ||
|
||
|
||
} else if (input.toLowerCase().startsWith("todo")) { | ||
try { | ||
String desc = input.substring(4).trim(); | ||
Todo todo = new Todo(desc); | ||
|
||
System.out.println(todo.getDescription()); | ||
tasks.add(todo); | ||
|
||
} catch (Exception e) { | ||
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. what types of errors are expected? can the exception catch be more specific? |
||
System.out.println("An error occurred while adding the todo."); | ||
} | ||
} else { | ||
// Add the task to the list | ||
Task newTask = new Task(input); | ||
tasks.add(newTask); | ||
System.out.println("Added: " + input); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
System.out.println("Fine. If you have no ideas imma head out"); | ||
|
||
} | ||
|
||
private static void showWelcome() { | ||
System.out.println("Hello my name is DUKE"); | ||
System.out.println("What can I do for you today?"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public class Event extends Task{ | ||
|
||
protected String time; | ||
String start; | ||
String end; | ||
Comment on lines
+9
to
+10
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 adding in access modifiers and not leave it to default. |
||
public Event(String description, String start, String end) { | ||
super(description); | ||
this.start = start; | ||
this.end = end; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "[E]" + super.getDescription() + " " + start + "-" + end ; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
public class Task { | ||
String description; | ||
protected boolean isDone; | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public void setDone(boolean done) { | ||
isDone = done; | ||
} | ||
|
||
|
||
public String getDescription() { | ||
return "[" + getStatusIcon() + "] " + description; | ||
} | ||
|
||
|
||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class Todo extends Task{ | ||
protected String 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. should this variable be marked as private instead of protected? its the final class in the inheritance chain |
||
|
||
public Todo(String description) { | ||
super(description); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "[T]" + super.getDescription(); | ||
} | ||
} |
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.
Is there a reason why you don't use toLowerCase() for this specific command?