Skip to content
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

[iapetusbob] iP #385

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
106e38e
Level 1
iapetusbob Jan 19, 2023
415a967
Level-2
iapetusbob Jan 20, 2023
48aff3a
Level-3
iapetusbob Jan 20, 2023
1368b37
Level-5
iapetusbob Jan 30, 2023
d21bb6e
Level-5
iapetusbob Jan 30, 2023
1bc4747
Level-7
iapetusbob Feb 5, 2023
dff68ac
Level-8
iapetusbob Feb 6, 2023
b6de93c
MoreOOP
iapetusbob Feb 8, 2023
aca63fa
Merge pull request #1 from iapetusbob/add-gradle-support
iapetusbob Feb 9, 2023
b8ea184
add-gradle-support
iapetusbob Feb 9, 2023
be1870f
Merge pull request #2 from iapetusbob/origin/add-gradle-support
iapetusbob Feb 9, 2023
871d399
JAR
iapetusbob Feb 10, 2023
1200509
junit
iapetusbob Feb 11, 2023
18fa619
javadocs
iapetusbob Feb 14, 2023
01503ed
javadocs
iapetusbob Feb 14, 2023
8e458d8
A-Checkstyle
iapetusbob Feb 17, 2023
6a711f4
Merge pull request #4 from iapetusbob/branch-A-CheckStyle
iapetusbob Feb 17, 2023
dd7e692
branch-Level-10
iapetusbob Feb 17, 2023
2ddf308
Merge branch 'branch-Level-10' of https://github.com/iapetusbob/ip in…
iapetusbob Feb 17, 2023
b1cb5a1
branch-Level-10
iapetusbob Feb 17, 2023
6fd1a4a
Merge pull request #6 from iapetusbob/branch-Level-10
iapetusbob Feb 17, 2023
fb02add
readme
iapetusbob Feb 17, 2023
f61a7bc
readme
iapetusbob Feb 17, 2023
70e7de6
readme
iapetusbob Feb 17, 2023
f4571a2
readme
iapetusbob Feb 17, 2023
2085c41
readme
iapetusbob Feb 17, 2023
849b2f2
readme
iapetusbob Feb 17, 2023
86e7a1b
readme
iapetusbob Feb 17, 2023
a1a0df9
readme
iapetusbob Feb 17, 2023
8b60111
readme
iapetusbob Feb 17, 2023
fdc1e3a
readme
iapetusbob Feb 17, 2023
bb0e340
readme
iapetusbob Feb 17, 2023
cd0cdf7
jar
iapetusbob Feb 17, 2023
8b39140
L4
iapetusbob Feb 20, 2023
f292f45
UG
iapetusbob Feb 23, 2023
a1926cb
v0.3
iapetusbob Mar 19, 2023
29bb3f4
find command!!!11
iapetusbob Mar 20, 2023
2cc7f63
mark command fixed
iapetusbob Mar 20, 2023
b293347
fixed find
iapetusbob Mar 20, 2023
3e90bf7
fixed adding dupes, prettified the things
iapetusbob Mar 20, 2023
6164973
squished bugs
iapetusbob Mar 20, 2023
27a0ec7
userguide
iapetusbob Mar 20, 2023
da35a31
Update UserGuide.md
iapetusbob Mar 20, 2023
6d6ffd5
Update README.md
iapetusbob Mar 20, 2023
f416d54
Delete Ui.png
iapetusbob Mar 20, 2023
944c856
Add files via upload
iapetusbob Mar 20, 2023
7a83d29
Update README.md
iapetusbob Mar 20, 2023
3efbfac
Delete Ui.png
iapetusbob Mar 20, 2023
e6529b1
Add files via upload
iapetusbob Mar 20, 2023
77f7e42
Update README.md
iapetusbob Mar 20, 2023
00a2151
Update UserGuide.md
iapetusbob Mar 24, 2023
f4deb72
tests
iapetusbob Mar 24, 2023
1023e23
Merge branch 'master' of https://github.com/iapetusbob/ip
iapetusbob Mar 24, 2023
e1967ba
Update UserGuide.md
iapetusbob Mar 24, 2023
2bc8be0
Update UserGuide.md
iapetusbob Mar 24, 2023
f7a334c
Update UserGuide.md
iapetusbob Mar 24, 2023
1fb6fe7
Update README.md
iapetusbob Mar 26, 2023
20642d9
Update README.md
iapetusbob Mar 26, 2023
bae5a96
Update README.md
iapetusbob Mar 26, 2023
22ea094
bug fixes
iapetusbob Mar 26, 2023
b79fc3d
bug fixes
iapetusbob Mar 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 179 additions & 1 deletion src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,188 @@
import java.util.Scanner;
import java.util.Arrays;
import DukeHelpfulCode.*;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps you can ensure import classes are stated explicitly to meet coding standards.
Eg. import DukeHelpfulCode.Task;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package name should also be in all lower case to meet coding standards.



