-
Notifications
You must be signed in to change notification settings - Fork 454
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
[Rama Venkatesh] iP #503
base: master
Are you sure you want to change the base?
[Rama Venkatesh] iP #503
Changes from 9 commits
d839859
a5e37a0
9f114de
254a843
dcbae92
cba3a3a
ec3c11f
913b02f
75ec70d
76f877c
d6610f1
6e00451
a4d5124
98be0ed
bb01e2e
f54b7d8
6e50441
54125a4
c471774
b330b0d
35c0733
49b8c33
a5955e0
0dd98f3
deafde9
80d6917
84bc195
f1722c7
90738d5
8c536cb
1848605
6657c54
d183176
559aa07
6137ed5
99eeead
0dc6f8e
48c8b01
6f08fb4
a6c7cec
431ad92
b919c18
23b81b1
6735ff4
85deaac
375ee70
5db5d46
790acc6
b5d33a9
1e5ca13
0557aa0
855c0ad
dc82355
27a3096
f17b05f
a9ce5a5
979f83f
8e8c1d7
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,10 +1,96 @@ | ||||||||
import tasks.*; | ||||||||
import exceptions.*; | ||||||||
import java.util.ArrayList; | ||||||||
import java.util.Scanner; | ||||||||
|
||||||||
public class Duke { | ||||||||
public static void main(String[] args) { | ||||||||
public static void main(String[] args) throws DukeException{ | ||||||||
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 sc = new Scanner(System.in); | ||||||||
|
||||||||
//Task[] tasks = new Task[100]; | ||||||||
ArrayList<Task> tasks = new ArrayList<Task>(); | ||||||||
int taskCounter = 0; | ||||||||
|
||||||||
String input = ""; | ||||||||
try {while(true){ | ||||||||
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.
Suggested change
|
||||||||
input = sc.nextLine(); | ||||||||
if(input.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.
Suggested change
|
||||||||
System.out.println("Bye. Hope to see you again soon!\n"); | ||||||||
break; | ||||||||
//System.exit(); | ||||||||
} | ||||||||
else if(input.equals("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.
Suggested change
|
||||||||
for(int i = 0; i < taskCounter; i++){ | ||||||||
System.out.println((i+1) + "." + tasks.get(i).toString()); | ||||||||
} | ||||||||
} else if (input.length() > 4 && input.substring(0,4).equals("done")){ | ||||||||
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.
Suggested change
|
||||||||
String taskDone = input.substring(5); | ||||||||
int taskDoneIndex = Integer.parseInt(taskDone)-1; | ||||||||
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.
Suggested change
|
||||||||
tasks.get(taskDoneIndex).makeDone(); | ||||||||
System.out.println("Nice! I've marked this task as done: "); | ||||||||
System.out.println(tasks.get(taskDoneIndex).toString()); | ||||||||
} | ||||||||
else { | ||||||||
if(input.length()<4 ){ | ||||||||
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.
Suggested change
|
||||||||
throw new DukeException("Unacceptable input"); | ||||||||
} | ||||||||
if(input.substring(0,4).equals("todo")){ | ||||||||
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.
Suggested change
|
||||||||
TodoTask newTask = new TodoTask(input.substring(5)); | ||||||||
tasks.add(newTask); | ||||||||
taskCounter++; | ||||||||
System.out.println("Got it. I've added this task: "); | ||||||||
System.out.print(" " + newTask.toString()); | ||||||||
|
||||||||
} else if(input.substring(0,5).equals("event")){ | ||||||||
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.
Suggested change
|
||||||||
String at = input.split("/")[1].substring(3); | ||||||||
EventTask newEvent = new EventTask(input.substring(6).split("/")[0], at); | ||||||||
tasks.add(newEvent); | ||||||||
taskCounter++; | ||||||||
System.out.println("Got it. I've added this task: "); | ||||||||
System.out.println(" " + newEvent.toString()); | ||||||||
} else if(input.length()>5 && input.length()<8){ | ||||||||
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.
Suggested change
|
||||||||
throw new DukeException("Unacceptable input"); | ||||||||
} | ||||||||
else if(input.substring(0,6).equals("delete")) { | ||||||||
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.
Suggested change
|
||||||||
// delete from arraylist | ||||||||
// reduce counter by 1 | ||||||||
int indexToDel = Integer.parseInt(input.substring(7)); | ||||||||
Task tasktoDel = tasks.get(indexToDel); | ||||||||
tasks.remove(indexToDel); | ||||||||
taskCounter--; | ||||||||
System.out.println(" Noted. I've removed this task: "); | ||||||||
System.out.println(" " + tasktoDel.toString()); | ||||||||
} | ||||||||
else if(input.substring(0,8).equals("deadline")){ | ||||||||
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.
Suggested change
|
||||||||
// deadline | ||||||||
String by = input.split("/")[1].substring(3); | ||||||||
DeadlineTask newDeadline = new DeadlineTask(input.substring(9).split("/")[0], by); | ||||||||
tasks.add(newDeadline); | ||||||||
taskCounter++; | ||||||||
System.out.println("Got it. I've added this task: "); | ||||||||
System.out.println(" " + newDeadline.toString()); | ||||||||
|
||||||||
} | ||||||||
|
||||||||
else { | ||||||||
throw new DukeException("Unacceptable input"); | ||||||||
} | ||||||||
|
||||||||
System.out.println("\nNow you have " + (taskCounter) + " tasks in the list."); | ||||||||
} | ||||||||
}} catch (DukeException e){ | ||||||||
System.out.println("OOPS!!! You have enteted an invalid category"); | ||||||||
} | ||||||||
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 think can format the curly braces better? |
||||||||
|
||||||||
} | ||||||||
} | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package tasks; | ||
|
||
public class DeadlineTask extends Task{ | ||
String by; | ||
public DeadlineTask(String description, String by) { | ||
super(description, TaskType.DEADLINE); | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
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.
|
||
String typeString = type == TaskType.TODO ? "T" : type == TaskType.EVENT? "E" : "D"; | ||
String doneSymbol = isDone? "X" : " "; | ||
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.
|
||
String result = "[" + typeString + "] " + "[" + doneSymbol + "] " + name + "(by: " + by + ")"; | ||
return result; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package tasks; | ||
|
||
public class EventTask extends Task { | ||
String at; | ||
public EventTask(String description, String at) { | ||
super(description, TaskType.EVENT); | ||
this.at = at; | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
String typeString = type == TaskType.TODO ? "T" : type == TaskType.EVENT? "E" : "D"; | ||
String doneSymbol = isDone? "X" : " "; | ||
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.
|
||
String result = "[" + typeString + "] " + "[" + doneSymbol + "] " + name + "(at: " + at + ")"; | ||
return result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package tasks; | ||
|
||
public class Task { | ||
|
||
protected String name; | ||
protected boolean isDone = false; | ||
TaskType type; | ||
|
||
public enum TaskType { | ||
TODO, DEADLINE, EVENT | ||
} | ||
|
||
public Task(String name, TaskType type) { | ||
this.name = name; | ||
this.type = type; | ||
} | ||
|
||
public boolean isDone(){ | ||
return isDone; | ||
} | ||
public void makeDone(){ | ||
isDone = true; | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
String typeString = type == TaskType.TODO ? "T" : type == TaskType.EVENT? "E" : "D"; | ||
String doneSymbol = isDone? "X" : " "; | ||
String result = "[" + typeString + "] " + "[" + doneSymbol + "] " + name; | ||
return result; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package tasks; | ||
|
||
public class TodoTask extends Task{ | ||
|
||
public TodoTask(String description) { | ||
super(description, TaskType.TODO); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package exceptions; | ||
|
||
public class DukeException extends Exception { | ||
public DukeException(String message){ | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ Hello from | |
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
|
||
Hello! I'm Duke | ||
What can I do for you? |
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.
Maybe can name out all the files that you are importing instead of using a wildcard?