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

[Caesar Pang] Duke Increments #350

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
60 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
3a7a107
Done Level 1. Added Greeting, Echo and Exit.
caesarpjz Aug 21, 2019
68a7aea
Done Level 2. Added List function and Task function.
caesarpjz Aug 21, 2019
73a6527
Done lvl 3.
caesarpjz Aug 22, 2019
dbb4abc
Done lvl 4.
caesarpjz Aug 22, 2019
176e935
Done lvl 5.
caesarpjz Aug 22, 2019
def7477
Done lvl 6.
caesarpjz Aug 22, 2019
c0f8da0
Clean up my code a bit. Added some edge cases and fixed some issues.
caesarpjz Aug 28, 2019
e89761d
Added a storage class to add tasks into a file. Done a save feature. …
caesarpjz Aug 28, 2019
0c6b61e
Done date changes and formats.
caesarpjz Aug 29, 2019
5d44998
Merge branch 'branch-Level-8'
caesarpjz Aug 29, 2019
091b79e
Done A-MoreOOP. Added more classes.
caesarpjz Aug 29, 2019
c69f71c
Cleaned up code again, Seperated them more into different class. But …
caesarpjz Sep 1, 2019
6ef4264
Done JUnit.
caesarpjz Sep 2, 2019
935d978
Done jar.
caesarpjz Sep 2, 2019
780cd71
Done JavaDoc comments.
caesarpjz Sep 2, 2019
3bad8f8
did some changes.
caesarpjz Sep 2, 2019
8fd78d7
minor changes
caesarpjz Sep 2, 2019
52f5392
Done JavaDocs
caesarpjz Sep 2, 2019
b325ed9
Done Coding Standard.
caesarpjz Sep 2, 2019
49db2a4
Done Level 9 feature (find).
caesarpjz Sep 3, 2019
f3c9622
Merge branch 'branch-A-CodingStandard'
caesarpjz Sep 3, 2019
1f1162d
Merge branch 'branch-Level-9'
caesarpjz Sep 3, 2019
7e5d619
Merge
caesarpjz Sep 3, 2019
cc08ea3
Merge branch 'gradle'
caesarpjz Sep 5, 2019
3cd7815
Added Gradle.
caesarpjz Sep 5, 2019
26474d5
Added Checkstyle.
caesarpjz Sep 5, 2019
ca17439
Done
caesarpjz Sep 5, 2019
987507f
Done some changes
caesarpjz Sep 12, 2019
31ffff6
Clean some things up
caesarpjz Sep 12, 2019
723f40d
Added new things
caesarpjz Sep 12, 2019
9dfc61a
Did some changes. Added Command classes. Did more OOP as well
caesarpjz Sep 14, 2019
20b7205
Did some changes to handle input better.
caesarpjz Sep 16, 2019
72dfe57
Made some changes.
caesarpjz Sep 16, 2019
019698e
Created and added Travis
caesarpjz Sep 23, 2019
d568912
Added D-Expenses.
caesarpjz Sep 25, 2019
6266873
Added C-Help.
caesarpjz Sep 25, 2019
1c7277a
Added some design and started on user guide.
caesarpjz Sep 25, 2019
5782932
Changes to url link
caesarpjz Sep 25, 2019
5666c2b
Experimenting with the width and style of logo.
caesarpjz Sep 25, 2019
b02e389
Changes made to README.md and added images.
caesarpjz Sep 25, 2019
8bed604
Done up packaging and user guide and Ui.png.
caesarpjz Sep 26, 2019
1e0267f
Set theme jekyll-theme-time-machine
caesarpjz Sep 26, 2019
1fe1e75
Changes made to README.
caesarpjz Sep 26, 2019
7d9bd97
Merge branch 'master' of https://github.com/caesarpjz/duke
caesarpjz Sep 26, 2019
0a81e39
Changes to README
caesarpjz Sep 26, 2019
b18a292
Added some JavaDocs.
caesarpjz Sep 26, 2019
26b0cc8
Edited some JavaDocs.
caesarpjz Sep 26, 2019
ae98f7f
Fix test cases.
caesarpjz Sep 26, 2019
d541fae
fixed build.gradle
caesarpjz Sep 27, 2019
7c475c5
Fixed Storage Test.
caesarpjz Sep 27, 2019
b5a4861
Minor mistake in storage file
caesarpjz Sep 27, 2019
9ace65c
Did some edits to allow shadowJar to work.
caesarpjz Sep 27, 2019
ca838a8
Added assertions.
caesarpjz Sep 29, 2019
6222066
Better Code Quality.
caesarpjz Sep 29, 2019
c3a2655
Merge pull request #5 from caesarpjz/branch-A-Assertions
caesarpjz Sep 29, 2019
28874c8
Merge pull request #6 from caesarpjz/branch-A-CodeQuality
caesarpjz Sep 29, 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
40 changes: 40 additions & 0 deletions src/.idea/$PRODUCT_WORKSPACE_FILE$

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/.idea/artifacts/src_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added src/main/java/Deadline.class
Binary file not shown.
32 changes: 32 additions & 0 deletions src/main/java/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
public class Deadline extends Task {

protected String by;

/**
* Constructor for Deadline task.
*
* @param description Deadline task to be added.
* @param by Date of the deadline task.
*/
public Deadline(String description, String by) {
super(description);
this.by = by;
}

/**
* Method to give the string that is to be
* added to the list of tasks.
*
* @return Returns the string to be loaded into
* the file and printed out.
*/
@Override
public String toString() {
String date = formatDate(by);
if (getIsCorrectFormat()) {
return "[D]" + super.toString() + description + " (by: " + date + ")";
} else {
return "Invalid date format!";
}
}
}
Binary file added src/main/java/Duke.class
Binary file not shown.
51 changes: 44 additions & 7 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
import java.io.IOException;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
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;

