-
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
[SaiChaitanya13] ip #203
base: master
Are you sure you want to change the base?
[SaiChaitanya13] ip #203
Changes from 12 commits
cbe03ba
f2d0bfe
e5f9282
c0efa6e
eae4525
7435c1a
8c9d925
4a3350e
8bf9626
8e63c8d
63a70ee
7d9c743
cc2f69d
1f72f15
6d07cfd
8c7e7a7
a969961
f8c9289
5fe1586
9c94db0
cca8512
8d246b7
a9ef0bd
678f733
154b006
a6e5092
9fb485f
34f8b0d
5d87d90
91858cb
b7593c6
5c84e0b
d69ac7a
999cf72
8a086b7
df06edd
511e48c
4c43b1e
8f0a3e8
5c3cb49
5bebd19
de0616c
1dd986b
bb101ad
7b4656e
e45aba2
8ca8fd8
3ffea71
2675b55
39a3bfb
856052c
e444e1b
acc7aea
beb0c51
8cc346b
a3f035e
c2fc057
9aff198
15e388b
cb8a6f0
0a0118e
57d9fcb
3be8a94
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,127 @@ | ||
import java.util.Scanner; | ||
import java.util.Arrays; | ||
|
||
// camelCase used as a coding standard | ||
// indented according to Java coding standards | ||
|
||
public class Buddy { | ||
|
||
static final int TOTAL_TASKS = 100; | ||
|
||
public static void main(String[] args) { | ||
String greeting = "Hello there! I'm Buddy\n" | ||
+ "How may I assist you?"; | ||
String listOfCommands = "Here are the commands you can use: todo, deadline, event, list, mark, unmark, bye"; | ||
String exitMessage = "Hope I was of help to you! Have a great day and see you again, Buddy :)"; | ||
String divider = "________________________________________________________________________________"; | ||
|
||
System.out.println(divider); | ||
System.out.println(greeting); | ||
System.out.println(listOfCommands); | ||
System.out.println(divider); | ||
|
||
Task[] listOfThings = new Task[TOTAL_TASKS]; // why cannot private static? | ||
int currentPosition = 0; // why cannot private static? | ||
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. don't leave comments for yourself in the code |
||
String command; | ||
Scanner in = new Scanner(System.in); | ||
command = in.nextLine(); | ||
|
||
|
||
while (!command.equals("bye")) { | ||
|
||
int index = 1; | ||
if (command.equals("list")) { | ||
for (int i = 0; i < currentPosition; i++) { // while not null | ||
System.out.println(index + "." + listOfThings[index - 1]); | ||
index++; | ||
} | ||
} else if (command.startsWith("mark")) { // .startsWith(" ") | ||
int taskNumberIndexMark = 5; | ||
int taskNumber = Integer.parseInt(command.substring(taskNumberIndexMark)); | ||
// have to parse | ||
|
||
try { | ||
Task currentTask = listOfThings[taskNumber - 1]; | ||
currentTask.setDone(true); | ||
System.out.println(divider); | ||
System.out.println("Great work on completing this task! Marked as done! :)"); | ||
System.out.println(currentTask); | ||
System.out.println(divider); | ||
} catch (IndexOutOfBoundsException a) { | ||
System.out.println("That is not a valid task to mark! Please check your list again and input a valid task"); | ||
|
||
} | ||
} else if (command.startsWith("unmark")) { | ||
int taskNumberIndexUnmark = 7; | ||
int taskNumber = Integer.parseInt(command.substring(taskNumberIndexUnmark)); | ||
|
||
try { | ||
Task currentTask = listOfThings[taskNumber - 1]; | ||
|
||
currentTask.setDone(false); | ||
System.out.println(divider); | ||
System.out.println("Remember to come back to this task! Marked as undone!"); | ||
System.out.println(currentTask); | ||
System.out.println(divider); | ||
} catch (IndexOutOfBoundsException a) { | ||
System.out.println("That is not a valid task to unmark! Please check your list again and input a valid task"); | ||
|
||
} | ||
} else if (command.startsWith("todo") || command.startsWith("deadline") || command.startsWith("event")) { //todo or deadline or event --> put together so don't have to repeat the same code thrice | ||
System.out.println(divider); | ||
System.out.println("Got it! I have added this task: "); | ||
if (command.startsWith("todo")) { | ||
int todoStartingIndex = 5; | ||
|
||
Todo todoBeingAdded = new Todo(command.substring(todoStartingIndex)); | ||
listOfThings[currentPosition] = todoBeingAdded; | ||
|
||
// Task is not a Todo but Todo is a task | ||
System.out.println(todoBeingAdded); | ||
|
||
} else if (command.startsWith("deadline")) { | ||
int deadlineStartingIndex = 9; | ||
Task taskBeingAdded = new Task(command.substring(deadlineStartingIndex)); // task + date + slash (Description) | ||
// filter the description and date | ||
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 the use of comments to explain the code when needed. |
||
String taskWithDate = taskBeingAdded.description; | ||
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. Clear variable names that are easy to understand |
||
int indexOfSlash = taskWithDate.indexOf('/'); | ||
String taskDescription = taskWithDate.substring(0, (indexOfSlash - 1)); // substring goes to the one before the second index!!!! | ||
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 it might be good to indent the multiple line comments to be aligned with the block? |
||
String date = taskWithDate.substring(indexOfSlash + 4); | ||
Deadline deadlineBeingAdded = new Deadline(taskDescription, date); | ||
listOfThings[currentPosition] = deadlineBeingAdded; | ||
System.out.println(deadlineBeingAdded); | ||
|
||
} else if (command.startsWith("event")) { | ||
int eventStartingIndex = 6; | ||
Task taskBeingAdded = new Task(command.substring(eventStartingIndex)); | ||
// filter the description, from and to | ||
String wholeLine = taskBeingAdded.description; | ||
int indexOfFirstSlash = wholeLine.indexOf('/'); | ||
String taskDescription = wholeLine.substring(0, (indexOfFirstSlash - 1)); | ||
int indexOfSecondSlash = wholeLine.indexOf('/', (indexOfFirstSlash + 1)); //searches from index after first slash | ||
String from = wholeLine.substring((indexOfFirstSlash + 6), (indexOfSecondSlash)); | ||
String to = wholeLine.substring(indexOfSecondSlash + 4); | ||
Event eventBeingAdded = new Event(taskDescription, from, to); | ||
listOfThings[currentPosition] = eventBeingAdded; | ||
System.out.println(eventBeingAdded); | ||
} | ||
|
||
currentPosition++; | ||
System.out.print("You currently have " + currentPosition); | ||
if (currentPosition == 1) { | ||
System.out.println(" task remaining! Let's finish it quickly!"); | ||
} else { | ||
System.out.println(" tasks remaining! You got this, buddy!"); // all these same for all three subtasks so put at the bottom | ||
} | ||
} else { | ||
System.out.println("This command does not exist! Please type a valid command!"); | ||
} | ||
command = in.nextLine(); | ||
|
||
} | ||
System.out.println(divider); | ||
System.out.println(exitMessage); | ||
System.out.println(divider); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public class BuddyException { | ||
} |
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 toString() { | ||
return "[D]" + super.toString() + " (Please do by: " + by + "!)"; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
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; | ||
} | ||
|
||
@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,26 @@ | ||
public class Task { | ||
protected String description; | ||
protected boolean isDone; // protected => public | ||
|
||
public Task(String description) { | ||
this.description = description; | ||
this.isDone = false; | ||
} | ||
|
||
public String getStatusIcon() { | ||
return (isDone ? "X" : " "); // mark done task with X | ||
} | ||
|
||
public boolean isDone() { // do we need this | ||
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. use action naming for method |
||
return isDone; | ||
} | ||
|
||
public void setDone(boolean isDone) { | ||
this.isDone = isDone; | ||
} | ||
|
||
@Override // overrides --> print task prints this! | ||
public String toString() { | ||
return "[" + this.getStatusIcon() + "] " + this.description; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class Todo extends Task { | ||
protected boolean isDone; | ||
public Todo(String description) { | ||
super(description); // don't need isDone as isDone is already in Task class | ||
} | ||
|
||
@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.
too much happening in main, try to refactor to improve readibility and abstraction