-
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 10 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,144 @@ | ||
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().trim(); | ||
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")) { | ||
try { | ||
int x = Integer.parseInt(input.substring(5).trim()); | ||
if (x > 0 && x<=tasks.size()) { | ||
tasks.get(x - 1).setStatus(TaskStatus.DONE); | ||
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"); | ||
} | ||
} catch (NumberFormatException e) { | ||
System.out.println("______________________________\n"); | ||
System.out.println("Invalid Format"); | ||
System.out.println("______________________________\n"); | ||
} | ||
|
||
} else if (input.startsWith("unmark")) { | ||
try { | ||
int x = Integer.parseInt(input.substring(7)); | ||
if (x>0 && x<=tasks.size()) { | ||
tasks.get(x-1).setStatus(TaskStatus.UNDONE); | ||
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"); | ||
} | ||
} catch (NumberFormatException e) { | ||
System.out.println("______________________________\n"); | ||
System.out.println("Invalid Format"); | ||
System.out.println("______________________________\n"); | ||
} | ||
|
||
|
||
} else if (input.startsWith("todo")) { | ||
String temp = input.substring(4).trim(); | ||
if (temp.isEmpty()) { | ||
System.out.println("Invalid Input.\n"); | ||
} else { | ||
Task temp2 = new ToDo(temp); | ||
tasks.add(temp2); | ||
System.out.println("______________________________\n" | ||
+ "Added the task:\n" | ||
+ temp.toString() + "\n" | ||
+ "Total tasks - " + tasks.size() + "\n" | ||
+ "______________________________\n"); | ||
} | ||
|
||
} else if (input.startsWith("deadline ")) { | ||
try { | ||
String[] segments = input.substring(9).split(" /by "); | ||
if (segments.length < 2 || segments[0].trim().isEmpty() || segments[1].trim().isEmpty()) { | ||
System.out.println("Invalid Input.\n"); | ||
} else { | ||
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"); | ||
} | ||
} catch (ArrayIndexOutOfBoundsException e) { | ||
System.out.println("______________________________\n"); | ||
System.out.println("Invalid Format"); | ||
System.out.println("______________________________\n"); | ||
} | ||
|
||
|
||
} else if (input.startsWith("event ")) { | ||
try { | ||
String[] segments = input.substring(6).split(" /from "); | ||
if (segments.length<2) { | ||
System.out.println("Invalid Input.\n"); | ||
} else { | ||
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"); | ||
} | ||
} catch (ArrayIndexOutOfBoundsException e) { | ||
System.out.println("______________________________\n"); | ||
System.out.println("Invalid Format"); | ||
System.out.println("______________________________\n"); | ||
} | ||
|
||
} else if (input.startsWith("delete")) { | ||
try { | ||
int x = Integer.parseInt(input.substring(7).trim()); | ||
if (x>0 && x<=tasks.size()) { | ||
Task removedTask = tasks.remove(x - 1); | ||
System.out.println("______________________________\n"); | ||
System.out.println("Task removed :"); | ||
System.out.println(removedTask.toString()); | ||
System.out.println("Total tasks - " + tasks.size() + "\n"); | ||
System.out.println("______________________________\n"); | ||
} else { | ||
System.out.println("Invalid Input.\n"); | ||
} | ||
} catch (NumberFormatException e) { | ||
System.out.println("______________________________\n"); | ||
System.out.println("Invalid Format"); | ||
System.out.println("______________________________\n"); | ||
} | ||
} else { | ||
System.out.println("Invalid Input.\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().getStatusSymbol() + "]" + " " + 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().getStatusSymbol() +"]"+ " " + getInfo() + " " + " (from: " + from + " to: " + to + ")"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
public abstract class Task { | ||
private String info; | ||
private TaskStatus 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 = TaskStatus.UNDONE; | ||
} | ||
|
||
public String getInfo() { | ||
return info; | ||
} | ||
public TaskStatus getStatus() { | ||
return isDone; | ||
} | ||
public void setStatus(TaskStatus status) { | ||
this.isDone = status; | ||
} | ||
|
||
public abstract String toString(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
public enum TaskStatus { | ||
DONE("X"), | ||
UNDONE(" "); | ||
|
||
private String StatusSymbol; | ||
|
||
TaskStatus(String StatusSymbol) { | ||
this.StatusSymbol = StatusSymbol; | ||
} | ||
|
||
public String getStatusSymbol() { | ||
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. Specifically, what is the status that is returned about. |
||
return this.StatusSymbol; | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class ToDo extends Task { | ||
|
||
public ToDo(String info) { | ||
super(info); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[T]" + "[" + getStatus().getStatusSymbol() + "]" + " " + 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!