-
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
[Gabriel Waikin Loh Matienzo] iP #504
base: master
Are you sure you want to change the base?
Changes from 26 commits
d839859
3e87c13
dc74ffb
011e3c4
7645743
23d0603
58e344f
54a6d63
d2e0d94
cf01927
22e65ad
ecf6048
d4758a7
0e04a59
71bc434
181c271
34e99fe
402584f
39ddf68
854ba85
d393651
8341997
3ca7ec2
dd84115
335e18d
4d72ffc
6a1743f
516232c
f2d95fa
9c9f691
dacc19b
62a1cef
70a96dd
0378158
501f341
e19cd3e
4b8fc0f
f043b50
8000bc1
4fc6227
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,17 +1,17 @@ | ||
# IDEA files | ||
/.idea/ | ||
/out/ | ||
/*.iml | ||
|
||
# Gradle build files | ||
/.gradle/ | ||
/build/ | ||
src/main/resources/docs/ | ||
|
||
# MacOS custom attributes files created by Finder | ||
.DS_Store | ||
*.iml | ||
bin/ | ||
|
||
/text-ui-test/ACTUAL.txt | ||
text-ui-test/EXPECTED-UNIX.TXT | ||
# IDEA files | ||
/.idea/ | ||
/out/ | ||
/*.iml | ||
# Gradle build files | ||
/.gradle/ | ||
/build/ | ||
src/main/resources/docs/ | ||
# MacOS custom attributes files created by Finder | ||
.DS_Store | ||
*.iml | ||
bin/ | ||
/text-ui-test/ACTUAL.txt | ||
text-ui-test/EXPECTED-UNIX.TXT |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# Contributors | ||
|
||
Display | Name | Github Profile | Homepage | ||
---|:---:|:---:|:---: | ||
![](https://avatars0.githubusercontent.com/u/22460123?s=100) | Jeffry Lum | [Github](https://github.com/j-lum/) | [Homepage](https://se.kasugano.moe) | ||
![](https://avatars0.githubusercontent.com/u/1673303?s=100) | Damith C. Rajapakse | [Github](https://github.com/damithc/) | [Homepage](https://www.comp.nus.edu.sg/~damithch/) | ||
# I would like to join this list. How can I help the project | ||
|
||
For more information, please refer to our [contributor's guide](https://oss-generic.github.io/process/). | ||
# Contributors | ||
Display | Name | Github Profile | Homepage | ||
---|:---:|:---:|:---: | ||
![](https://avatars0.githubusercontent.com/u/22460123?s=100) | Jeffry Lum | [Github](https://github.com/j-lum/) | [Homepage](https://se.kasugano.moe) | ||
![](https://avatars0.githubusercontent.com/u/1673303?s=100) | Damith C. Rajapakse | [Github](https://github.com/damithc/) | [Homepage](https://www.comp.nus.edu.sg/~damithch/) | ||
# I would like to join this list. How can I help the project | ||
For more information, please refer to our [contributor's guide](https://oss-generic.github.io/process/). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
# Duke project template | ||
|
||
This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. | ||
|
||
## Setting up in Intellij | ||
|
||
Prerequisites: JDK 11, update Intellij to the most recent version. | ||
|
||
1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) | ||
1. Open the project into Intellij as follows: | ||
1. Click `Open`. | ||
1. Select the project directory, and click `OK`. | ||
1. If there are any further prompts, accept the defaults. | ||
1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).<br> | ||
In the same dialog, set the **Project language level** field to the `SDK default` option. | ||
3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: | ||
``` | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
``` | ||
# Duke project template | ||
This is a project template for a greenfield Java project. It's named after the Java mascot _Duke_. Given below are instructions on how to use it. | ||
## Setting up in Intellij | ||
Prerequisites: JDK 11, update Intellij to the most recent version. | ||
1. Open Intellij (if you are not in the welcome screen, click `File` > `Close Project` to close the existing project first) | ||
1. Open the project into Intellij as follows: | ||
1. Click `Open`. | ||
1. Select the project directory, and click `OK`. | ||
1. If there are any further prompts, accept the defaults. | ||
1. Configure the project to use **JDK 11** (not other versions) as explained in [here](https://www.jetbrains.com/help/idea/sdk.html#set-up-jdk).<br> | ||
In the same dialog, set the **Project language level** field to the `SDK default` option. | ||
3. After that, locate the `src/main/java/Duke.java` file, right-click it, and choose `Run Duke.main()` (if the code editor is showing compile errors, try restarting the IDE). If the setup is correct, you should see something like the below as the output: | ||
``` | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
# User Guide | ||
|
||
## Features | ||
|
||
### Feature-ABC | ||
|
||
Description of the feature. | ||
|
||
### Feature-XYZ | ||
|
||
Description of the feature. | ||
|
||
## Usage | ||
|
||
### `Keyword` - Describe action | ||
|
||
Describe the action and its outcome. | ||
|
||
Example of usage: | ||
|
||
`keyword (optional arguments)` | ||
|
||
Expected outcome: | ||
|
||
Description of the outcome. | ||
|
||
``` | ||
expected output | ||
``` | ||
# User Guide | ||
## Features | ||
### Feature-ABC | ||
Description of the feature. | ||
### Feature-XYZ | ||
Description of the feature. | ||
## Usage | ||
### `Keyword` - Describe action | ||
Describe the action and its outcome. | ||
Example of usage: | ||
`keyword (optional arguments)` | ||
Expected outcome: | ||
Description of the outcome. | ||
``` | ||
expected output | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public class Event { | ||
|
||
private Event event; | ||
private LocalDate eventDate; | ||
|
||
public Event(String input) { | ||
//create dates from strings | ||
this.eventDate = LocalDate.parse(input); | ||
this.eventDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,140 @@ | ||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
} | ||
} | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
|
||
private static void save(ArrayList<String> tasks) throws IOException { | ||
File f = new File("tasks.txt"); | ||
System.out.print(f.createNewFile()); | ||
FileWriter fw = new FileWriter("tasks.txt"); | ||
for (String task : tasks) { | ||
fw.write(task + System.lineSeparator()); | ||
} | ||
fw.close(); | ||
} | ||
|
||
private static void printFileContents(String filePath) throws FileNotFoundException { | ||
File f = new File(filePath); | ||
Scanner s = new Scanner(f); | ||
while (s.hasNext()) { | ||
System.out.println(s.nextLine()); | ||
} | ||
s.close(); | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
|
||
Scanner scanner = new Scanner(System.in); | ||
|
||
String logo = " _ _ \n" | ||
+ "| | _ _| | _____ \n" | ||
+ "| | | | | | |/ / _ \\\n" | ||
+ "| |___| |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
|
||
ArrayList<String> list = new ArrayList<String>(); | ||
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. Variable 'list' could be more descriptive; i.e, describe the purpose of the variable |
||
int amount = 0; | ||
|
||
String lineBreak = "\t____________________________________________________________"; | ||
System.out.println(lineBreak | ||
+ "\n\t Hello! I'm Luke, your slightly useful personal assistant!\n" | ||
+ "\t What can I do for you, my liege?\n" | ||
+ "\t Type 'list' to show previous inputs\n" | ||
+ "\t Type 'todo TASK' to indicate that TASK has to be done\n" | ||
+ "\t Type 'deadline TASK /by DATE/TIME' to indicate that TASK has to be done by DATE/TIME\n" | ||
+ "\t Type 'event TASK /at DATE/TIME PERIOD' to indicate that TASK occurs at DATE/TIME PERIOD\n" | ||
+ "\t Type 'done #' to indicate that task # has been done\n" | ||
+ "\t Type 'bye' to end\n" | ||
+ lineBreak); | ||
|
||
String response = scanner.nextLine(); | ||
|
||
while (!response.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. I think you should try splitting the logic in this while loop into different files/methods |
||
if (response.equals("list")) { | ||
System.out.println(lineBreak); | ||
System.out.println("\t Here are the tasks in your list:"); | ||
for (int i = 0; i < amount; i++) { | ||
System.out.println("\t " + (i + 1) + "." + list.get(i)); | ||
} | ||
System.out.println(lineBreak); | ||
} else if (response.matches("done ([0-9]|[1-9][0-9])")) { | ||
int taskNo = Integer.parseInt(response.replaceAll("\\D", "")) - 1; | ||
System.out.println(lineBreak); | ||
System.out.println("\t Nice! I've marked this task as done:"); | ||
list.set(taskNo, list.get(taskNo).substring(0,4) + "X" + list.get(taskNo).substring(5)); | ||
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.
|
||
System.out.println("\t " + list.get(taskNo)); | ||
System.out.println(lineBreak); | ||
save(list); | ||
} else if (response.matches("delete ([0-9]|[1-9][0-9])")) { | ||
int taskNo = Integer.parseInt(response.replaceAll("\\D", "")) - 1; | ||
System.out.println(lineBreak); | ||
System.out.println("\t Noted. I've removed this task:"); | ||
System.out.println("\t " + list.get(taskNo)); | ||
System.out.println("\t Now you have " + (amount - 1) + " tasks in the list."); | ||
System.out.println(lineBreak); | ||
list.set(taskNo, "deleted"); | ||
save(list); | ||
} else if (response.matches("todo .+")) { | ||
System.out.println(lineBreak); | ||
System.out.println("\t Got it. I've added this task:"); | ||
System.out.println("\t [T][ ] " + response.substring(5)); | ||
System.out.println("\t Now you have " + (amount + 1) + " tasks in the list."); | ||
System.out.println(lineBreak); | ||
list.add(amount, "[T][ ] " + response.substring(5)); | ||
amount++; | ||
save(list); | ||
} else if (response.matches("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. For response matching, you might benefit from using Enums :) |
||
System.out.println(lineBreak); | ||
System.out.println("\t Got it. I've added this task:"); | ||
int pos = response.indexOf('/'); | ||
list.add(amount, "[D][ ] " | ||
+ response.substring(9, pos - 1) | ||
+ " (by: " + response.substring(response.indexOf('/') + 4) + ")"); | ||
System.out.println("\t " + list.get(amount)); | ||
System.out.println("\t Now you have " + (amount + 1) + " tasks in the list."); | ||
System.out.println(lineBreak); | ||
amount++; | ||
save(list); | ||
} else if (response.matches("event .+")) { | ||
System.out.println(lineBreak); | ||
System.out.println("\t Got it. I've added this task:"); | ||
int pos = response.indexOf('/'); | ||
list.add(amount, "[E][ ] " | ||
+ response.substring(6, pos - 1) | ||
+ " (at: " + response.substring(response.indexOf('/') + 4) + ")"); | ||
System.out.println("\t " + list.get(amount)); | ||
System.out.println("\t Now you have " + (amount + 1) + " tasks in the list."); | ||
System.out.println(lineBreak); | ||
amount++; | ||
save(list); | ||
} else if (response.equals("todo")) { | ||
System.out.println(lineBreak); | ||
System.out.println("☹ OOPS!!! The description of a todo cannot be empty."); | ||
System.out.println(lineBreak); | ||
} else if (response.equals("deadline")) { | ||
System.out.println(lineBreak); | ||
System.out.println("☹ OOPS!!! The description of a deadline cannot be empty."); | ||
System.out.println(lineBreak); | ||
} else if (response.equals("event")) { | ||
System.out.println(lineBreak); | ||
System.out.println("☹ OOPS!!! The description of an event cannot be empty."); | ||
System.out.println(lineBreak); | ||
} else { | ||
System.out.println(lineBreak); | ||
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. You could consider abstracting the System.out.println(lineBreak);
System.out.println(something);
System.out.println(lineBreak); to avoid repeated code |
||
System.out.println("☹ OOPS!!! I'm sorry, but I don't know what that means :-("); | ||
System.out.println(lineBreak); | ||
} | ||
response = scanner.nextLine(); | ||
} | ||
System.out.println(lineBreak); | ||
System.out.println("\t Bye! Talk again sometime!"); | ||
System.out.println(lineBreak); | ||
|
||
scanner.close(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,55 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
|
||
Hello from | ||
_ _ | ||
| | _ _| | _____ | ||
| | | | | | |/ / _ \ | ||
| |___| |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
|
||
____________________________________________________________ | ||
Hello! I'm Luke, your slightly useful personal assistant! | ||
What can I do for you, my liege? | ||
Type 'list' to show previous inputs | ||
Type 'todo TASK' to indicate that TASK has to be done | ||
Type 'deadline TASK /by DATE/TIME' to indicate that TASK has to be done by DATE/TIME | ||
Type 'event TASK /at DATE/TIME PERIOD' to indicate that TASK occurs at DATE/TIME PERIOD | ||
Type 'done #' to indicate that task # has been done | ||
Type 'bye' to end | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Got it. I've added this task: | ||
[T][ ] borrow book | ||
Now you have 1 tasks in the list. | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Got it. I've added this task: | ||
[D][ ] return book (by: Sunday) | ||
Now you have 2 tasks in the list. | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Got it. I've added this task: | ||
[E][ ] project meeting (at: Mon 2-4pm) | ||
Now you have 3 tasks in the list. | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Here are the tasks in your list: | ||
1.[T][ ] borrow book | ||
2.[D][ ] return book (by: Sunday) | ||
3.[E][ ] project meeting (at: Mon 2-4pm) | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Nice! I've marked this task as done: | ||
[D][X] return book (by: Sunday) | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Nice! I've marked this task as done: | ||
[E][X] project meeting (at: Mon 2-4pm) | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Here are the tasks in your list: | ||
1.[T][ ] borrow book | ||
2.[D][X] return book (by: Sunday) | ||
3.[E][X] project meeting (at: Mon 2-4pm) | ||
____________________________________________________________ | ||
____________________________________________________________ | ||
Bye! Talk again sometime! | ||
____________________________________________________________ |
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.
A longer, more descriptive name (like simply
fileWriter
) might be better here.