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

[Galen Cheung] iP #238

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6a34db9
Add level 1-6
cheunggalen Jan 21, 2021
fd47a56
Add test files
cheunggalen Jan 26, 2021
673692a
Add Level-7
cheunggalen Jan 31, 2021
faefe9a
Add Level-8
cheunggalen Jan 31, 2021
6c3d616
Merge branch 'branch-Level-8'
cheunggalen Jan 31, 2021
ad9bbe1
Add A-MoreOOP
cheunggalen Jan 31, 2021
da4bde2
Add JUnit Tests for Task and TaskList
cheunggalen Jan 31, 2021
40a6901
Add A-JavaDoc
cheunggalen Feb 1, 2021
a523da4
Add A-CodingStandard
cheunggalen Feb 1, 2021
7e95fd7
Add Level-9
cheunggalen Feb 1, 2021
f745f1e
Merge branch 'branch-A-CodingStandard'
cheunggalen Feb 1, 2021
5b68ef4
Merge branch 'branch-Level-9'
cheunggalen Feb 1, 2021
d250ecc
Add corrected Level-7
cheunggalen Feb 2, 2021
5acb7f9
Add A-Gradle
cheunggalen Feb 3, 2021
ba449dd
Add modified A-Gradle
cheunggalen Feb 3, 2021
8c6c6ff
Add Level-10
cheunggalen Feb 6, 2021
f2f66f2
Add A-Assertions
cheunggalen Feb 16, 2021
5aa35bd
Add A-CodeQuality
cheunggalen Feb 17, 2021
9368796
Merge pull request #2 from cheunggalen/branch-A-Assertions
cheunggalen Feb 18, 2021
5dda2d4
Merge branch 'master' of https://github.com/cheunggalen/ip
cheunggalen Feb 18, 2021
7219bb1
Merge branch 'master' into branch-A-CodeQuality
cheunggalen Feb 18, 2021
2d98d61
Merge pull request #3 from cheunggalen/branch-A-CodeQuality
cheunggalen Feb 18, 2021
82abb8a
Merge branch 'master' of https://github.com/cheunggalen/ip
cheunggalen Feb 18, 2021
8191bc2
Add C-DetectDuplicates
cheunggalen Feb 18, 2021
652d7ea
Merge pull request #4 from cheunggalen/branch-C-DetectDuplicates
cheunggalen Feb 18, 2021
e0b227a
Merge branch 'master' of https://github.com/cheunggalen/ip
cheunggalen Feb 18, 2021
ba97fbe
Set theme jekyll-theme-midnight
cheunggalen Feb 19, 2021
a536d24
Add A-UserGuide
cheunggalen Feb 19, 2021
d93287f
Add screenshot of Duke, Ui.png into the user guide, README.md.
cheunggalen Feb 19, 2021
89640ab
Merge branch 'master' of https://github.com/cheunggalen/ip
cheunggalen Feb 19, 2021
c8a89a6
Add the modified user guide, README.md.
cheunggalen Feb 19, 2021
31c4a9a
Set theme jekyll-theme-cayman
cheunggalen Feb 19, 2021
18fbc91
Merge branch 'master' of https://github.com/cheunggalen/ip
cheunggalen Feb 19, 2021
ecf269f
Add modified user guide, README.md.
cheunggalen Feb 19, 2021
3629de4
Change shadow version
cheunggalen Mar 7, 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
Empty file added data/duke.txt
Empty file.
Binary file added lib/apiguardian-api-1.0.0-javadoc.jar
Binary file not shown.
Binary file added lib/apiguardian-api-1.0.0-sources.jar
Binary file not shown.
Binary file added lib/apiguardian-api-1.0.0.jar
Binary file not shown.
Binary file added lib/junit-jupiter-5.4.2-javadoc.jar
Binary file not shown.
Binary file added lib/junit-jupiter-5.4.2-sources.jar
Binary file not shown.
Binary file added lib/junit-jupiter-5.4.2.jar
Binary file not shown.
Binary file added lib/junit-jupiter-api-5.4.2-javadoc.jar
Binary file not shown.
Binary file added lib/junit-jupiter-api-5.4.2-sources.jar
Binary file not shown.
Binary file added lib/junit-jupiter-api-5.4.2.jar
Binary file not shown.
Binary file added lib/junit-jupiter-engine-5.4.2-javadoc.jar
Binary file not shown.
Binary file added lib/junit-jupiter-engine-5.4.2-sources.jar
Binary file not shown.
Binary file added lib/junit-jupiter-engine-5.4.2.jar
Binary file not shown.
Binary file added lib/junit-jupiter-params-5.4.2-javadoc.jar
Binary file not shown.
Binary file added lib/junit-jupiter-params-5.4.2-sources.jar
Binary file not shown.
Binary file added lib/junit-jupiter-params-5.4.2.jar
Binary file not shown.
Binary file added lib/junit-platform-commons-1.4.2-javadoc.jar
Binary file not shown.
Binary file added lib/junit-platform-commons-1.4.2-sources.jar
Binary file not shown.
Binary file added lib/junit-platform-commons-1.4.2.jar
Binary file not shown.
Binary file added lib/junit-platform-engine-1.4.2-javadoc.jar
Binary file not shown.
Binary file added lib/junit-platform-engine-1.4.2-sources.jar
Binary file not shown.
Binary file added lib/junit-platform-engine-1.4.2.jar
Binary file not shown.
Binary file added lib/opentest4j-1.1.1-javadoc.jar
Binary file not shown.
Binary file added lib/opentest4j-1.1.1-sources.jar
Binary file not shown.
Binary file added lib/opentest4j-1.1.1.jar
Binary file not shown.
Binary file added src/main/java/Deadline.class
Binary file not shown.
8 changes: 8 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* A type of Task.
*/
public class Deadline extends Task {
public Deadline(String description, String date, String time) {
super(description, date, time, "[D]", false);
}
}
9 changes: 9 additions & 0 deletions src/main/java/DeleteException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* A type of DukeException.
* An exception for bad deletions.
*/
public class DeleteException extends DukeException {
public DeleteException(String error) {
super(error);
}
}
Binary file added src/main/java/Duke.class
Binary file not shown.
57 changes: 50 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,53 @@
import java.util.Scanner;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.IOException;
Copy link