/**
* Constructor for Duke that takes in a file to add text into.
*
* @param filepath File that the task is added to.
* @throws IOException If the named file exists but is a directory rather than a regular file,
* does not exist but cannot be created, or cannot be opened for any other reason.
*/
public Duke(String filepath) throws IOException {
ui = new Ui();
storage = new Storage(filepath);
try {
tasks = new TaskList(storage.load());
} catch (DukeException | FileNotFoundException e) {
ui.showLoadingError();
tasks = new TaskList();
}
}

/**
* Contains the methods to start the bot and
* start to take in inputs for the bot
*/
public void run() {
ui.greeting();
ui.nextCommand();
}

/**
* Main method.
*/
public static void main(String[] args) throws IOException{
Copy link

Choose a reason for hiding this comment

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

I think this is a bad practice. You should probably catch the IOException somewhere within your code, rather than just throwing it from your main method.

new Duke("todo.txt").run();
}

}
Binary file added src/main/java/DukeException.class
Binary file not shown.
12 changes: 12 additions & 0 deletions src/main/java/DukeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class DukeException extends Exception {

/**
* Constructor for Duke Exceptions.
*
* @param message takes in the error and
* prints it out to the user.
*/
public DukeException(String message) {
super(message);
}
}
Binary file added src/main/java/Event.class
Binary file not shown.
36 changes: 36 additions & 0 deletions src/main/java/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.text.SimpleDateFormat;
import java.util.Date;

public class Event extends Task {

protected String when;
protected boolean isValid;

/**
* Constructor for Event task.
*
* @param description Event task to be attended.
* @param when Date of the event.
*/
public Event(String description, String when) {
super(description);
this.when = when;
}

/**
* Method to give the string that is to be
* added to the list of tasks.
*
* @return Returns the string to be loaded into
* the file and printed out.
*/
@Override
public String toString() {
String date = formatDate(when);
Copy link

Choose a reason for hiding this comment

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

You may want to consider storing this formatted date as a variable, so you don't have to keep converting it all the time.

if (getIsCorrectFormat()) {
return "[E]" + super.toString() + description + " (at: " + date + ")";
} else {
return "Invalid date format!";
}
}
}
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.
13 changes: 13 additions & 0 deletions src/main/java/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import java.util.Scanner;

public class Parser {

Scanner sc = new Scanner(System.in);

/**
* Constructor for Parser class.
*/
public Parser() {

}
}
Binary file added src/main/java/Storage.class
Binary file not shown.
135 changes: 135 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import java.io.*;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Scanner;

