Skip to content

[Ma Yitao] ip#101

Open
PrinceCatt wants to merge 28 commits into
nus-cs2113-AY2425S1:masterfrom
PrinceCatt:master
Open

[Ma Yitao] ip#101
PrinceCatt wants to merge 28 commits into
nus-cs2113-AY2425S1:masterfrom
PrinceCatt:master

Conversation

@PrinceCatt

Copy link
Copy Markdown

No description provided.

@Toby-Yu Toby-Yu left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good to me

Comment thread src/main/java/Utils/messageHandler.java Outdated
Comment on lines +60 to +80
type = messages.get(i-1).getType();
String typeSign = "";
String startTime = "";
String endTime = "";
String By = "";
String From = "";
if(type == 1){
typeSign = "[T]";
}
else if(type == 2){
By = " By: ";
typeSign = "[D]";
endTime = messages.get(i-1).getEndTime();
}
else if(type == 3){
typeSign = "[E]";
By = " By: ";
From = " From: ";
startTime = messages.get(i-1).getStartTime();
endTime = messages.get(i-1).getEndTime();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

maybe using case is also another way.

Comment thread src/main/java/Utils/messageHandler.java Outdated
System.out.println("-----------------------------------");
System.out.println("added:" + message.getMessage());
System.out.println("-----------------------------------");
public static void addList(messageList list, String input){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

it looks good to me in this addList function

Comment thread src/main/java/Entity/Message.java Outdated
Comment on lines +20 to +26
public Message(String message, String startTime, String endTime, int type) {
this.message = message;
this.isDone = false;
this.startTime = startTime;
this.endTime = endTime;
this.type = type;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the variable name follows the coding standard which is good.

Comment thread src/main/java/Utils/messageHandler.java Outdated
Comment on lines +61 to +65
String typeSign = "";
String startTime = "";
String endTime = "";
String By = "";
String From = "";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the variable name is easy for me to know the use of it

@LuxLucky7 LuxLucky7 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The code works well but readability could be worked on

private String endTime;

//todo
public Message(String message) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would the name of the method as a verb give a better idea on what the method does?

Comment thread src/main/java/Entity/Message.java Outdated
}

//event
public Message(String message, String startTime, String endTime, int type) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe the use and reason for overloading the Message function could be made more explicit?

Comment thread src/main/java/Utils/messageHandler.java Outdated
@@ -57,19 +57,72 @@ public static void listShow(messageList list) {
else {
doneSign = "";
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could the overuse of the word message and its variations - as variable name, class name, method name - get confusing for the writer and the reader? Maybe you could try using other names

Comment on lines +89 to +113
List<Message> messages = list.getMessages();
Message message = new Message(input);
String[] strings = input.split(" ");
String eventName = strings[1].split(" ")[1];
messages.add(message);
list.setMessages(messages);
System.out.println("-----------------------------------");
System.out.println("added:" + message.getMessage());
}

else if(input.contains("deadline")) {
List<Message> messages = list.getMessages();
String[] strings = input.split("/");
String endTime = strings[strings.length-1].split(" ")[1];
String eventName = strings[strings.length-2].split(" ")[1];
Message message = new Message(eventName, endTime, 2);
messages.add(message);
list.setMessages(messages);
System.out.println("-----------------------------------");
System.out.println("added:" + message.getMessage());
}

else if(input.contains("event")) {
List<Message> messages = list.getMessages();
String[] strings = input.split("/");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would a function, which does the same task that you are doing now, within each if-else if bracket make it more readable and clear?

Comment thread src/main/java/Yukino.java
Comment on lines +19 to +27
String logo = "__ __ _ \n"
+ "\\ \\ / /_ _ / /___ __ ______ ______ \n"
+ " \\ / // / // ___/ / // ___ ///--/ / \n"
+ " / // /__/ // \\ / // / / ///__/ / \n"
+ " /_/ /____/ /_/ \\_\\/_//_/ /_//_____/ \n";
System.out.println(logo);
System.out.println("Hello, I am Yukino!\n");
System.out.println("What can I do for you?\n");
System.out.println("-----------------------------------\n");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe this can be refactored into a method such as printWelcomeMessage() so as to make main() more concise and readable.

import java.util.ArrayList;
import java.util.List;

public class messageList {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Generally class names should be in Pascal case according to the coding standard so this should be MessageList. See https://se-education.org/guides/conventions/java/basic.html

Comment on lines +128 to +148
public static void mark(messageList list, String input) {
List<Message> messages = list.getMessages();
String[] sentences = input.split(" ");
int number = Integer.parseInt(sentences[1]);
if(number > messages.size()) {
System.out.println("Sorry, you are marking an event that has not been added");
return;
}

if(input.contains("unmark")){
messages.get(number-1).setDone(false);
System.out.println("-----------------------------------\n");
System.out.println("I have marked this task as not done!\n" + "[X] " + messages.get(number-1).getMessage());
System.out.println("-----------------------------------\n");
}
else {
messages.get(number - 1 ).setDone(true);
System.out.println("-----------------------------------\n");
System.out.println("I have marked this task as done!\n" + "[X] " + messages.get(number-1).getMessage());
System.out.println("-----------------------------------\n");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe using a more descriptive name such as markMessage might be a better here. Additionally, you could consider using a separate method for mark and unmark to make your code more concise and readable.

System.out.println("-----------------------------------\n");
}

public static void listShow(messageList list) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe using a more descriptive name such as listMessages is better here to describe the entity being listed.

Comment thread src/main/java/Utils/messageHandler.java Outdated
System.out.println("-----------------------------------\n");
}

public static void addList(messageList list, String input){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe naming it addToList might be clearer here as you are adding the messages to a list and not adding a list of messages. You could also consider addMessage as well.

Comment on lines +89 to +121
List<Message> messages = list.getMessages();
Message message = new Message(input);
String[] strings = input.split(" ");
String eventName = strings[1].split(" ")[1];
messages.add(message);
list.setMessages(messages);
System.out.println("-----------------------------------");
System.out.println("added:" + message.getMessage());
}

else if(input.contains("deadline")) {
List<Message> messages = list.getMessages();
String[] strings = input.split("/");
String endTime = strings[strings.length-1].split(" ")[1];
String eventName = strings[strings.length-2].split(" ")[1];
Message message = new Message(eventName, endTime, 2);
messages.add(message);
list.setMessages(messages);
System.out.println("-----------------------------------");
System.out.println("added:" + message.getMessage());
}

else if(input.contains("event")) {
List<Message> messages = list.getMessages();
String[] strings = input.split("/");
String startTime = strings[strings.length-2].split(" ")[1];
String endTime = strings[strings.length-1].split(" ")[1];
String eventName = strings[strings.length-3].split(" ")[1];
Message message = new Message(eventName, startTime, endTime, 3);
messages.add(message);
list.setMessages(messages);
System.out.println("-----------------------------------");
System.out.println("added:" + message.getMessage());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps you could refactor these 3 parts into methods to make this part more concise and readable.

@@ -0,0 +1,76 @@
package Entity;

public class Message {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe you could consider a different name for this class that represents the tasks to be stored as I initially thought this meant the input messages instead of the tasks that are being created and stored in the IP.

this.messages = messages;
}

public static void add(Message message) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps naming this as addMessage might make it clearer and more consistent with the other methods above.

Comment thread src/main/java/Utils/messageHandler.java Outdated

public class messageHandler {

public static void preHandle(messageList list) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe using a more descriptive name such as preHandleInput might be better here to specify what this method is doing.

Comment thread src/main/java/Yukino.java Outdated

Scanner scanner = new Scanner(System.in);
String input = null;
messageList list = new messageList();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe naming this as messageList or messages might be better to specify what this list contains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants