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

[Gabriel Waikin Loh Matienzo] iP #504

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
3e87c13
Level-1
GabrielWLM Aug 19, 2021
dc74ffb
Level-2
GabrielWLM Aug 19, 2021
011e3c4
Level-2
GabrielWLM Aug 19, 2021
7645743
Level-3
GabrielWLM Aug 19, 2021
23d0603
Level-4
GabrielWLM Aug 19, 2021
58e344f
Level-5
GabrielWLM Aug 19, 2021
54a6d63
Level-6
GabrielWLM Aug 19, 2021
d2e0d94
branch-Level-7
GabrielWLM Sep 3, 2021
cf01927
branch-Level-8
GabrielWLM Sep 3, 2021
22e65ad
Merge branch 'branch-Level-7'
GabrielWLM Sep 3, 2021
ecf6048
Merge branch 'branch-Level-8'
GabrielWLM Sep 3, 2021
d4758a7
A-MoreOOP
GabrielWLM Sep 3, 2021
0e04a59
A-Packages
GabrielWLM Sep 3, 2021
71bc434
A-JUnit
GabrielWLM Sep 3, 2021
181c271
A-Jar
GabrielWLM Sep 3, 2021
34e99fe
A-JavaDoc
GabrielWLM Sep 3, 2021
402584f
A-CodingStandard
GabrielWLM Sep 3, 2021
39ddf68
Level-9
GabrielWLM Sep 3, 2021
854ba85
Merge branch 'branch-A-JavaDoc'
GabrielWLM Sep 3, 2021
d393651
Merge branch 'branch-A-CodingStandard'
GabrielWLM Sep 3, 2021
8341997
Merge branch 'branch-Level-9'
GabrielWLM Sep 3, 2021
3ca7ec2
A-Gradle
GabrielWLM Sep 3, 2021
dd84115
Merge branch 'branch-A-Gradle'
GabrielWLM Sep 3, 2021
335e18d
Level-10
GabrielWLM Sep 3, 2021
4d72ffc
Level-10
GabrielWLM Sep 3, 2021
6a1743f
Merge branch 'branch-Level-10'
GabrielWLM Sep 3, 2021
516232c
Update sample data
GabrielWLM Sep 10, 2021
f2d95fa
A-Assertions
GabrielWLM Sep 10, 2021
9c9f691
A-CodeQuality
GabrielWLM Sep 10, 2021
dacc19b
Merge pull request #1 from GabrielWLM/branch-A-Assertions
GabrielWLM Sep 10, 2021
62a1cef
Merge branch 'master' into branch-A-CodeQuality
GabrielWLM Sep 10, 2021
70a96dd
Merge pull request #2 from GabrielWLM/branch-A-CodeQuality
GabrielWLM Sep 10, 2021
0378158
Merge pull request #4 from GabrielWLM/add-gradle-support
GabrielWLM Sep 16, 2021
501f341
Refactor duke
GabrielWLM Sep 17, 2021
e19cd3e
import junit dependencies and improve code quality
GabrielWLM Sep 20, 2021
4b8fc0f
add README and Ui screenshot
GabrielWLM Sep 22, 2021
f043b50
Set theme jekyll-theme-modernist
GabrielWLM Sep 22, 2021
8000bc1
fix folder creation and jar execution
GabrielWLM Sep 27, 2021
4fc6227
Merge branch 'master' of https://github.com/GabrielWLM/ip
GabrielWLM Sep 27, 2021
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
34 changes: 17 additions & 17 deletions .gitignore
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
18 changes: 9 additions & 9 deletions CONTRIBUTORS.md
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/).
48 changes: 24 additions & 24 deletions README.md
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
____ _
| _ \ _ _| | _____
| | | | | | | |/ / _ \
| |_| | |_| | < __/
|____/ \__,_|_|\_\___|
```
58 changes: 29 additions & 29 deletions docs/README.md
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
```
15 changes: 15 additions & 0 deletions src/main/java/Dates.java
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"));
}
}
150 changes: 140 additions & 10 deletions src/main/java/Duke.java
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");
Copy link

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.

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>();

Choose a reason for hiding this comment

The 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")) {

Choose a reason for hiding this comment

The 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));

Choose a reason for hiding this comment

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

substring(0,4)
substring(0, 4)

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 .+")) {
Copy link

Choose a reason for hiding this comment

The 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);
Copy link

Choose a reason for hiding this comment

The 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();
}
}
62 changes: 55 additions & 7 deletions text-ui-test/EXPECTED.TXT
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!
____________________________________________________________
Loading