public class Storage {
protected static ArrayList<Task> taskList = new ArrayList<Task>();
protected static String file = "todo.txt";

public Storage(String file) {
Copy link

Choose a reason for hiding this comment

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

You should consider removing this parameter, since it doesn't seem to do anything.

Copy link

Choose a reason for hiding this comment

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

You should consider removing this parameter, since it doesn't seem to do anything.


}

/**
* Adds tasks to the file.
*
* @param filepath File that the task is added to.
* @param textToAdd Tasks that needs to be added.
* @throws IOException If the named file exists but
* is a directory rather than a regular file,
* does not exist but cannot be created, or
* cannot be opened for any other reason.
*/
public void addToFile(String filepath, String textToAdd) throws IOException {
FileWriter typer = new FileWriter(filepath, true);
typer.write(textToAdd + System.lineSeparator());
Copy link

Choose a reason for hiding this comment

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

Have to say that I didn't know about this System.lineSeparator() function. Looks like it might be useful for a cross-platform application. Good job 👍👍

typer.close();
}

/**
* Writes task to a file.
* Can be used as a way to overwrite tasks in the file as well.
*
* @param filepath File that the task is added to.
* @param textToAdd Tasks that needs to be added.
* @throws IOException If the named file exists but
* is a directory rather than a regular file,
* does not exist but cannot be created, or
* cannot be opened for any other reason.
*/
public void writeToFile(String filepath, String textToAdd) throws IOException {
FileWriter typer = new FileWriter(filepath);
typer.write(textToAdd);
typer.close();
}

/**
* Counts the number of tasks in the list.
*
* @param filename File that the tasks are in.
* @return Returns the number of tasks.
* @throws IOException If the named file exists but
* is a directory rather than a regular file,
* does not exist but cannot be created, or
* cannot be opened for any other reason.
*/
public static int countLines(String filename) throws IOException {
try (InputStream inputs = new BufferedInputStream(new FileInputStream(filename))) {
byte[] characters = new byte[1024];
Copy link

Choose a reason for hiding this comment

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

Just curious, is there a reason you chose to use byte rather than char?

int readCharacters = inputs.read(characters);
if (readCharacters == -1) {
// no lines to read
return 0;
}
int count = 0;
while (readCharacters == 1024) {
for (int i = 0; i < 1024; ) {
if (characters[i++] == '\n') {
++count;
}
}
readCharacters = inputs.read(characters);
}
// count remaining characters
while (readCharacters != -1) {
for (int i = 0; i < readCharacters; ++i) {
if (characters[i] == '\n') {
++count;
}
}
readCharacters = inputs.read(characters);
}

return count == 0 ? 1 : count;
}
}

/**
* Loads the task into the tasklist
* in TaskList from the file.
*
* @return ArrayList that has been copied from the file.
* @throws IOException If the named file exists but is a directory rather than a regular file,
* does not exist but cannot be created, or cannot be opened for any other reason.
* @throws DukeException If there is nothing in the file to be loaded,
* this exception will be thrown.
*/
public ArrayList<Task> load() throws IOException, DukeException {
File f = new File(file);
Scanner sc = new Scanner(f);
ArrayList<Task> tempList;
if (countLines(file) == 0) {
throw new DukeException("Woahsies wavy! There is nothing in this file!");
} else {
while (sc.hasNext()) {
String task = sc.nextLine();
int index = task.indexOf("[");
String taskType = task.substring(index + 1, index + 2);
int spaceIndex = task.indexOf(" ");
switch (taskType) {
Copy link

Choose a reason for hiding this comment

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

There's a specific convention to follow for switch statements! https://nus-cs2103-ay1920s1.github.io/website/coding-standards/java/intermediate.html

case "T":
Task toDo = new Todo(task.substring(spaceIndex));
taskList.add(toDo);
break;
case "D":
int byIndex = task.indexOf("(");
Task deadline = new Deadline(task.substring(spaceIndex, byIndex - 1),
task.substring(byIndex + 4));
taskList.add(deadline);
break;
case "E":
int atIndex = task.indexOf("(");
Task event = new Event(task.substring(spaceIndex, atIndex - 1),
task.substring(atIndex + 4));
taskList.add(event);
break;
}
}
Ui.printIndent();
System.out.println("Your file has been loaded! :)");
tempList = new ArrayList<Task>(taskList);
return tempList;
}
}
}
Binary file added src/main/java/Task.class
Binary file not shown.
Loading