-
Notifications
You must be signed in to change notification settings - Fork 228
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
base: master
Are you sure you want to change the base?
[Galen Cheung] iP #238
Changes from 13 commits
6a34db9
fd47a56
673692a
faefe9a
6c3d616
ad9bbe1
da4bde2
40a6901
a523da4
7e95fd7
f745f1e
5b68ef4
d250ecc
5acb7f9
ba449dd
8c6c6ff
f2f66f2
5aa35bd
9368796
5dda2d4
7219bb1
2d98d61
82abb8a
8191bc2
652d7ea
e0b227a
ba97fbe
a536d24
d93287f
89640ab
c8a89a6
31c4a9a
18fbc91
ecf269f
3629de4
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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); | ||
} | ||
} |
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; | ||
|
||
/* | ||
* 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(); | ||
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 like how you used a relative path here 👍 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. Thanks :) |
||
} | ||
} | ||
} |
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); | ||
} | ||
} |
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) { | ||
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 public constructor needs a documentation also 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. 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() + ":"; | ||
} | ||
} | ||
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. 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. 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 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); | ||
} | ||
} |
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); | ||
} | ||
} |
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: Duke | ||
|
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.
maybe import of java.io should be in front of java.nio/util coz of lexicographic order
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.
Will correct it, thanks.