diff --git a/production/ip/Commands.class b/production/ip/Commands.class new file mode 100644 index 000000000..f44b64280 Binary files /dev/null and b/production/ip/Commands.class differ diff --git a/production/ip/MrStripes.class b/production/ip/MrStripes.class new file mode 100644 index 000000000..ab394e615 Binary files /dev/null and b/production/ip/MrStripes.class differ diff --git a/production/ip/Texts.class b/production/ip/Texts.class new file mode 100644 index 000000000..db2649f82 Binary files /dev/null and b/production/ip/Texts.class differ diff --git a/src/main/java/Commands.java b/src/main/java/Commands.java new file mode 100644 index 000000000..4210ca2fb --- /dev/null +++ b/src/main/java/Commands.java @@ -0,0 +1,60 @@ + + +public class Commands { + + private static final int MAX_LENGTH = 100; + private Task[] tasks = new Task[MAX_LENGTH]; + + public int length = 0; + + private boolean isExited = false; + + public Commands() { + + } + + public void accept(String nextLine) { + + int index = (nextLine.indexOf(' ')); + String commandKeyword = (index == -1)? nextLine : nextLine.substring(0, index).trim(); + + final String commandText = (index == -1)? nextLine : nextLine.substring(index).trim(); + switch (commandKeyword) { + case "exit" -> this.isExited = true; + case "list" -> this.list(); + case "add" -> { + this.tasks[length] = new Task(nextLine.substring(index)); + this.echo(); + length++; + } + case "mark" -> { + this.tasks[Integer.parseInt(commandText)].setDone(true); + echo(Integer.parseInt(commandText)); + } + case "unmark" -> { + this.tasks[Integer.parseInt(commandText)].setDone(false); + echo(Integer.parseInt(commandText)); + } + } + + } + + + private void list() { + for (int i = 0; i < length; i++) { + System.out.println( i +": "+ tasks[i]); + } + } + + private void echo() { + System.out.println("added: " + tasks[length]); + } + private void echo( int index) { + System.out.println(tasks[index]); + } + + public boolean isAcceptingCommands () { + return !isExited; + } + +} diff --git a/src/main/java/Duke.java b/src/main/java/Duke.java deleted file mode 100644 index 5d313334c..000000000 --- a/src/main/java/Duke.java +++ /dev/null @@ -1,10 +0,0 @@ -public class Duke { - public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - } -} diff --git a/src/main/java/MrStripes.java b/src/main/java/MrStripes.java new file mode 100644 index 000000000..66e7fe21d --- /dev/null +++ b/src/main/java/MrStripes.java @@ -0,0 +1,18 @@ + + +import java.util.Scanner; + +public class MrStripes { + public static void main(String[] args) { + + System.out.println(Texts.GREETINGS); + + Scanner scanner = new Scanner(System.in); + Commands commands = new Commands(); + while (commands.isAcceptingCommands()) { + commands.accept(scanner.nextLine()); + } + + System.out.println(Texts.GOODBYE); + } +} diff --git a/src/main/java/Task.java b/src/main/java/Task.java new file mode 100644 index 000000000..4c453574e --- /dev/null +++ b/src/main/java/Task.java @@ -0,0 +1,36 @@ +public class Task { + private String line; + private boolean isDone; + + public String getLine() { + return line; + } + + public void setLine(String line) { + this.line = line; + } + + public boolean isDone() { + return isDone; + } + + public void setDone(boolean done) { + isDone = done; + } + + public Task(String line, boolean isDone) { + this.line = line; + this.isDone = isDone; + } + + public Task(String line) { + this.line = line; + this.isDone = false; + } + + @Override + public String toString() { + return "[" + (isDone? "X" : " ") + "]" + + line; + } +} diff --git a/src/main/java/Texts.java b/src/main/java/Texts.java new file mode 100644 index 000000000..acf3bae84 --- /dev/null +++ b/src/main/java/Texts.java @@ -0,0 +1,6 @@ + +public class Texts { + public static final String GREETINGS = " hello"; + public static final String GOODBYE = "goodbye"; + +}