public class Duke {

private static String LINEBREAK = "_________________________________________________________________\n";
private static UserList USERLIST = new UserList();

public static void main(String[] args) {
greeting();
takeCmd();
}

private static void takeCmd() {
/**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detailed JavaDoc comment that tells others what each command does. However, JavaDoc comment should be outside and above the function to meet coding standards.

Is it possible to separate the code into smaller functions that will be called? This makes that code looks cleaner.

* Controls flow, logic, checking of the user inputs as commands.
* Recognized user commands:
* bye -> quit
* todo -> creates todo task
* deadline-> creates deadline task
* event -> creates event task
* list -> display
* mark -> marks the (i-1)th item as done, since UserList is 0-index
* unmark -> unmarks the (i-1)th item
* Unrecognized commands will simply be echoed then Duke waits next command.
*/
Scanner userCmd = new Scanner(System.in);
String askForCmd = LINEBREAK + "Okay. What would you like to do next?\nIf you want to exit DUKE, type 'bye'!\n";
String[] cmd = userCmd.nextLine().split(" ");
if (cmd[0].equals("bye")) {
exit();
} else if (cmd[0].equals("todo")) {
String taskName = "";
if (cmd.length>1) {
for (int i = 1; i < cmd.length; i++) {
taskName += cmd[i] + " ";
}
} else {
System.out.println("Sorry, I didn't quite catch that. What task would you like to add?\n" + LINEBREAK);
taskName = userCmd.nextLine();
}
addTodo(new Todo(taskName));
System.out.println(askForCmd);
takeCmd();
} else if (cmd[0].equals("deadline")){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to split commands into seperate functions

String taskName = "";
String dateTime = "";
if (cmd.length>1) {
for (int i = 1; i < cmd.length; i++) {
if (!cmd[i].equals("/by")){
taskName += cmd[i] + " ";
} else {
i++;
dateTime += cmd[i] + " ";
}
}
} else {
System.out.println("Sorry, I didn't quite catch that. What task would you like to add?\n" + LINEBREAK);
cmd = userCmd.nextLine().split(" ");
for (int i = 0; i < cmd.length; i++) {
if (!cmd[i].equals("/by")){
taskName += cmd[i] + " ";
} else {
i++;
dateTime += cmd[i] + " ";
}
}
}
addDeadline(new Deadline(taskName, dateTime));
System.out.println(askForCmd);
takeCmd();
} else if (cmd[0].equals("event")){
String taskName = "";
String startDateTime = "";
String endDateTime = "";
if (cmd.length > 1) {
int from = Arrays.asList(cmd).indexOf("/from");
int to = Arrays.asList(cmd).indexOf("/to");
for (int i = 1; i < cmd.length; i++){
if (i < from) {
taskName += cmd[i] + " ";
} else if (i > from && i < to){
startDateTime += cmd[i] + " ";
} else if (i > to){
endDateTime += cmd[i] + " ";
}
}
} else {
System.out.println("Sorry, I didn't quite catch that. What task would you like to add?\n" + LINEBREAK);
cmd = userCmd.nextLine().split(" ");
int from = Arrays.asList(cmd).indexOf("/from");
int to = Arrays.asList(cmd).indexOf("/to");
for (int i = 0; i < cmd.length; i++){
if (i < from) {
taskName += cmd[i] + " ";
} else if (i > from && i < to){
startDateTime += cmd[i] + " ";
} else if (i > to){
endDateTime += cmd[i] + " ";
}
}
}
addEvent(new Event(taskName, startDateTime, endDateTime));
System.out.println(askForCmd);
takeCmd();
} else if (cmd[0].equals("list")){
list();
System.out.println(askForCmd);
takeCmd();
} else if (cmd[0].equals("mark") || cmd[0].equals("unmark")) {
String markUnmark = cmd[0];
if (userCmd.hasNext()) {
try {
int listIdx = Integer.parseInt(userCmd.next());
mark(markUnmark, listIdx);
System.out.println(askForCmd);
takeCmd();
} catch (NumberFormatException e) {
System.out.println("Sorry, I don't understand what you want to me to do.\n" + askForCmd);
takeCmd();
}
} else {
System.out.println("Sorry, I don't understand what you want to me to do.\n" + askForCmd);
takeCmd();
}
} else {
System.out.println(askForCmd);
takeCmd();
}
}

private static void greeting() {
/**
* Start-up logo and message
*/
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
System.out.println("Hello from\n" + logo + LINEBREAK + "Type 'bye' to exit!\n" + LINEBREAK + "What can I do for you today?\n");
}

private static void exit() {
/**
* Exits Duke.
* userCmd "bye"
*/
System.out.println("Bye. Hope to see you again soon!\n" + LINEBREAK);
}

private static void addTodo(Todo todo){
USERLIST.addToDo(todo);
}

private static void addDeadline(Deadline dl){
USERLIST.addDeadline(dl);
}

private static void addEvent(Event e){
USERLIST.addEvent(e);
}

private static void list(){
/**
* userCmd "list"
* Displays userList vertically.
*/
if (USERLIST.len() == 0){
System.out.println(LINEBREAK + "Oops, it seems that your list is empty!\n");
} else {
System.out.println(LINEBREAK + "Your list looks like this:\n" + USERLIST.toString() + LINEBREAK);
}
}

private static void mark(String markCmd, int idx){
try {
USERLIST.mark(markCmd, idx);
} catch (UserList.TaskNotInListException e) {
System.out.println("Sorry, can't find that task.\n");
} catch (UserList.TaskAlrMarkException e){
System.out.println("The Task has already been marked.\n");
}
}

}
16 changes: 16 additions & 0 deletions src/main/java/DukeHelpfulCode/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package DukeHelpfulCode;

