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

[Rama Venkatesh] iP #503

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d839859
Add Gradle support
May 24, 2020
a5e37a0
Level-1
ramaven Aug 19, 2021
9f114de
Level-2
ramaven Aug 19, 2021
254a843
Level-3
ramaven Aug 19, 2021
dcbae92
Level-4
ramaven Aug 19, 2021
cba3a3a
Level-5
ramaven Aug 19, 2021
ec3c11f
Level-6
ramaven Aug 19, 2021
913b02f
modified expected output
ramaven Sep 2, 2021
75ec70d
enum & refactoring
ramaven Sep 2, 2021
76f877c
enum; refactoring
ramaven Sep 2, 2021
d6610f1
added save functionality
ramaven Sep 5, 2021
6e00451
added save
ramaven Sep 5, 2021
a4d5124
Added DukeDate parse
ramaven Sep 6, 2021
98be0ed
Merge branch 'master' into branch-Level-8
ramaven Sep 6, 2021
bb01e2e
Merge pull request #1 from ramaven/branch-Level-8
ramaven Sep 6, 2021
f54b7d8
fixed getDate() bug
ramaven Sep 6, 2021
6e50441
refactored packages
ramaven Sep 6, 2021
54125a4
removed debug statements
ramaven Sep 6, 2021
c471774
added Command class; OOP
ramaven Sep 6, 2021
b330b0d
adhered coding standard
ramaven Sep 11, 2021
35c0733
adhered coding standard
ramaven Sep 11, 2021
49b8c33
added javadocs
ramaven Sep 11, 2021
a5955e0
added find functionality
ramaven Sep 11, 2021
0dd98f3
Merge pull request #2 from ramaven/branch-A-CodingStandard
ramaven Sep 11, 2021
deafde9
Merge pull request #3 from ramaven/branch-A-JavaDoc
ramaven Sep 11, 2021
80d6917
Merge pull request #4 from ramaven/branch-Level-9
ramaven Sep 11, 2021
84bc195
Merge pull request #6 from ramaven/add-gradle-support
ramaven Sep 12, 2021
f1722c7
fixed file save bug
ramaven Sep 12, 2021
90738d5
fixed file save bug
ramaven Sep 12, 2021
8c536cb
added gradle support
ramaven Sep 12, 2021
1848605
Merge branch 'master' into branch-A-Gradle
ramaven Sep 12, 2021
6657c54
Merge pull request #7 from ramaven/branch-A-Gradle
ramaven Sep 12, 2021
d183176
checkstyle
ramaven Sep 12, 2021
559aa07
Merge pull request #8 from ramaven/branch-A-Checkstyle
ramaven Sep 12, 2021
6137ed5
modified gradle build file
ramaven Sep 12, 2021
99eeead
Merge branch 'master' into branch-A-Checkstyle
ramaven Sep 12, 2021
0dc6f8e
Merge pull request #9 from ramaven/branch-A-Checkstyle
ramaven Sep 12, 2021
48c8b01
Added GUI
ramaven Sep 13, 2021
6f08fb4
Merge pull request #10 from ramaven/branch-Level-10
ramaven Sep 13, 2021
a6c7cec
Add assert statements
ramaven Sep 14, 2021
431ad92
Merge pull request #11 from ramaven/branch-A-Assertions
ramaven Sep 14, 2021
b919c18
Find command: make matching case insensitive
ramaven Sep 14, 2021
23b81b1
Merge pull request #12 from ramaven/branch-C-BetterSearch
ramaven Sep 14, 2021
6735ff4
Improve code quality
ramaven Sep 15, 2021
85deaac
Merge pull request #13 from ramaven/branch-A-CodeQuality
ramaven Sep 15, 2021
375ee70
Add product screenshot
ramaven Sep 15, 2021
5db5d46
Add user guide
ramaven Sep 15, 2021
790acc6
Set theme jekyll-theme-minimal
ramaven Sep 15, 2021
b5d33a9
Set theme jekyll-theme-leap-day
ramaven Sep 15, 2021
1e5ca13
Edit User Guide
ramaven Sep 15, 2021
0557aa0
Merge branch 'master' of https://github.com/ramaven/ip
ramaven Sep 15, 2021
855c0ad
Update README
ramaven Sep 15, 2021
dc82355
Update README.md
ramaven Sep 15, 2021
27a3096
Update README.md
ramaven Sep 15, 2021
f17b05f
Update README.md
ramaven Sep 15, 2021
a9ce5a5
Add credits
ramaven Sep 15, 2021
979f83f
Improve code quality
ramaven Sep 15, 2021
8e8c1d7
Add test methods
ramaven Sep 17, 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
4 changes: 4 additions & 0 deletions data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
T;1;read book
D;0;return book;June 6th
E;0;project meeting;Aug 6th 2-4pm
T;1;join sports club
63 changes: 49 additions & 14 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import tasks.*;
import exceptions.*;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class Duke {

private static TaskList taskList;


// public Duke() throws FileNotFoundException {
// this.storage = new Storage();
// taskList = storage.loadTaskList();
//
// }

public static void main(String[] args) throws DukeException{
String logo = " ____ _ \n"
+ "| _ \\ _ _| | _____ \n"
@@ -16,39 +28,52 @@ public static void main(String[] args) throws DukeException{

Scanner sc = new Scanner(System.in);

//Task[] tasks = new Task[100];
ArrayList<Task> tasks = new ArrayList<Task>();
int taskCounter = 0;

String input = "";

Storage storage = new Storage();
try{
taskList = storage.loadTaskList();
} catch (FileNotFoundException e){
System.out.println(e.getMessage());
}


try {while(true){

Choose a reason for hiding this comment

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

Suggested change
try {while(true){
try {
while(true) {

input = sc.nextLine().strip();
if(input.equals("bye")){

Choose a reason for hiding this comment

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

Suggested change
if(input.equals("bye")){
if(input.equals("bye")) {

System.out.println("Bye. Hope to see you again soon!\n");
storage.saveTaskListToDisk(taskList);
break;
//System.exit();
}
else if(input.equals("list")) {

Choose a reason for hiding this comment

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

Suggested change
else if(input.equals("list")) {
else if (input.equals("list")) {

for(int i = 0; i < taskCounter; i++){
System.out.println((i+1) + "." + tasks.get(i).toString());
for(int i = 0; i < taskList.numberOfTasks(); i++){
System.out.println((i+1) + "." + taskList.getTask(i).toString());
}
} else if (input.length() > 4 && input.substring(0,4).equals("done")){

Choose a reason for hiding this comment

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

Suggested change
} else if (input.length() > 4 && input.substring(0,4).equals("done")){
} else if (input.length() > 4 && input.substring(0,4).equals("done")) {

String taskDone = input.substring(5);
int taskDoneIndex = Integer.parseInt(taskDone)-1;

Choose a reason for hiding this comment

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

Suggested change
int taskDoneIndex = Integer.parseInt(taskDone)-1;
int taskDoneIndex = Integer.parseInt(taskDone) - 1;

tasks.get(taskDoneIndex).makeDone();
// tasks.get(taskDoneIndex).makeDone();
taskList.getTask(taskDoneIndex).makeDone();
System.out.println("Nice! I've marked this task as done: ");
System.out.println(tasks.get(taskDoneIndex).toString());
// System.out.println(tasks.get(taskDoneIndex).toString());
System.out.println(taskList.getTask(taskDoneIndex).toString());

}
else {
if(input.length()<4 ){

Choose a reason for hiding this comment

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

Suggested change
if(input.length()<4 ){
if (input.length() < 4) {

throw new DukeException("Unacceptable input");
}
if(input.substring(0,4).equals("todo")){

Choose a reason for hiding this comment

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

Suggested change
if(input.substring(0,4).equals("todo")){
if(input.substring(0,4).equals("todo")) {

TodoTask newTask = new TodoTask(input.substring(5));
tasks.add(newTask);
taskCounter++;
TodoTask newTodo = new TodoTask(input.substring(5));
//tasks.add(newTask);
taskList.addTask(newTodo);
//taskCounter++;
System.out.println("Got it. I've added this task: ");
System.out.print(" " + newTask.toString());
System.out.print(" " + newTodo.toString());

} else if(input.substring(0,5).equals("event")){

Choose a reason for hiding this comment

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

Suggested change
} else if(input.substring(0,5).equals("event")){
} else if(input.substring(0,5).equals("event")) {

//String at = input.split("/")[1].substring(3);
@@ -62,26 +87,34 @@ else if(input.equals("list")) {
date += "/" + dateArr[i];
}
}

String at = input.split("/")[1].substring(3);
EventTask newEvent = new EventTask(input.substring(6).split("/")[0], date);
tasks.add(newEvent);
taskCounter++;
//tasks.add(newEvent);
taskList.addTask(newEvent);
//taskCounter++;
System.out.println("Got it. I've added this task: ");
System.out.println(" " + newEvent.toString());

} else if(input.length()>5 && input.length()<8){

Choose a reason for hiding this comment

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

Suggested change
} else if(input.length()>5 && input.length()<8){
} else if (input.length() > 5 && input.length() < 8) {

throw new DukeException("Unacceptable input");
}
else if(input.substring(0,6).equals("delete")) {

Choose a reason for hiding this comment

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

Suggested change
else if(input.substring(0,6).equals("delete")) {
else if (input.substring(0,6).equals("delete")) {

// delete from arraylist
// reduce counter by 1

int indexToDel = Integer.parseInt(input.substring(7))-1;
Task tasktoDel = tasks.get(indexToDel);
//Task tasktoDel = tasks.get(indexToDel);
Task tasktoDel = taskList.getTask(indexToDel);

tasks.remove(indexToDel);
taskCounter--;
System.out.println(" Noted. I've removed this task: ");
System.out.println(" " + tasktoDel.toString());
}
else if(input.substring(0,8).equals("deadline")){

Choose a reason for hiding this comment

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

Suggested change
else if(input.substring(0,8).equals("deadline")){
else if(input.substring(0,8).equals("deadline")) {

// deadline

//String by = input.split("/")[1].substring(3);
String[] dateArr = input.split("/");
String date = "";
@@ -93,7 +126,9 @@ else if(input.substring(0,8).equals("deadline")){
}
}
DeadlineTask newDeadline = new DeadlineTask(input.substring(9).split("/")[0], date);
tasks.add(newDeadline);
//tasks.add(newDeadline);
taskList.addTask(newDeadline);

taskCounter++;
System.out.println("Got it. I've added this task: ");
System.out.println(" " + newDeadline.toString());
@@ -104,7 +139,7 @@ else if(input.substring(0,8).equals("deadline")){
throw new DukeException("Unacceptable input");
}

System.out.println("\nNow you have " + (taskCounter) + " tasks in the list.");
System.out.println("\nNow you have " + (taskList.numberOfTasks()) + " tasks in the list.");
}
}} catch (DukeException e){
System.out.println("OOPS!!! You have enteted an invalid category");
149 changes: 149 additions & 0 deletions src/main/java/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import tasks.*;
import exceptions.*;

import java.io.*;
import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Scanner;


public class Storage {

private String userDir = System.getProperty("user.dir");
private String dataFilePath = userDir + "/" + "data.txt";

private static final String DELIMITER = ";";

public TaskList loadTaskList() throws FileNotFoundException {

File f = new File(dataFilePath);
ArrayList<Task> taskList = new ArrayList<Task>();

if(!f.exists()){
return new TaskList(new ArrayList<Task>());
}

try{
Scanner dataReader = new Scanner(f);

while(dataReader.hasNextLine()){
// convert saved info to Task
String currLine = dataReader.nextLine();
Task currTask = convertStringToTask(currLine);
taskList.add(currTask);
}
dataReader.close();

} catch (FileNotFoundException e){
System.out.println("File unable to load");
}

return new TaskList(taskList);

}

public void saveTaskListToDisk(TaskList taskList){

File f = new File(dataFilePath);
if(!f.exists()) {
try{
boolean created = f.createNewFile();
} catch (IOException e) {
System.out.println("Error creating file");
}
}

try{
FileWriter writeTasks = new FileWriter(dataFilePath);
String allTasksString = "";

for(int i = 0; i < taskList.numberOfTasks(); i++){
Task currTask = taskList.getTask(i);
String taskString = convertTaskToString(currTask);
allTasksString += taskString + "\n";

}

writeTasks.write(allTasksString);
writeTasks.flush();
writeTasks.close();


} catch (IOException e){
System.out.println("Error creating file");
}

}

public String convertTaskToString(Task task){

// Example storage in file:
// T | 1 | read book
// D | 0 | return book | June 6th
// E | 0 | project meeting | Aug 6th 2-4pm

String taskType = task.getType() == Task.TaskType.TODO ? "T" :
task.getType() == Task.TaskType.EVENT ? "E" : "D";

String taskName = task.getName();

String isDone = task.isDone() ? "1" : "0";

String taskString = taskType + DELIMITER + isDone + DELIMITER + taskName;

if (task.getType() == Task.TaskType.EVENT){
taskString += DELIMITER;
taskString += ((EventTask) task).getDate();
}

if(task.getType() == Task.TaskType.DEADLINE){
taskString += DELIMITER;
taskString += ((DeadlineTask) task).getDate();
}

return taskString;

}

public Task convertStringToTask(String line){

// Example storage in file:
// T | 1 | read book
// D | 0 | return book | June 6th
// E | 0 | project meeting | Aug 6th 2-4pm

String[] lineSplit = line.split(DELIMITER);
System.out.println(lineSplit.length);
Task.TaskType taskType = lineSplit[0].equals("T") ? Task.TaskType.TODO :
lineSplit[0].equals("D") ? Task.TaskType.DEADLINE : Task.TaskType.EVENT;

boolean taskDone = lineSplit[1].equals("0") ? false : true;

Task currTask;

switch (taskType){
case TODO:
currTask = new TodoTask(lineSplit[2]);
break;

case DEADLINE:
currTask = new DeadlineTask(lineSplit[2], lineSplit[3]);
break;

case EVENT:
currTask = new EventTask(lineSplit[2], lineSplit[3]);
break;

default:
throw new IllegalArgumentException("Corrupted file");
}

if(taskDone ){
currTask.makeDone();
}

return currTask;

}

}
37 changes: 37 additions & 0 deletions src/main/java/TaskList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.util.ArrayList;
import tasks.*;

public class TaskList {
private ArrayList<Task> tasks;

public TaskList(ArrayList<Task> tasks){
this.tasks = tasks;
}

// 1. adding a task to the list

public void addTask(Task task){
tasks.add(task);
}

// 2. getting a task in a specified index
public Task getTask(int index){
return tasks.get(index);
}

// 3. removing a task from the specified index
public void removeTask(int index){
tasks.remove(index);
}

// 4. clearing tasklist
public void clearTaskList(){
tasks.clear();
}

// 5. checking number of tasks in tasklist
public int numberOfTasks(){
return tasks.size();
}

}
5 changes: 5 additions & 0 deletions src/main/java/Tasks/DeadlineTask.java
Original file line number Diff line number Diff line change
@@ -16,11 +16,16 @@ public DeadlineTask(String description, String by) {
this.dateReadable = DukeDate.parseDateToString(dateFormatted);
}

public String getDate(){
return by;
}

@Override
public String toString(){

Choose a reason for hiding this comment

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

public String toString() {

String typeString = type == TaskType.TODO ? "T" : type == TaskType.EVENT? "E" : "D";
String doneSymbol = isDone? "X" : " ";

Choose a reason for hiding this comment

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

String doneSymbol = isDone ? "X" : " ";

String result = "[" + typeString + "] " + "[" + doneSymbol + "] " + name + "(by: " + dateReadable + ")";

return result;
}

5 changes: 5 additions & 0 deletions src/main/java/Tasks/EventTask.java
Original file line number Diff line number Diff line change
@@ -16,11 +16,16 @@ public EventTask(String description, String at) {
this.dateReadable = DukeDate.parseDateToString(dateFormatted);
}

public String getDate(){
return at;
}

@Override
public String toString(){
String typeString = type == TaskType.TODO ? "T" : type == TaskType.EVENT? "E" : "D";
String doneSymbol = isDone? "X" : " ";

Choose a reason for hiding this comment

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

String doneSymbol = isDone ? "X" : " ";

String result = "[" + typeString + "] " + "[" + doneSymbol + "] " + name + "(at: " + dateReadable + ")";

return result;
}
}
9 changes: 9 additions & 0 deletions src/main/java/Tasks/Task.java
Original file line number Diff line number Diff line change
@@ -18,6 +18,15 @@ public Task(String name, TaskType type) {
public boolean isDone(){
return isDone;
}

public TaskType getType(){
return type;
}

public String getName(){
return name;
}

public void makeDone(){
isDone = true;
}