[Ma Yitao] ip#101
Conversation
| 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(); | ||
| } |
| System.out.println("-----------------------------------"); | ||
| System.out.println("added:" + message.getMessage()); | ||
| System.out.println("-----------------------------------"); | ||
| public static void addList(messageList list, String input){ |
There was a problem hiding this comment.
it looks good to me in this addList function
| 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; | ||
| } |
There was a problem hiding this comment.
the variable name follows the coding standard which is good.
| String typeSign = ""; | ||
| String startTime = ""; | ||
| String endTime = ""; | ||
| String By = ""; | ||
| String From = ""; |
There was a problem hiding this comment.
the variable name is easy for me to know the use of it
LuxLucky7
left a comment
There was a problem hiding this comment.
The code works well but readability could be worked on
| private String endTime; | ||
|
|
||
| //todo | ||
| public Message(String message) { |
There was a problem hiding this comment.
Would the name of the method as a verb give a better idea on what the method does?
| } | ||
|
|
||
| //event | ||
| public Message(String message, String startTime, String endTime, int type) { |
There was a problem hiding this comment.
Maybe the use and reason for overloading the Message function could be made more explicit?
| @@ -57,19 +57,72 @@ public static void listShow(messageList list) { | |||
| else { | |||
| doneSign = ""; | |||
| } | |||
There was a problem hiding this comment.
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
| 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("/"); |
There was a problem hiding this comment.
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?
| 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"); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
| 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"); | ||
| } |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Maybe using a more descriptive name such as listMessages is better here to describe the entity being listed.
| System.out.println("-----------------------------------\n"); | ||
| } | ||
|
|
||
| public static void addList(messageList list, String input){ |
There was a problem hiding this comment.
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.
| 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()); |
There was a problem hiding this comment.
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 { | |||
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Perhaps naming this as addMessage might make it clearer and more consistent with the other methods above.
|
|
||
| public class messageHandler { | ||
|
|
||
| public static void preHandle(messageList list) { |
There was a problem hiding this comment.
Maybe using a more descriptive name such as preHandleInput might be better here to specify what this method is doing.
|
|
||
| Scanner scanner = new Scanner(System.in); | ||
| String input = null; | ||
| messageList list = new messageList(); |
There was a problem hiding this comment.
Maybe naming this as messageList or messages might be better to specify what this list contains.
…o branch-level-6
branch-level-8
branch-level-9
No description provided.