Skip to content
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
65f72a8
Add support for Gradle workflow
j-lum Aug 6, 2019
0112efe
Add sample checkstyle configuration
j-lum Aug 12, 2019
cfd6da7
Change file mode on `gradle` to be executable
j-lum Aug 18, 2019
6e6ace1
Merge pull request #12 from j-lum/gradle+x
j-lum Aug 18, 2019
a3ca5a4
Add configuration for console applications
j-lum Aug 20, 2019
7b60e81
Merge pull request #13 from j-lum/javaexec
j-lum Aug 21, 2019
69d98fe
Level-1
Aug 27, 2019
2cde05a
added Level-1, ACTUAL.TXT, EXPECTED.txt, input.txt, runtest.sh
Aug 27, 2019
6522dbc
Change in location of test-ui-text folder
Aug 27, 2019
e42b83c
added level 2
Aug 27, 2019
88723af
added level 3, added Task.java to represent Task
Sep 4, 2019
c708f13
added level 4 and 5, with error handling and separate class files to …
Sep 5, 2019
a526b71
added level-6
Sep 5, 2019
3ff017e
fixed printing error for list
Sep 10, 2019
27a6b76
Revert "fixed printing error for list"
Sep 10, 2019
51c544f
Revert "fixed printing error for list"
Sep 10, 2019
fee74d8
added Level-7
Sep 10, 2019
13c47ef
added Level-8
Sep 10, 2019
985ff1b
Merge branch 'branch-Level-7'
Sep 10, 2019
198f8fe
added level-9, with changes to level-8
Sep 11, 2019
345e316
added increments: A-MoreOOP, A-Packages
Sep 17, 2019
4c122a8
added test code folder
Sep 17, 2019
bb0807e
Merge branch 'gradle' of https://github.com/bitterg0d/duke
Sep 17, 2019
c4493e8
added gradle plugins: shadowjar
Sep 17, 2019
331d9c1
Added JavaDoc comments for code
Sep 17, 2019
5a0f754
Tweaked the code to comply with coding standard
Sep 17, 2019
ce5cb34
added javaFX plugin, completed 3/4 of GUI
Sep 18, 2019
cb6776e
added A-JavaFx and Level-10 GUI
Sep 18, 2019
ff8c0e0
added help guidance for users, packaged dialogbox/main/mainwindow int…
Sep 29, 2019
8a8d5ba
updated README.md user guide, added max width and padding of dialog box
Sep 29, 2019
5f7260e
resolved checkbox issue, updated jar version number
Sep 29, 2019
9818dd6
updated link of Ui to a working link
Sep 29, 2019
ba34f15
Set theme jekyll-theme-slate
bitterg0d Sep 29, 2019
4597d26
Set theme jekyll-theme-slate
bitterg0d Sep 29, 2019
8800c86
Set theme jekyll-theme-slate
bitterg0d Sep 29, 2019
40fff66
Set theme jekyll-theme-slate
bitterg0d Sep 29, 2019
7f54bc0
updated user guide
Sep 29, 2019
304706f
Merge branch 'master' of https://github.com/bitterg0d/duke
Sep 29, 2019
7c9ad7b
fixed typos in README.md
Sep 30, 2019
3d8bcd7
edited inline code
Sep 30, 2019
91c2f8e
edited README.md
Sep 30, 2019
3b91222
edited README.md
Sep 30, 2019
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
50 changes: 50 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DateTimeException;
import java.util.Date;

public class Deadline extends Task {

private SimpleDateFormat deadline;
protected String by;
private Date date;
protected int dd, mm, yyyy, hrs, min, time;

public Deadline(String description, String by) throws DateTimeException {
super(description);
this.by = by;
this.type = "D";

this.deadline = new SimpleDateFormat("dd/MM/yyyy HHmm");
}

@Override
public String getType() {
return this.type;
}

@Override
public String getBy() {
return this.by;
}

public String convertEventTime() throws ParseException, DateTimeException {
Comment thread
bitterg0d marked this conversation as resolved.
Outdated

try {
date = deadline.parse(this.by);
return deadline.format(date);
} catch (ParseException exception) {
System.out.println("\u2639 OOPS!!! Please enter a valid deadline");
}
return "";
}

@Override
public String toString() {
try {
return "[D]" + super.toString() + " (by: " + convertEventTime() + ")";
} catch (ParseException exception) {
return "Error";
}
}
}
202 changes: 200 additions & 2 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,208 @@
import java.io.IOException;
import java.text.ParseException;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;

