Skip to content

Commit

Permalink
Organise packages and ui message
Browse files Browse the repository at this point in the history
  • Loading branch information
zognin committed Aug 21, 2021
1 parent 8e8a313 commit e3c595a
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 70 deletions.
2 changes: 0 additions & 2 deletions src/main/java/command/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
public class ListCommand extends Command {
private TaskList list;

public ListCommand() {}

public static ListCommand createCommand() {
return new ListCommand();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/exception/DukeException.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package exception;

import ui.message.ErrorMessage;
import ui.message.Message;

public class DukeException extends Exception {
Expand All @@ -8,6 +9,6 @@ public DukeException(String message) {
}

public Message getOutputMessage() {
return new Message(this.getMessage());
return new ErrorMessage(this.getMessage());
}
}
5 changes: 3 additions & 2 deletions src/main/java/storage/Storage.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storage;

import tasklist.TaskList;
import ui.message.ErrorMessage;
import ui.message.Message;

import java.io.File;
Expand All @@ -19,7 +20,7 @@ public static StorageFile loadListFile() {
String filePath = String.format("%s/%s", dataDirectoryPath, listFileName);
return StorageFile.loadFile(filePath);
} catch (IOException e) {
Message message = new Message("There was a problem in getting the list data");
Message message = new ErrorMessage("There was a problem in loading the list data");
message.print();
return null;
}
Expand All @@ -31,7 +32,7 @@ public static TaskList scanListFileDataToList(StorageFile listFile) {
listFile.scanFileDataToList(list);
return list;
} catch (FileNotFoundException e) {
Message message = new Message("There was a problem in scanning the list data to a list");
Message message = new ErrorMessage("There was a problem in scanning the storage data to a list");
message.print();
return null;
}
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/ui/message/DoneMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DoneMessage extends Message {
* @param message the string to be used in the done message
*/
public DoneMessage(String message) {
super(message);
super(message,"≧(´▽`)≦");
}

/**
Expand All @@ -27,14 +27,4 @@ public DoneMessage(String message) {
public String getMessage() {
return DONE_PREFIX + "\n\t\t" + super.getMessage();
}

/**
* Gets the message with a happy face added to it
*
* @return the string message with a happy face
*/
@Override
public String getMessageWithFace() {
return this.getMessage() + " ≧(´▽`)≦";
}
}
7 changes: 7 additions & 0 deletions src/main/java/ui/message/ErrorMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ui.message;

public class ErrorMessage extends Message {
public ErrorMessage(String message) {
super(message, "「(゚ペ)");
}
}
12 changes: 1 addition & 11 deletions src/main/java/ui/message/ExitMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ public class ExitMessage extends Message {
* @param message the string to be used in the exit message
*/
public ExitMessage(String message) {
super(message);
}

/**
* Gets the message with a waving face added to it
*
* @return the string message with a waving face
*/
@Override
public String getMessageWithFace() {
return this.getMessage() + " ヾ(=´・∀・`=)";
super(message, "ヾ(=´・∀・`=)");
}
}
12 changes: 1 addition & 11 deletions src/main/java/ui/message/GreetMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ public class GreetMessage extends Message {
* @param message the string to be used in the greeting message
*/
public GreetMessage(String message) {
super(message);
}

/**
* Gets the message with a cheering face added to it
*
* @return the string message with a cheering face
*/
@Override
public String getMessageWithFace() {
return this.getMessage() + " ٩(。•́‿•̀。)۶";
super(message, "٩(。•́‿•̀。)۶");
}
}
12 changes: 1 addition & 11 deletions src/main/java/ui/message/ListChangeMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ListChangeMessage extends Message {
* @param itemsInList the number of items in the list after the change.
*/
public ListChangeMessage(String message, int itemsInList) {
super(message);
super(message, "(^^)b");
this.itemsInList = itemsInList;
}

Expand All @@ -35,14 +35,4 @@ public String getMessage() {
numOfTasks,
task);
}

/**
* Gets the message with a thumbs up face added to it.
*
* @return the string message with a thumbs up face.
*/
@Override
public String getMessageWithFace() {
return this.getMessage() + " (^^)b";
}
}
12 changes: 1 addition & 11 deletions src/main/java/ui/message/ListMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ListMessage extends Message {
* @param message the string to be used in the list message
*/
public ListMessage(String message) {
super(message);
super(message, "ヽ(°〇°)ノ");
}

/**
Expand All @@ -27,14 +27,4 @@ public ListMessage(String message) {
public String getMessage() {
return LIST_PREFIX + "\n\t" + super.getMessage();
}

/**
* Gets the message with a shocked face added to it
*
* @return the string message with a shocked face
*/
@Override
public String getMessageWithFace() {
return this.getMessage() + "ヽ(°〇°)ノ";
}
}
22 changes: 12 additions & 10 deletions src/main/java/ui/message/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@
* It includes methods to format the output message.
*/
public class Message {
private static String FORMATTED_LINE = "_________________________________________________";
private String message;
private final static String FORMATTED_LINE = "_________________________________________________";
private final String message;
private String face;

/**
* Constructor to instantiate a `ui.message.DukeOutputMessage`.
*
* @param message the string to be used in the output message
*/
public Message(String message) {
public Message(String message, String face) {
this.message = message;
this.face = face;
}

protected String getMessage() {
return this.message;
}

protected String getMessageWithFace() {
return this.message + " 「(゚ペ)";
private String getMessageWithFace() {
char lastCharacter = this.getMessage().charAt(this.getMessage().length() - 1);

if (Character.isWhitespace(lastCharacter)) {
return String.format("%s%s", this.getMessage(), this.face);
}
return String.format("%s %s", this.getMessage(), this.face);
}

private String getFormattedMessage() {
Expand Down

0 comments on commit e3c595a

Please sign in to comment.