Choose a reason for hiding this comment

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

maybe import of java.io should be in front of java.nio/util coz of lexicographic order

Copy link
Author

Choose a reason for hiding this comment

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

Will correct it, thanks.


/*
* The main class for the Duke app.
*/
public class Duke {
private Storage storage;
private TaskList tasks;
private Ui ui;

public Duke(String filePath) {
ui = new Ui();
storage = new Storage(filePath);
tasks = new TaskList();
}

/*
* Run the Duke app.
*/
public void run() {
Scanner sc = new Scanner(System.in);
ui.reply();
Path path = Paths.get(this.storage.getFilePath());
if (Files.exists(path)) {
this.tasks = storage.readFromFile();
} else {
try {
Files.createDirectories(path.getParent());
Files.createFile(path);
} catch (IOException e) {
e.printStackTrace();
}
}
Parser parser = new Parser(tasks, ui, storage);
while (true) {
String command = sc.nextLine();
parser.insertCommand(command);
parser.process();
if (parser.isFinished()) {
break;
}
}
System.exit(0);
}

public static void main(String[] args) {
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
new Duke("./data/duke.txt").run();

Choose a reason for hiding this comment

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

I like how you used a relative path here 👍

Copy link
Author

Choose a reason for hiding this comment

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

Thanks :)

}
}
}
Binary file added src/main/java/DukeException.class
Binary file not shown.
8 changes: 8 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* The main exception for Duke.
*/
public class DukeException extends Exception {
public DukeException(String error) {
super(error);
}
}
Binary file added src/main/java/Event.class
Binary file not shown.
93 changes: 93 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* A type of Task.
*/
public class Event extends Task {
public Event(String description, String date, String time) {
Copy link

Choose a reason for hiding this comment

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

i think public constructor needs a documentation also

Copy link
Author

Choose a reason for hiding this comment

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

Noted, thanks.

super(description, date, time, "[E]", true);
}

/*
* Convert time from 24h format to 12h format.
* Separate hour and minute by adding a colon.
* Add am or pm depending on time of the day.
* Override Task's timeFormatter since Event has a start and
* end time while Task only has a start time.
*/
@Override
public void formatTime() {
String copy = this.getTime();
String[] sArr = copy.split("-");
String time1 = sArr[0];
String time2 = sArr[1];
char[] cArr = time1.toCharArray();
Integer tensHour = cArr[0] - '0';
Integer onesHour = cArr[1] - '0';
Integer tensMin = cArr[2] - '0';
Integer onesMin = cArr[3] - '0';
String start = "";
boolean isAfternoon = false;
if (!tensHour.equals(0)) {
Integer combinedHour = tensHour * 10 + onesHour;
if (combinedHour >= 12) {
isAfternoon = true;
if (combinedHour >= 13) {
combinedHour -= 12;
}
}
start += combinedHour.toString() + ":";
} else {
if (onesHour.equals(0)) {
start += "12:";
} else {
start += onesHour.toString() + ":";
}
}
if (tensMin == 0) {
start += "0";
} else {
start += tensMin.toString();
}
start += onesMin.toString();
if (isAfternoon) {
start += "pm";
} else {
start += "am";
}
cArr = time2.toCharArray();
tensHour = cArr[0] - '0';
onesHour = cArr[1] - '0';
tensMin = cArr[2] - '0';
onesMin = cArr[3] - '0';
String end = "";
isAfternoon = false;
if (!tensHour.equals(0)) {
Integer combinedHour = tensHour * 10 + onesHour;
if (combinedHour >= 12) {
isAfternoon = true;
if (combinedHour >= 13) {
combinedHour -= 12;
}
}
end += combinedHour.toString() + ":";
} else {
if (onesHour.equals(0)) {
end += "12:";
} else {
end += onesHour.toString() + ":";
}
}
Copy link

@noelmathewisaac noelmathewisaac Feb 4, 2021

Choose a reason for hiding this comment

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

Perhaps you can consider using else if and else statements here instead of a nested if-else to improve code readability? I noticed the same in other places too.

Copy link
Author

Choose a reason for hiding this comment

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

I will check and correct them, thanks.

if (tensMin == 0) {
end += "0";
} else {
end += tensMin.toString();
}
end += onesMin.toString();
if (isAfternoon) {
end += "pm";
} else {
end += "am";
}
String convertedTime = start + "-" + end;
this.setTime(convertedTime);
}
}
9 changes: 9 additions & 0 deletions src/main/java/FindException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* A type of DukeException.
* An exception for when the keyword is not found in the task-list.
*/
public class FindException extends DukeException {
public FindException(String error) {
super(error);
}
}
9 changes: 9 additions & 0 deletions src/main/java/IncompleteException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* A type of DukeException.
* An exception for incomplete commands.
*/
public class IncompleteException extends DukeException {
public IncompleteException(String error) {
super(error);
}
}
3 changes: 3 additions & 0 deletions src/main/java/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: Duke

Binary file added src/main/java/Parser.class
Binary file not shown.
Loading