-
Notifications
You must be signed in to change notification settings - Fork 590
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
[samriddh2145] iP #645
base: master
Are you sure you want to change the base?
[samriddh2145] iP #645
Changes from 7 commits
68c58c1
03523ec
81a9c53
962daa9
19b1f75
93e0062
15bb306
40808b5
3ca6677
0265f50
756f9de
cf46cc2
1cecdae
b645e1d
1460fdd
682a2a7
484c3fc
d150412
e030379
2012375
dd58a5c
6d4d819
37768e9
5ff2982
5934709
3b1822e
5be2639
3b1e02f
e9f77b6
68f3ec0
3463b57
a3de517
8acd894
97e452a
b758e84
85cef01
1256e3c
af9b906
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,4 +1,4 @@ | ||
# Duke User Guide | ||
# Bing User Guide | ||
|
||
// Update the title above to match the actual product name | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import java.util.Scanner; | ||
import java.util.ArrayList; | ||
public class Bing { | ||
public static void main(String[] args) { | ||
String message = "______________________________\n" | ||
+ "Hi! My name is Bing\n" | ||
+ "How can I help you?\n" | ||
+ "______________________________\n"; | ||
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 notice you have many areas in your code where you are using a string of underscores to denote a line. You may consider declaring a variable, e.g. LINE, to avoid code repetition! |
||
System.out.println(message); | ||
Scanner scanner = new Scanner(System.in); | ||
String input; | ||
ArrayList<Task> tasks = new ArrayList<Task>(); | ||
while (true) { | ||
input = scanner.nextLine(); | ||
if (input.equals("Bye") || input.equals("bye")) { | ||
System.out.println("______________________________\n" | ||
+ "Bye. Have a good day.\n" | ||
+ "______________________________\n"); | ||
break; | ||
} else if (input.equals("list")) { | ||
System.out.println("______________________________\n" | ||
+ "All tasks in your list :\n"); | ||
for (int i=0 ; i<tasks.size() ; i++) { | ||
System.out.println((i + 1)+". "+tasks.get(i).toString()); | ||
} | ||
System.out.println("______________________________\n"); | ||
} else if (input.startsWith("mark")) { | ||
int x = Integer.parseInt(input.substring(5)); | ||
if (x>0 && x<=tasks.size()) { | ||
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 may use some spacing around the characters here? |
||
tasks.get(x-1).setToDone(); | ||
System.out.println("______________________________\n"); | ||
System.out.println("This task is marked as done :"); | ||
System.out.println(tasks.get(x-1).toString()); | ||
System.out.println("______________________________\n"); | ||
} else { | ||
System.out.println("Invalid Input.\n"); | ||
} | ||
|
||
} else if (input.startsWith("unmark")) { | ||
int x = Integer.parseInt(input.substring(7)); | ||
if (x>0 && x<=tasks.size()) { | ||
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 may use some spacing around the characters here too? |
||
tasks.get(x-1).setToUndone(); | ||
System.out.println("______________________________\n"); | ||
System.out.println("This task is marked as undone :"); | ||
System.out.println(tasks.get(x-1).toString()); | ||
System.out.println("______________________________\n"); | ||
} else { | ||
System.out.println("Invalid Input.\n"); | ||
} | ||
|
||
} else if (input.startsWith("todo")) { | ||
Task temp = new ToDo(input.substring(5)); | ||
tasks.add(temp); | ||
System.out.println("______________________________\n" | ||
+ "Added the task:\n" | ||
+ temp.toString() + "\n" | ||
+ "Total tasks - " + tasks.size() + "\n" | ||
+ "______________________________\n"); | ||
|
||
} else if (input.startsWith("deadline ")) { | ||
String[] segments = input.substring(9).split(" /by "); | ||
Task temp = new Deadline(segments[0],segments[1]); | ||
tasks.add(temp); | ||
System.out.println("______________________________\n" | ||
+ "Added the task:\n" | ||
+ temp.toString() + "\n" | ||
+ "Total tasks - " + tasks.size() + "\n" | ||
+ "______________________________\n"); | ||
} else if (input.startsWith("event ")) { | ||
String[] segments = input.substring(6).split(" /from "); | ||
String[] segments2 = segments[1].split(" /to "); | ||
Task temp = new Event(segments[0],segments2[0],segments2[1]); | ||
tasks.add(temp); | ||
System.out.println("______________________________\n" | ||
+ "Added the task:\n" | ||
+ temp.toString() + "\n" | ||
+ "Total tasks - " + tasks.size() + "\n" | ||
+ "______________________________\n"); | ||
|
||
} else { | ||
System.out.println("Invalid Input.\n"); | ||
//Task temp = new Task(input); | ||
//tasks.add(temp); | ||
//System.out.println("______________________________\n" | ||
// + "Added: "+ input + "\n" | ||
// + "______________________________\n"); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
public class Deadline extends Task { | ||
|
||
private String deadline; | ||
|
||
public Deadline(String info, String 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. Consider adding a JavaDoc comment for this as it will likely cause a Checkstyle error, since public constructors are required to have such a comment. |
||
super(info); | ||
this.deadline = deadline; | ||
} | ||
@Override | ||
public String toString() { | ||
return "[D]" + "[" + getStatus() + "]" + " " + getInfo() + " (by: " + deadline + ")"; | ||
} | ||
|
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
public class Event extends Task { | ||
private String from; | ||
private String to; | ||
public Event(String info, String from, String to) { | ||
super(info); | ||
this.from = from; | ||
this.to = to; | ||
} | ||
|
||
|
||
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. Nit: Unnecessary newline |
||
@Override | ||
public String toString() { | ||
return "[E]" + "[" + getStatus() +"]"+ " " + getInfo() + " " + " (from: " + from + " to: " + to + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
public abstract class Task { | ||
private String info; | ||
private boolean isDone; | ||
|
||
public Task(String info) { | ||
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 a JavaDoc comment to the explain constructor for this class. |
||
this.info = info; | ||
this.isDone = false; | ||
} | ||
|
||
public String getInfo() { | ||
return info; | ||
} | ||
public String getStatus() { | ||
if (isDone) { | ||
return "X"; | ||
} else { | ||
return " "; | ||
} | ||
} | ||
public void setToDone() { | ||
this.isDone = true; | ||
} | ||
public void setToUndone() { | ||
this.isDone = false; | ||
} | ||
public abstract String toString(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class ToDo extends Task { | ||
|
||
public ToDo(String info) { | ||
super(info); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[T]" + "["+ getStatus() + "]" + " " + getInfo(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,62 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
______________________________ | ||
Hi! My name is Bing | ||
How can I help you? | ||
______________________________ | ||
|
||
______________________________ | ||
Added the task: | ||
[D][ ] Do Assignment (by: Friday) | ||
Total tasks - 1 | ||
______________________________ | ||
|
||
______________________________ | ||
Added the task: | ||
[T][ ] write essay | ||
Total tasks - 2 | ||
______________________________ | ||
|
||
______________________________ | ||
All tasks in your list : | ||
|
||
1. [D][ ] Do Assignment (by: Friday) | ||
2. [T][ ] write essay | ||
______________________________ | ||
|
||
______________________________ | ||
Added the task: | ||
[E][ ] group meet (from: Thurs 4pm to: 6pm) | ||
Total tasks - 3 | ||
______________________________ | ||
|
||
______________________________ | ||
|
||
This task is marked as done : | ||
[T][X] write essay | ||
______________________________ | ||
|
||
______________________________ | ||
All tasks in your list : | ||
|
||
1. [D][ ] Do Assignment (by: Friday) | ||
2. [T][X] write essay | ||
3. [E][ ] group meet (from: Thurs 4pm to: 6pm) | ||
______________________________ | ||
|
||
______________________________ | ||
|
||
This task is marked as undone : | ||
[T][ ] write essay | ||
______________________________ | ||
|
||
______________________________ | ||
All tasks in your list : | ||
|
||
1. [D][ ] Do Assignment (by: Friday) | ||
2. [T][ ] write essay | ||
3. [E][ ] group meet (from: Thurs 4pm to: 6pm) | ||
______________________________ | ||
|
||
______________________________ | ||
Bye. Have a good day. | ||
______________________________ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
deadline Do Assignment /by Friday | ||
todo write essay | ||
list | ||
event group meet /from Thurs 4pm /to 6pm | ||
mark 2 | ||
list | ||
unmark 2 | ||
list | ||
bye |
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.
Consider abstracting away portions of your code to helper methods and then refactoring your code to match the OOP style of coding. Kudos on the extensive error handling nonetheless!