-
Notifications
You must be signed in to change notification settings - Fork 200
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
[TJ-Hoo] iP #190
base: master
Are you sure you want to change the base?
[TJ-Hoo] iP #190
Changes from 11 commits
a1fb5b3
50e9438
8f06dc1
15e6f91
f19569e
aeb3c02
8b22744
1feb6e5
7c31d51
1bf5e36
3d6f6e3
875ec03
2f9f975
6bdd653
e1391de
8206b33
2e3fd7c
4375e13
905f7d0
1ebdea6
31322c7
3986655
9c0ba57
f221b77
ce6d09e
c25b455
f8faf8e
9366fd6
4eb7c4a
24afabf
3f092ce
dc79a03
fd2c8f9
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,11 @@ | ||
public class Deadline extends Task { | ||
protected String due; | ||
public Deadline(String info, String due) { | ||
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 name is a better naming for the variable instead of info |
||
super(info); | ||
this.due = due; | ||
} | ||
@Override | ||
public String toString(){ | ||
return "[D]" + super.toString() + "(by: " + due + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,85 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
import java.security.InvalidAlgorithmParameterException; | ||
import java.util.MissingFormatArgumentException; | ||
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("Hello! I'm Duke \nWhat can I do for you?"); | ||
Scanner in = new Scanner(System.in); | ||
ArrayList<Task> tasks = new ArrayList<Task>(); | ||
|
||
String userInput; | ||
while(in.hasNext()){ | ||
userInput = in.nextLine(); | ||
if(userInput.equals("bye")){ | ||
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. Leave a space before the open curly bracket |
||
System.out.println("Bye. Hope to see you again soon!"); | ||
break; | ||
} else if(userInput.contains("list")) { | ||
for (int i = 0; i < tasks.size(); i++) { | ||
System.out.print(i + 1 + "."); | ||
System.out.println(tasks.get(i).toString()); | ||
} | ||
} else if (userInput.contains("todo")) { | ||
String info = userInput.substring(5).trim(); | ||
tasks.add(new Todo(info)); | ||
int finalTask = tasks.size() - 1; | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(tasks.get(finalTask).toString()); | ||
if (tasks.size() == 1) { | ||
System.out.println("Now you have " +tasks.size()+" task in the list."); | ||
} else { | ||
System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
} | ||
} else if (userInput.contains("deadline")) { | ||
String [] listArray = userInput.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. Consider changing to a more meaningful name such as phrases |
||
String description = listArray[0]; | ||
String dueDate = listArray[1]; | ||
String info = description.substring(8).trim(); | ||
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 avoid all these magic numbers, use named constant instead. |
||
String due = dueDate.substring(3).trim(); | ||
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. Try to avoid similar/confusing naming of variable |
||
tasks.add(new Deadline(info, due)); | ||
int finalTask = tasks.size() - 1; | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(tasks.get(finalTask).toString()); | ||
if (tasks.size() == 1) { | ||
System.out.println("Now you have " + tasks.size() + " task in the list."); | ||
} else { | ||
System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
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 creating a method for this since it is used a few times in the code |
||
} | ||
} else if (userInput.contains("event")) { | ||
String [] listArray = userInput.split("/",3); | ||
String description = listArray[0]; | ||
String startTime = listArray[1]; | ||
String endTime = listArray[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. User might not give the desired input. Consider implement some error handling taught in week 5 |
||
String info = description.substring(6).trim(); | ||
String start = startTime.substring(5).trim(); | ||
String end = endTime.substring(3).trim(); | ||
tasks.add(new Event(info, start, end)); | ||
int finalTask = tasks.size() - 1; | ||
System.out.println("Got it. I've added this task:"); | ||
System.out.println(tasks.get(finalTask).toString()); | ||
if (tasks.size() == 1){ | ||
System.out.println("Now you have " + tasks.size() + " task in the list."); | ||
} else { | ||
System.out.println("Now you have " + tasks.size() + " tasks in the list."); | ||
} | ||
} else if(userInput.contains("mark")){ | ||
Integer itemNumber; | ||
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. You can still use normal int data type |
||
String [] commandIndex = userInput.split(" ",2); | ||
itemNumber = Integer.parseInt(IndexArr[1])-1; | ||
if (userInput.equals("unmark")) { | ||
System.out.println("OK, I've marked this task as not done yet:"); | ||
tasks.get((int) itemNumber).isCompleted = false; | ||
System.out.println(tasks.get(itemNumber).toString()); | ||
} | ||
else { | ||
System.out.println("Nice! I've marked this task as done:"); | ||
tasks.get(itemNumber).isCompleted = true; | ||
System.out.println(tasks.get(itemNumber).toString()); | ||
} | ||
} else { | ||
tasks.add(new Task(userInput, false)); | ||
System.out.println("added: " + userInput); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
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. Relatively long and deep nested code. Consider break up the code with more abstractions. (create method for segments that are used repeatedly and a method for each command) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class Event extends Task { | ||
protected String startTime; | ||
protected String endTime; | ||
|
||
public Event(String info, String startTime, String endTime) { | ||
super(info); | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + "(from: " + startTime + " to: " + endTime + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class Task { | ||
protected String name; | ||
protected boolean isCompleted; | ||
public Task(String info) { | ||
this.name = info; | ||
} | ||
public Task(String info, boolean isCompleted) { | ||
this.name = info; | ||
isCompleted = false; | ||
} | ||
public String toString () { | ||
return(isCompleted?"[X]"+this.name:"[ ]"+this.name); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public class Todo extends Task { | ||
public Todo (String info) { | ||
super (info); | ||
} | ||
public String toString() { | ||
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 adding override annotation to indicate that the method is overriding a method from the parent class. Be consistent in the annotations for all the classes. |
||
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.
Use noun for variable. Perhaps dueDate is a better name for it.