public class Deadline extends Task{
// tasks that need to be done before a specific date/time
private String dateTime;

public Deadline(String name, String dateTime) {
super(name);
this.dateTime = dateTime;
}

public String toString(){
return "[D] " + super.toString() + " (by: " + this.dateTime + ")";
}

}
19 changes: 19 additions & 0 deletions src/main/java/DukeHelpfulCode/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package DukeHelpfulCode;

public class Event extends Task{
// tasks that start at a specific date/time and ends at a specific date/time

private String startDateTime;
private String endDateTime;

public Event(String name, String startDateTime, String endDateTime) {
super(name);
this.startDateTime = startDateTime;
this.endDateTime = endDateTime;
}

public String toString() {
return "[E] " + super.toString() + " (from: " + this.startDateTime + " to: " + this.endDateTime + ")";
}

}
59 changes: 59 additions & 0 deletions src/main/java/DukeHelpfulCode/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package DukeHelpfulCode;

public class Task {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JavaDoc for classes should also be outside and above the class itself.

/**
* Task class for things added to the UserList
* Methods:
* markAsDone -> mark Task as done if not done and vice versa.
*/

private static String LINEBREAK = "_________________________________________________________________\n";
private String name;
private Boolean isDone = false;

public Task (String name) {
this.name = name;
}

public String getName() {
return this.name;
}

public boolean isDone(){
return isDone;
}

public String toString() {
/**
* Returns "[done] Task"
*/
char doneX = ' ';
if (isDone) {
doneX = 'X';
}
return "[" + doneX + "]" + " " + name;
}

public boolean equals(Object obj){
if (obj instanceof Task) {
Task objTask = (Task) obj;
return objTask.name.equals(this.name);
} else {
return false;
}
}

public void mark() {
/**
* Marks Task as done if not done and vice versa.
*/
if (isDone) {
System.out.println(LINEBREAK + "OK, '" + this.name + "' has been marked as Not Done.\n");
isDone = false;
} else {
System.out.println(LINEBREAK + "OK, '" + this.name + "' has been marked as Done.\n");
isDone = true;
}
}

}
15 changes: 15 additions & 0 deletions src/main/java/DukeHelpfulCode/Todo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package DukeHelpfulCode;

public class Todo extends Task{
// tasks without any date/time atached to it
public Todo(String name) {
super(name);
}

public String toString(){
return "[T] " + super.toString();
}



}
Loading