//import java.io.IOException;
//import java.text.ParseException;
Comment thread
bitterg0d marked this conversation as resolved.
Outdated

public class Duke {
public static void main(String[] args) {

private ArrayList<Task> list;
private Saved savedFile;
private Scanner scan;
final private static String LINE = "____________________________________________________________";

public static void main(String[] args) throws IOException, ParseException {
new Duke("src/main/java/data.txt").run();
}

public Duke(String filePath) throws IOException, ParseException {
scan = new Scanner(System.in);
savedFile = new Saved(filePath);
list = savedFile.loadData();
}

public void run() throws IOException, ParseException {

final String GOT_IT = "Got it. I've added this task:";
Comment thread
bitterg0d marked this conversation as resolved.
Outdated
String cmd;

printIntro();

Boolean isNotBye = true;
while(isNotBye) {
cmd = scan.nextLine();
String cmdArr[] = cmd.split(" ", 2);
String firstWord = cmdArr[0];

switch (firstWord) {
case "bye":
printLine();
printDuke("Bye. Hope to see you again soon!");
printLine();
isNotBye = false;
break;

case "list":
printLine();
if (list.isEmpty()) {
System.out.println(" There is nothing in your list.");
printLine();
break;
}
printList(list);
break;

case "done":
printLine();
Comment thread
bitterg0d marked this conversation as resolved.
Outdated
int taskNum = Integer.valueOf(cmdArr[1]);
list.get(taskNum - 1).isDone(true);
printDuke("Nice! I've marked this task as done");
System.out.println(" " + taskNum + ". [" + list.get(taskNum - 1).getStatusIcon() + "]"
+ list.get(taskNum - 1).getDesc());
Comment thread
bitterg0d marked this conversation as resolved.
Outdated
printLine();
break;

case "todo":
try {
String task = cmdArr[1];
Todo todo = new Todo(task);
list.add(todo);

//output
Comment thread
bitterg0d marked this conversation as resolved.
Outdated
printLine();
printDuke(GOT_IT);
printDuke(todo.toString());
printDuke("Now you have " + list.size() + " tasks in the list");
printLine();
} catch (ArrayIndexOutOfBoundsException exception) {
printLine();
printDuke("\u2639 OOPS!!! The description of a todo cannot be empty.");
printLine();
}
break;

case "deadline":
try {
Comment thread
bitterg0d marked this conversation as resolved.
Outdated
String taskAndDate = cmdArr[1];
String dl[] = taskAndDate.split("/", 2);
Comment thread
bitterg0d marked this conversation as resolved.
Outdated
try {
Comment thread
bitterg0d marked this conversation as resolved.
Outdated
String by = dl[1].substring(3);
Deadline deadline = new Deadline(dl[0], by);
list.add(deadline);
//output
printDuke(GOT_IT);
printDuke(deadline.toString());
printDuke("Now you have " + list.size() + " tasks in the list");
printLine();
} catch (ArrayIndexOutOfBoundsException exception) {
printLine();
printDuke("\u2639 OOPS!!! Please enter when the deadline is due");
printLine();
}
} catch (ArrayIndexOutOfBoundsException exception) {
printLine();
printDuke("\u2639 OOPS!!! The description of a deadline cannot be empty.");
printLine();
}
break;

case "event":
try {
String eventAndDate = cmdArr[1];
String e[] = eventAndDate.split("/", 2);
try {
String at = e[1].substring(3);
Event event = new Event(e[0], at);
list.add(event);

//output
printLine();
printDuke(GOT_IT);
printDuke(event.toString());
printDuke("Now you have " + list.size() + " tasks in the list");
printLine();
} catch (ArrayIndexOutOfBoundsException exception) {
printLine();
printDuke("\u2639 OOPS!!! Please enter when the event is happening");
printLine();
}
} catch (ArrayIndexOutOfBoundsException exception) {
printLine();
printDuke("\u2639 OOPS!!! The description of an event cannot be empty.");
printLine();
}
break;

case "delete":
try {
int deleteNum = Integer.valueOf(cmdArr[1]);
Task deletedTask = list.get(deleteNum - 1);
list.remove(deleteNum - 1);

printLine();
printDuke("Noted. I've removed this task:");
printDuke(deletedTask.toString());
printDuke("Now you have " + list.size() + " tasks in the list");
printLine();
} catch (ArrayIndexOutOfBoundsException exception) {
printLine();
printDuke("\u2639 OOPS!!! Please add the task number");
printLine();
}
break;

case "find":
String keyword = cmdArr[1];
ArrayList<Task> matchingTasks = new ArrayList<>();
for (Task task : list) {
if (task.getDesc().contains(keyword)) {
matchingTasks.add(task);
}
}
printList(matchingTasks);
break;
default:
printLine();
printDuke("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
printLine();
}
}
savedFile.saveToFile(list);
}

public static void printIntro() {
/*
Comment thread
bitterg0d marked this conversation as resolved.
Outdated
Comment thread
bitterg0d marked this conversation as resolved.
Outdated
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
+ "| | | | | | | |/ / _ \\\n"
+ "| |_| | |_| | < __/\n"
+ "|____/ \\__,_|_|\\_\\___|\n";
System.out.println("Hello from\n" + logo);
*/
printLine();
System.out.println(" Hello! I'm Duke");
System.out.println(" What can I do for you?");
printLine();
}
public static void printLine() {
Comment thread
bitterg0d marked this conversation as resolved.
Outdated
System.out.println(" " + LINE);
}

public static void printDuke(String toPrint) {
System.out.println(" " + toPrint);
}
public void printList(ArrayList<Task> list) {
System.out.println(" Here are the tasks in your list:");
for (int i = 0; i < list.size(); i++) {
Task task = list.get(i);
System.out.println(" " + (i + 1) + ". " + task.toString());

}

printLine();
}
}
}
45 changes: 45 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DateTimeException;
import java.util.Date;
import java.time.LocalTime;
Comment thread
bitterg0d marked this conversation as resolved.
Outdated

public class Event extends Task {

protected String at;
private SimpleDateFormat eventTime;
private Date date;
//protected int dd, mm, yyyy, startTime, startHrs, startMin, endTime, endHrs, endMin;
Comment thread
bitterg0d marked this conversation as resolved.
Outdated

public Event(String description, String at) throws DateTimeException {
super(description);
this.at = at.trim();
this.event = "event";
this.type = "E";

eventTime = new SimpleDateFormat("dd/MM/yyyy HHmm");
}

@Override
public String getType() {
return this.type;
}

@Override
public String getAt() {
return this.at;
}

public String convertEventTime() throws ParseException, DateTimeException {
this.date = eventTime.parse(this.at);
return this.eventTime.format(date);
}
@Override
public String toString() {
try {
return "[E]" + super.toString() + " (at: " + convertEventTime() + ")";
} catch (ParseException exception) {
return "Error";
Comment thread
bitterg0d marked this conversation as resolved.
}
}
}
74 changes: 74 additions & 0 deletions src/main/java/Saved.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Scanner;

import java.io.FileWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Saved {
private String filePath;

public Saved(String filePath) {
this.filePath = filePath;
}

public ArrayList<Task> loadData() throws FileNotFoundException, ParseException {
Comment thread
bitterg0d marked this conversation as resolved.
Outdated
File file = new File(filePath);
Scanner scan = new Scanner(file);

ArrayList<Task> list = new ArrayList<>();

while(scan.hasNext()) {
String[] text = scan.nextLine().split(" \\| ", 4);

Task t;

switch (text[0]) {
case "T":
t = new Todo(text[2]);
break;
case "D":
t = new Deadline(text[2], text[3]);
break;
case "E":
t = new Event(text[2], text[3]);
break;
default:
t = new Task("");
break;
}

if (text[1].equals("1")) {
t.isDone = true;
Comment thread
bitterg0d marked this conversation as resolved.
Outdated
}

list.add(t);
}
return list;
}

public void saveToFile(ArrayList<Task> list) throws IOException, ParseException {
FileWriter newFile = new FileWriter(this.filePath);
String listToFile = "";
String s;

for (Task task: list) {
if (task instanceof Event) {
s = "E" + " | "+ task.getDone() + " | " + task.getDesc() + " | " + task.getAt();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rather than having multiple if else statements, you can create an abstract method on the Task class that converts the task to a suitable storage format.

} else if (task instanceof Deadline) {
s = "D | " + task.getDone() + " | " + task.getDesc() + " | " + task.getBy();
} else {
s = "T | " + task.getDone() + " | " + task.getDesc();
}
newFile.write(s);
newFile.write("\n");
}


newFile.write(listToFile);
newFile.flush();
//newFile.close();
}
}
Loading