Skip to content

Commit

Permalink
Resolve Merge branch 'branch-A-CodingStandard'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/duke/command/AddCommand.java
#	src/main/java/duke/command/Command.java
#	src/main/java/duke/command/DeleteCommand.java
#	src/main/java/duke/command/ExitCommand.java
#	src/main/java/duke/command/PrintCommand.java
#	src/main/java/duke/command/UnmarkCommand.java
#	src/main/java/duke/exception/BlankCommandException.java
#	src/main/java/duke/exception/DukeException.java
#	src/main/java/duke/functionality/Parser.java
#	src/main/java/duke/functionality/Storage.java
#	src/main/java/duke/functionality/TaskList.java
  • Loading branch information
ChanWeiJie committed Jan 23, 2022
2 parents 273eacb + 3b48d14 commit 54a3489
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 66 deletions.
7 changes: 4 additions & 3 deletions src/main/java/duke/command/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import duke.task.Task;
import duke.functionality.TaskList;

/**
* Represents the add command. A <code>AddCommand</code> object corresponds to adding that specified task
* to the taskList in the TaskList class.
Expand All @@ -10,10 +11,10 @@ public class AddCommand extends Command {

/**
* Constructor of AddCommand class.
* @param t task object created from user input.
* @param task task object created from user input.
*/
public AddCommand(Task t){
super(t, null);
public AddCommand(Task task) {
super(task, null);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/duke/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ public abstract class Command{

/**
* Constructor of Command class.
* @param t task object created from user input.
* @param task task object created from user input.
* @param number an indicator to the index of the taskList in TaskList class.
*/
public Command(Task t, Integer number) {
this.task = t;
public Command(Task task, Integer number) {
this.task = task;
this.index = number;
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/duke/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class DeleteCommand extends Command {
* @param number an indicator to the index of the taskList in TaskList class.
*/
public DeleteCommand(Integer number) {

super(null, number);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/duke/command/UnmarkCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package duke.command;

import duke.functionality.TaskList;

/**
* Represents the unmark command. A <code>UnmarkCommand</code> object allows users to set the corresponding task as
* not done.
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/duke/functionality/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
* to the actions taken to parse and format user inputs.
*/
public class Parser {

private static final int EVENT_OFFSET = 5;
private static final int TODO_OFFSET = 4;
private static final int DEADLINE_OFFSET = 8;
Expand Down Expand Up @@ -110,10 +109,10 @@ public static Command parse(String input) throws DukeException {
String[] splitDuration = durationInput.split(" ");
LocalDate date;
LocalTime time;
try{
try {
date = formatDate(splitDuration[0]);
time = formatTime(splitDuration[1]);
} catch(DateTimeParseException e) {
} catch (DateTimeParseException e) {
throw new DukeException("The expected input form is deadline ____ /by yyyy-mm-dd hhmm");
}

Expand All @@ -132,11 +131,11 @@ public static Command parse(String input) throws DukeException {
LocalDate date;
LocalTime startTime;
LocalTime endTime;
try{
try {
date = formatDate(splitDuration[0]);
startTime = formatTime(splitDuration[1]);
endTime = formatTime(splitDuration[2]);
} catch(DateTimeParseException e) {
} catch (DateTimeParseException e) {
throw new DukeException("The expected input form is event ____ /at yyyy-mm-dd hhmm hhmm");
}

Expand Down
68 changes: 34 additions & 34 deletions src/main/java/duke/functionality/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public Storage(String pwd, String path){

/**
* Returns nothing, but stores the specified task into the taskList in TaskList class.
* @param t the task created in Parser class.
* @param task the task created in Parser class.
*/
public static void storeToList(Task t) { //same as addToList but no printing
TaskList.taskList.add(t);
public static void storeToList(Task task) { //same as addToList but no printing
TaskList.taskList.add(task);
TaskList.numOfTask++;
}

Expand All @@ -46,9 +46,9 @@ public static void storeToList(Task t) { //same as addToList but no printing
*/
public static void writeToFile(String path) throws IOException {
FileWriter fw = new FileWriter(path);
for(int i = 0; i < TaskList.numOfTask; i++) {
Task t = TaskList.taskList.get(i);
fw.write(craftOutput(t));
for (int i = 0; i < TaskList.numOfTask; i++) {
Task task = TaskList.taskList.get(i);
fw.write(craftOutput(task));
fw.write(System.lineSeparator());
}
fw.close();
Expand All @@ -67,33 +67,33 @@ public static void updateTextFile() {

/**
* Returns nothing, but reads the input from the specified file and stores them in the taskList in TaskList class.
* @param f the text file that stores all tasks.
* @param file the text file that stores all tasks.
* @throws FileNotFoundException if the file is missing.
*/
public static void readFileDataAndStoreInList(File f) throws FileNotFoundException {
Scanner sc = new Scanner(f);
public static void readFileDataAndStoreInList(File file) throws FileNotFoundException {
Scanner sc = new Scanner(file);
while ((sc.hasNextLine())) {
String input = sc.nextLine();
String[] inputSplit = input.split("\\|"); //split input by |
String task = inputSplit[0];
Integer mark = Integer.parseInt(inputSplit[1]);
if(task.equals("T")) {
if (task.equals("T")) {
Todo tempTask = new Todo(inputSplit[2]);
if(mark == 1) {
if (mark == 1) {
tempTask.setTaskDone();
}
storeToList(tempTask);
} else if(task.equals("D")) {
} else if (task.equals("D")) {
Deadline tempTask = new Deadline(inputSplit[2], Parser.formatDate(inputSplit[3]),
Parser.formatTime(inputSplit[4]));
if(mark == 1) {
if (mark == 1) {
tempTask.setTaskDone();
}
storeToList(tempTask);
} else if (task.equals("E")) {
Event tempTask = new Event(inputSplit[2], Parser.formatDate(inputSplit[3]) ,
Parser.formatTime(inputSplit[4]), Parser.formatTime(inputSplit[5]));
if(mark == 1) {
if (mark == 1) {
tempTask.setTaskDone();
}
storeToList(tempTask);
Expand All @@ -103,35 +103,35 @@ public static void readFileDataAndStoreInList(File f) throws FileNotFoundExcepti

/**
* Returns a crafted output to be stored in the text file.
* @param t the task created in Parser class.
* @param task the task created in Parser class.
* @return crafted output.
*/
public static String craftOutput(Task t) {
public static String craftOutput(Task task) {
String output = "";
String doneIcon = t.getStatusIcon();
if(t instanceof Todo) {
String doneIcon = task.getStatusIcon();
if (task instanceof Todo) {
if(doneIcon.equals("X")) {
output = "T|1|" + t.getDescription();
output = "T|1|" + task.getDescription();
} else {
output = "T|0|" + t.getDescription();
output = "T|0|" + task.getDescription();
}
} else if(t instanceof Deadline) {
} else if (task instanceof Deadline) {
if(doneIcon.equals("X")) {
output = "D|1|" + t.getDescription() + "|" + Parser.dateToString(((Deadline) t).getDate())
+ "|" + Parser.timeToString(((Deadline) t).getTime());
output = "D|1|" + task.getDescription() + "|" + Parser.dateToString(((Deadline) task).getDate())
+ "|" + Parser.timeToString(((Deadline) task).getTime());
} else {
output = "D|0|" + t.getDescription() + "|" + Parser.dateToString(((Deadline) t).getDate())
+ "|" + Parser.timeToString(((Deadline) t).getTime());
output = "D|0|" + task.getDescription() + "|" + Parser.dateToString(((Deadline) task).getDate())
+ "|" + Parser.timeToString(((Deadline) task).getTime());
}
} else if(t instanceof Event) {
} else if (task instanceof Event) {
if(doneIcon.equals("X")) {
output = "E|1|" + t.getDescription() + "|" + Parser.dateToString(((Event) t).getDate())
+ "|" + Parser.timeToString(((Event) t).getStartTime())
+ "|" + Parser.timeToString(((Event) t).getEndTime());
output = "E|1|" + task.getDescription() + "|" + Parser.dateToString(((Event) task).getDate())
+ "|" + Parser.timeToString(((Event) task).getStartTime())
+ "|" + Parser.timeToString(((Event) task).getEndTime());
} else {
output = "E|0|" + t.getDescription() + "|" + Parser.dateToString(((Event) t).getDate())
+ "|" + Parser.timeToString(((Event) t).getStartTime())
+ "|" + Parser.timeToString(((Event) t).getEndTime());
output = "E|0|" + task.getDescription() + "|" + Parser.dateToString(((Event) task).getDate())
+ "|" + Parser.timeToString(((Event) task).getStartTime())
+ "|" + Parser.timeToString(((Event) task).getEndTime());
}
}
return output;
Expand All @@ -144,10 +144,10 @@ public static String craftOutput(Task t) {
public void load() throws IOException {
File directory = new File(pwd + "/data");
File inputFile = new File(pwd + path);
if(directory.mkdir()) {
if (directory.mkdir()) {
System.out.println("You do not have the Directory, do not worry! I will create the directory for you");
}
if(inputFile.createNewFile()) {
if (inputFile.createNewFile()) {
System.out.println("You do not have the file, do not worry! I will create the file for you");
}
readFileDataAndStoreInList(inputFile);
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/duke/functionality/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public void deleteTask(int taskNum) {
public void markTask(int taskNum) {
String message = "Nice! I've marked this task as done:\n" ;
int actualTaskNum = taskNum - 1; //minus 1 as list index is from 0
Task t = taskList.get(actualTaskNum); // get the task from the array
t.setTaskDone();
Task task = taskList.get(actualTaskNum); // get the task from the array
task.setTaskDone();
Storage.updateTextFile();
System.out.println(message + t.toString());
System.out.println(message + task.toString());
}

/**
Expand All @@ -50,10 +50,10 @@ public void markTask(int taskNum) {
public void unMarkTask(int taskNum) {
String message = "OK, I've marked this task as not done yet:\n";
int actualTaskNum = taskNum - 1;
Task t = taskList.get(actualTaskNum); // get the task from the array
t.setTaskNotDone();
Task task = taskList.get(actualTaskNum); // get the task from the array
task.setTaskNotDone();
Storage.updateTextFile();
System.out.println(message + t.toString());
System.out.println(message + task.toString());
}

/**
Expand All @@ -71,13 +71,13 @@ public void printList(){

/**
* Returns nothing, but adds the task specified into the taskList.
* @param t the task created in Parser class.
* @param task the task created in Parser class.
*/
public void addToList(Task t) {
public void addToList(Task task) {
String message = "Got it. I've added this task:\n";
taskList.add(t);
taskList.add(task);
numOfTask++;
Storage.updateTextFile();
System.out.println(message + t.toString() + "\nNow you have " + numOfTask + " tasks in the list.");
System.out.println(message + task.toString() + "\nNow you have " + numOfTask + " tasks in the list.");
}
}
1 change: 0 additions & 1 deletion src/main/java/duke/main/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* to a TaskBot that helps keep tracks of all tasks inputted by a user.
*/
public class Duke {

private final Storage storage;
private TaskList tasks;
private final Ui ui;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/task/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public Deadline(String description, LocalDate date, LocalTime time) {
this.date = date;
}

public LocalTime getTime(){
public LocalTime getTime() {
return this.time;
}

public LocalDate getDate(){
public LocalDate getDate() {
return this.date;
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/duke/task/Event.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package duke.task;

import java.time.LocalDate;
Expand Down Expand Up @@ -28,15 +27,15 @@ public Event(String description, LocalDate date, LocalTime startTime, LocalTime
this.endTime = endTime;
}

public LocalDate getDate(){
public LocalDate getDate() {
return this.date;
}

public LocalTime getStartTime(){
public LocalTime getStartTime() {
return this.startTime;
}

public LocalTime getEndTime(){
public LocalTime getEndTime() {
return this.endTime;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/duke/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public Task(String description) {
this.isDone = false;
}

public String getStatusIcon(){
if(this.isDone) {
public String getStatusIcon() {
if (this.isDone) {
return "X";
} else {
return " ";
Expand All @@ -33,7 +33,7 @@ public void setTaskNotDone() {
this.isDone = false;
}

public String getDescription(){
public String getDescription() {
return this.description;
}

Expand Down

0 comments on commit 54a3489

Please sign in to comment.