-
Notifications
You must be signed in to change notification settings - Fork 315
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
[Karan Dev Sapra] Duke Increments #356
base: master
Are you sure you want to change the base?
Changes from 18 commits
65f72a8
0112efe
cfd6da7
6e6ace1
a3ca5a4
7b60e81
6dfbb70
87fb84e
24796d0
f302e6b
e5ec66b
76204fe
9a81e57
4ff446c
a504967
0ec0fe4
1a541a9
e26dc70
313de67
9559d8a
35acea9
e8daed2
1c21635
8219d3d
808d2dd
e5b08a3
e56bf4d
dfe5277
16f1bda
5304e70
d9893cc
d708610
0f9f7bd
2e58d6b
59acd1a
5131533
85bffc6
07298f9
8f60f0f
acb5af9
8a19a8b
e461b9a
8d53e2c
af61ae9
b54fc5f
015f926
022e6c7
1360dee
540fb54
a966f0a
63aebb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import java.io.IOException; | ||
|
||
public class AddCommand extends Command { | ||
|
||
private Task task; | ||
|
||
public AddCommand (Task task) { | ||
this.task = task; | ||
} | ||
|
||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws IOException { | ||
|
||
taskList.add(task); | ||
|
||
ui.add(taskList.list); | ||
|
||
storage.save(taskList.list); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import java.io.IOException; | ||
|
||
public abstract class Command { | ||
|
||
public abstract void execute (TaskList taskList, Ui ui, Storage storage) throws IOException; | ||
|
||
public boolean isExit() { | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public class DateClass { | ||
|
||
public static Date stringToDate (String string) { | ||
|
||
SimpleDateFormat format = new SimpleDateFormat("d/MM/yyyy HHmm"); | ||
|
||
Date date = null; | ||
|
||
try { | ||
date = format.parse(string); | ||
} catch (ParseException e) { | ||
|
||
} | ||
|
||
return date; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import java.util.Date; | ||
|
||
public class Deadline extends Task { | ||
|
||
protected String by; | ||
|
||
protected Date date; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.by = by; | ||
|
||
this.date = DateClass.stringToDate(by); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + " (by: " + by + ")"; | ||
} | ||
|
||
@Override | ||
public String saveFormat() { | ||
return String.format("D | %d | %s | %s", this.isDone ? 1 : 0, this.description, this.by); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import java.io.IOException; | ||
|
||
public class DeleteCommand extends Command { | ||
|
||
int index; | ||
|
||
public DeleteCommand (int index) { | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws IOException { | ||
|
||
Task task = taskList.delete(index); | ||
|
||
ui.delete(taskList.list, task); | ||
|
||
storage.save(taskList.list); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import java.io.IOException; | ||
|
||
public class DoneCommand extends Command { | ||
|
||
int index; | ||
|
||
public DoneCommand (int index) { | ||
this.index = index; | ||
} | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws IOException { | ||
|
||
Task task = taskList.done(this.index); | ||
|
||
ui.done(task); | ||
|
||
storage.save(taskList.list); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,51 @@ | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.util.Scanner; | ||
|
||
public class Duke { | ||
public static void main(String[] args) { | ||
String logo = " ____ _ \n" | ||
+ "| _ \\ _ _| | _____ \n" | ||
+ "| | | | | | | |/ / _ \\\n" | ||
+ "| |_| | |_| | < __/\n" | ||
+ "|____/ \\__,_|_|\\_\\___|\n"; | ||
System.out.println("Hello from\n" + logo); | ||
|
||
private Storage storage; | ||
private TaskList tasks; | ||
private Ui ui; | ||
|
||
public Duke(String filePath, String folderPath) { | ||
ui = new Ui(); | ||
storage = new Storage(filePath, folderPath); | ||
try { | ||
tasks = new TaskList(storage.retrieve()); | ||
} catch (FileNotFoundException e) { | ||
|
||
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. Would it be better to inform the user about the exception? |
||
try { | ||
storage.makeDirectory(folderPath); | ||
tasks = new TaskList(); | ||
} catch (IOException ex) { | ||
ui.abort(); | ||
System.exit(0); | ||
} | ||
} | ||
} | ||
|
||
public void run() { | ||
ui.greeting(); | ||
boolean isExit = false; | ||
while (!isExit) { | ||
try { | ||
String fullCommand = ui.readCommand(); | ||
// ui.showLine(); // show the divider line ("_______") | ||
Command c = Parser.parse(fullCommand); | ||
c.execute(tasks, ui, storage); | ||
isExit = c.isExit(); | ||
} catch (DukeException | IOException e) { | ||
ui.showError(e.getMessage()); | ||
} finally { | ||
//ui.showLine(); | ||
} | ||
} | ||
} | ||
|
||
|
||
public static void main(String[] args) throws DukeException, IOException { | ||
|
||
new Duke("../data/duke.txt", "../data").run(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
public class DukeException extends Exception { | ||
|
||
public DukeException (String message) { | ||
super(message); | ||
} | ||
|
||
public static DukeException emptyDescription () { | ||
return new DukeException("☹ OOPS!!! The description of a todo cannot be empty."); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import java.util.Date; | ||
|
||
public class Event extends Task { | ||
|
||
protected String at; | ||
|
||
protected Date date; | ||
|
||
public Event(String description, String at) { | ||
super(description); | ||
this.at = at; | ||
|
||
this.date = DateClass.stringToDate(at); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + " (at: " + at + ")"; | ||
} | ||
|
||
@Override | ||
public String saveFormat() { | ||
return String.format("E | %d | %s | %s", this.isDone ? 1 : 0, this.description, this.at); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import java.io.IOException; | ||
|
||
public class ExitCommand extends Command { | ||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws IOException { | ||
ui.bye(); | ||
} | ||
|
||
@Override | ||
public boolean isExit() { | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import java.io.IOException; | ||
|
||
public class ListCommand extends Command { | ||
|
||
|
||
@Override | ||
public void execute(TaskList taskList, Ui ui, Storage storage) throws IOException { | ||
ui.list(); | ||
taskList.list(); | ||
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 might want to make the two methods here somewhat clearer in terms of naming? Both |
||
} | ||
} |
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.
Would it be better to handle the exception instead of doing nothing?
Let's say you can throw ParseException to Duke class and let it handle the output/ message.