Skip to content

Commit

Permalink
fixing GUT
Browse files Browse the repository at this point in the history
  • Loading branch information
yuifuku1118 committed Sep 17, 2021
2 parents 58fc978 + fa40a61 commit b784f91
Show file tree
Hide file tree
Showing 25 changed files with 873 additions and 181 deletions.
Binary file added Jar/Duke.jar
Binary file not shown.
13 changes: 13 additions & 0 deletions src/main/java/Duke/Action.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package Duke;
public enum Action {
LIST,
DONE,
TODO,
DEADLINE,
EVENT,
DELETE,
BYE,
FIND,
UNKNOWN
}

36 changes: 36 additions & 0 deletions src/main/java/Duke/Deadline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package Duke;
import java.text.SimpleDateFormat;

/**
* <pre>
* Child class Deadline from Task Class
* </pre>
*/
public class Deadline extends Task{


/**
* Defult constructor,
*/
public Deadline(String actionName, boolean compleated, String date, String type) {
super(actionName, compleated, type, date);
}

/**
* Defult to String.
* @return String representation of task
*/
@Override
public String toString(){

SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy HH:mm");

String check = "[ ]";
if (this.compleated){
check = "[X]";
}
return "[D] " + check + " " + this.actionName + "(by: " + dateFormat.format(date) + ")";
}
}


32 changes: 32 additions & 0 deletions src/main/java/Duke/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package Duke;
import java.text.SimpleDateFormat;

/**
* <pre>
* Child class Event from Task Class
* </pre>
*/
public class Event extends Task{

/**
* Defult constructor,
*/
public Event(String actionName, boolean compleated, String date, String type){
super(actionName, compleated, type, date);
}

/**
* Defult to String.
* @return String representation of task
*/
@Override
public String toString(){
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy HH:mm");

String check = "[ ]";
if (this.compleated){
check = "[X]";
}
return "[E] " + check + " " + this.actionName + "(at: " + dateFormat.format(date) + ")";
}
}
12 changes: 12 additions & 0 deletions src/main/java/Duke/InputNotValidError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package Duke;

/**
* <pre>
* InputNotValidError class
* </pre>
*/
public class InputNotValidError extends Exception {
public InputNotValidError(String errorMessage) {
super(errorMessage);
}
}
70 changes: 70 additions & 0 deletions src/main/java/Duke/Parser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package Duke;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Parser {
String command;
Action action;

public Parser(String command){
this.command = command;
this.action = action(command);
}

public Action action(String command){
String[] splited = command.split(" ", 2);

String action1 = splited[0];
if (action1.equals("list")){
return Action.LIST;
}else if (action1.equals("done")){
return Action.DONE;
}else if(action1.equals("todo")){
return Action.TODO;
}else if(action1.equals("deadline")){
return Action.DEADLINE;
}else if(action1.equals("event")){
return Action.EVENT;
}else if(action1.equals("delete")){
return Action.DELETE;
}else if(action1.equals("bye")){
return Action.BYE;
}else if(action1.equals("find")){
return Action.FIND;
}
else{
return Action.UNKNOWN;
}
}

public Action getAction(){
return this.action;
}

public int getCommandSize(){
String[] splited = this.command.split(" ", 2);
return splited.length;
}

public String getActionList(){
String[] splited = this.command.split(" ", 2);
return splited[1];
}

public boolean isValid() throws InputNotValidError{
Set<Action> infoReqired = new HashSet<>(Arrays.asList(
Action.TODO, Action.DONE,Action.DONE,Action.DEADLINE,Action.EVENT));
if (this.action == Action.UNKNOWN){
throw new InputNotValidError("☹ OOPS!!! I'm sorry, but I don't know what that means :-(");
}else{
if(infoReqired.contains(this.action) && this.getCommandSize() <= 1){
throw new InputNotValidError("☹ OOPS!!! The description of a " + this.getActionList() + " cannot be empty.");
}else{
return true;
}
}

}

}
90 changes: 90 additions & 0 deletions src/main/java/Duke/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package Duke;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;



/**
* <pre>
* Stroage class,
* this class is to deal with
* loading tasks from the file and saving tasks in the file.
* </pre>
* @param <String> Filepath path to the data txt file
*/
public class Storage {

String filepath;

/**
* Defult constructor
* @param filepath filepath to the data txt file
*/
public Storage (String filepath){
this.filepath = filepath;
}

/**
* Method to load data from txt file,
* returns the arraylist of tring array representation of tasks.
* @return String array representation of tasks
*/
public ArrayList<String[]> loadData() throws FileNotFoundException{
ArrayList<String[]> res = new ArrayList<>();
try (BufferedReader br = new BufferedReader(new FileReader(this.filepath))) {
String line;
while ((line = br.readLine()) != null) {
String[] splited = line.split("\\|");
res.add(splited);
}
} catch (IOException e) {
e.printStackTrace();
}
return res;
}

/**
* Method to save data to txt file,
* @param tasks String array representation of tasks
*/
public void saveData(ArrayList<Task> tasks) throws IOException{
File fout = new File(this.filepath);
FileOutputStream fos = new FileOutputStream(fout);

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

for(Task eachtask : tasks){
String actionname = eachtask.getActionName();
boolean compleated = eachtask.getCompleted();
String type = eachtask.getType();
String done = "0";
String output;

if (compleated){
done = "1";
}

if(type.equals("T")){
output = type + " | " + done + " | " + actionname;
}else{
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HHmm");
Date date = eachtask.getDate();
output = type + " | " + done + " | " + actionname + " | " + dateFormat.format(date) ;
}
bw.write(output);
bw.newLine();
}
bw.close();
}

}
94 changes: 94 additions & 0 deletions src/main/java/Duke/Task.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package Duke;
import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
* <pre>
* Task object to hold the task,
* this is to create each tasks framework.
* </pre>
* @param <String> actionName name of the action
* @param <boolean> compleated weather the task if completed
* @param <String> type action type
* @param <Date> date Date object of the task
*/
public class Task{
String actionName;
boolean compleated;
String type;
Date date;

/**
* Defult constructor,
* prase the date into spedific format.
* @param actionName name of the action
* @param compleated weather the task if completed
* @param type action type
* @param date Date object of the task
*/
public Task(String actionName, boolean compleated, String type, String date){
this.actionName = actionName;
this.compleated = compleated;
this.type = type;
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HHmm");
try {
this.date = format.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
}

/**
* To mark the task as
* as compleated.
*/
public void doneTask(){
this.compleated = true;
}

/**
* To return the name of the action.
* @return action name
*/
public String getActionName(){
return this.actionName;
}

/**
* To return the boolean of compleateness.
* @return compleated boolean
*/
public boolean getCompleted(){
return this.compleated;
}

/**
* To return the type of the action.
* @return action type name
*/
public String getType(){
return this.type;
}

/**
* To return the date of the task.
* @return date of task
*/
public Date getDate(){
return this.date;
}

/**
* Defult to String.
* @return String representation of task
*/
public String toString(){
String check = "[ ]";
if (this.compleated){
check = "[X]";
}
return check + " " + this.actionName;
}
}
Loading

0 comments on commit b784f91

Please sign in to comment.