From 4e12ea9656e8d12021cafdb30c4b70cc81d7880b Mon Sep 17 00:00:00 2001 From: lhydl Date: Fri, 2 Oct 2020 12:20:08 +0800 Subject: [PATCH 001/360] Testing --- src/main/java/seedu/duke/Duke.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 5c74e68d59..0f09af9200 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -7,12 +7,12 @@ public class Duke { * Main entry-point for the java.duke.Duke application. */ public static void main(String[] args) { - String logo = " ____ _ \n" + String LOGO = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); + System.out.println("Hello from\n" + LOGO); System.out.println("What is your name?"); Scanner in = new Scanner(System.in); From e42a33370c14623dd93a0adca3b9f0ecc79b4703 Mon Sep 17 00:00:00 2001 From: limgl1998 Date: Fri, 2 Oct 2020 12:24:30 +0800 Subject: [PATCH 002/360] testing --- src/main/java/seedu/duke/Duke.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 5c74e68d59..a7444f94f2 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -15,7 +15,7 @@ public static void main(String[] args) { System.out.println("Hello from\n" + logo); System.out.println("What is your name?"); - Scanner in = new Scanner(System.in); - System.out.println("Hello " + in.nextLine()); + Scanner IN = new Scanner(System.in); + System.out.println("Hello " + IN.nextLine()); } } From a9df211d475b492d55934cb1d07a0d7b7d4599c7 Mon Sep 17 00:00:00 2001 From: lhydl Date: Fri, 2 Oct 2020 12:28:54 +0800 Subject: [PATCH 003/360] Testing --- docs/AboutUs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/AboutUs.md b/docs/AboutUs.md index 0f072953ea..f81e91d14a 100644 --- a/docs/AboutUs.md +++ b/docs/AboutUs.md @@ -2,7 +2,7 @@ Display | Name | Github Profile | Portfolio --------|:----:|:--------------:|:---------: -![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Hao Yuan | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) From 5679539999c7f008406f5495947695291f304463 Mon Sep 17 00:00:00 2001 From: lhydl Date: Fri, 2 Oct 2020 12:29:41 +0800 Subject: [PATCH 004/360] Testing --- src/main/java/seedu/duke/Duke.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 0f09af9200..5c74e68d59 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -7,12 +7,12 @@ public class Duke { * Main entry-point for the java.duke.Duke application. */ public static void main(String[] args) { - String LOGO = " ____ _ \n" + String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" + "| | | | | | | |/ / _ \\\n" + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + LOGO); + System.out.println("Hello from\n" + logo); System.out.println("What is your name?"); Scanner in = new Scanner(System.in); From cd017fbb53619454718b57fd9f85043316bec4a9 Mon Sep 17 00:00:00 2001 From: DesmondKJL Date: Fri, 2 Oct 2020 12:33:10 +0800 Subject: [PATCH 005/360] Change About Us name for tutorial activity --- docs/AboutUs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/AboutUs.md b/docs/AboutUs.md index 0f072953ea..d2e4ed4017 100644 --- a/docs/AboutUs.md +++ b/docs/AboutUs.md @@ -2,7 +2,7 @@ Display | Name | Github Profile | Portfolio --------|:----:|:--------------:|:---------: -![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Desmond Kwa | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) From d70c026035d4355f55ee1c15dd0330718824911f Mon Sep 17 00:00:00 2001 From: limgl1998 Date: Fri, 2 Oct 2020 12:33:46 +0800 Subject: [PATCH 006/360] testing tutorial --- docs/AboutUs.md | 2 +- src/main/java/seedu/duke/Duke.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/AboutUs.md b/docs/AboutUs.md index 0f072953ea..36402903a1 100644 --- a/docs/AboutUs.md +++ b/docs/AboutUs.md @@ -2,7 +2,7 @@ Display | Name | Github Profile | Portfolio --------|:----:|:--------------:|:---------: -![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Johnny Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index a7444f94f2..5c74e68d59 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -15,7 +15,7 @@ public static void main(String[] args) { System.out.println("Hello from\n" + logo); System.out.println("What is your name?"); - Scanner IN = new Scanner(System.in); - System.out.println("Hello " + IN.nextLine()); + Scanner in = new Scanner(System.in); + System.out.println("Hello " + in.nextLine()); } } From 68981f42a3dd72c0e8e80128b1b85fcd144b0fd2 Mon Sep 17 00:00:00 2001 From: KennethEer <59533849+KennethEer@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:35:11 +0800 Subject: [PATCH 007/360] Testing --- docs/AboutUs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/AboutUs.md b/docs/AboutUs.md index 0f072953ea..e68f910810 100644 --- a/docs/AboutUs.md +++ b/docs/AboutUs.md @@ -2,7 +2,7 @@ Display | Name | Github Profile | Portfolio --------|:----:|:--------------:|:---------: -![](https://via.placeholder.com/100.png?text=Photo) | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) +![](https://via.placeholder.com/100.png?text=Photo) | Kenneth Eer | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) ![](https://via.placeholder.com/100.png?text=Photo) | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) From 36f4f6adfeff9dd35a05cf7b57bd9121425e7662 Mon Sep 17 00:00:00 2001 From: KennethEer <59533849+KennethEer@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:00:04 +0800 Subject: [PATCH 008/360] Add Module class to handle module information --- src/main/java/seedu/duke/Module.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/seedu/duke/Module.java diff --git a/src/main/java/seedu/duke/Module.java b/src/main/java/seedu/duke/Module.java new file mode 100644 index 0000000000..089f45e620 --- /dev/null +++ b/src/main/java/seedu/duke/Module.java @@ -0,0 +1,25 @@ +package seedu.duke; + +public class Module { + protected String modulecode; + protected int exp = -1; + //create an array here for actual workload + + public Module(String mod) { + this.modulecode = mod; + } + + public Module(String mod, String exp) { + this.modulecode = mod; + this.exp = Integer.parseInt(exp); + } + + public String toString() { + if (this.exp == -1) { + return this.modulecode; + } + else { + return this.modulecode + " " + this.exp; + } + } +} From 1f80b61409fbda9f41228e784e47116ee23b1df6 Mon Sep 17 00:00:00 2001 From: KennethEer <59533849+KennethEer@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:01:26 +0800 Subject: [PATCH 009/360] Add ModuleList class with functions to add module and expected workload --- src/main/java/seedu/duke/ModuleList.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/seedu/duke/ModuleList.java diff --git a/src/main/java/seedu/duke/ModuleList.java b/src/main/java/seedu/duke/ModuleList.java new file mode 100644 index 0000000000..daea9f9bab --- /dev/null +++ b/src/main/java/seedu/duke/ModuleList.java @@ -0,0 +1,21 @@ +package seedu.duke; +import java.util.ArrayList; + +public class ModuleList { + + public static ArrayList modList = new ArrayList<>(); + + public static ArrayList add(String input) { + if (input.startsWith("addmod")) { + Module s = new Module(input.substring(7)); + modList.add(s); + System.out.println(s + " is added"); + } else if (input.startsWith("addexp")) { + Module s = new Module(input.substring(7, 13), input.substring(14)); + modList.add(s); + System.out.println(s + " is added"); + } + return modList; + } +} + From 53f773c52b465e7d9eec8c2f7f2dea768b3c98df Mon Sep 17 00:00:00 2001 From: KennethEer <59533849+KennethEer@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:02:33 +0800 Subject: [PATCH 010/360] Modify Duke file to input the modules --- src/main/java/seedu/duke/Duke.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 5c74e68d59..5bca72fa92 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -6,6 +6,14 @@ public class Duke { /** * Main entry-point for the java.duke.Duke application. */ + //private static ArrayList modList = new ArrayList<>(); + + public static void printlist() { + for (int i = 0; i < ModuleList.modList.size(); i++) { + System.out.println(ModuleList.modList.get(i)); + } + } + public static void main(String[] args) { String logo = " ____ _ \n" + "| _ \\ _ _| | _____ \n" @@ -17,5 +25,17 @@ public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Hello " + in.nextLine()); + + String input = in.nextLine(); + while (!input.equals("bye")) { + if (input.startsWith("add")) { + ModuleList.add(input); + } else { + System.out.println("Sorry, I don't understand"); + } + input = in.nextLine(); + } + printlist(); + System.out.println("Bye"); } } From 645da246e51c81dd6a9dd3fc4d56ad5daacfc0bd Mon Sep 17 00:00:00 2001 From: KennethEer <59533849+KennethEer@users.noreply.github.com> Date: Fri, 2 Oct 2020 14:20:04 +0800 Subject: [PATCH 011/360] Update coding standard --- src/main/java/seedu/duke/Module.java | 3 +-- src/main/java/seedu/duke/ModuleList.java | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/duke/Module.java b/src/main/java/seedu/duke/Module.java index 089f45e620..b9164ce8d3 100644 --- a/src/main/java/seedu/duke/Module.java +++ b/src/main/java/seedu/duke/Module.java @@ -17,8 +17,7 @@ public Module(String mod, String exp) { public String toString() { if (this.exp == -1) { return this.modulecode; - } - else { + } else { return this.modulecode + " " + this.exp; } } diff --git a/src/main/java/seedu/duke/ModuleList.java b/src/main/java/seedu/duke/ModuleList.java index daea9f9bab..8c778e9d5e 100644 --- a/src/main/java/seedu/duke/ModuleList.java +++ b/src/main/java/seedu/duke/ModuleList.java @@ -1,4 +1,5 @@ package seedu.duke; + import java.util.ArrayList; public class ModuleList { From 51910191c1503074399b4bf9cffeb8b4dd13bac1 Mon Sep 17 00:00:00 2001 From: lhydl Date: Sat, 3 Oct 2020 12:27:58 +0800 Subject: [PATCH 012/360] Add Ui class to handle the ui of the program --- src/main/java/seedu/duke/Duke.java | 4 +-- src/main/java/seedu/duke/Ui.java | 48 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/main/java/seedu/duke/Ui.java diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 5bca72fa92..1a6b4e2971 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -8,7 +8,7 @@ public class Duke { */ //private static ArrayList modList = new ArrayList<>(); - public static void printlist() { + public static void printList() { for (int i = 0; i < ModuleList.modList.size(); i++) { System.out.println(ModuleList.modList.get(i)); } @@ -35,7 +35,7 @@ public static void main(String[] args) { } input = in.nextLine(); } - printlist(); + printList(); System.out.println("Bye"); } } diff --git a/src/main/java/seedu/duke/Ui.java b/src/main/java/seedu/duke/Ui.java new file mode 100644 index 0000000000..04afdbfeaa --- /dev/null +++ b/src/main/java/seedu/duke/Ui.java @@ -0,0 +1,48 @@ +package seedu.duke; + +import java.util.ArrayList; +import java.util.Scanner; + +/** + * Text UI of the program. + */ +public class Ui { + private static Scanner in = new Scanner(System.in); + + /** + * Reads input entered by the user. + * + * @return input entered by the user + */ + public static String readCommand() { + return in.nextLine(); + } + + /** + * Prints the invalid command line. + */ + public static void printInvalidCommand() { + System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-(" + System.lineSeparator()); + } + + /** + * Prints the welcome screen when the program starts. + */ + public static void printWelcomeScreen() { + String logo = " ____ _\n" + + "| _ \\ _ _| | _____\n" + + "| | | | | | | |/ / _ \\\n" + + "| |_| | |_| | < __/\n" + + "|____/ \\__,_|_|\\_\\___|\n"; + System.out.println("Hello from\n" + logo); + System.out.println("What is your name?"); + } + + /** + * Prints the exit line when user entered "bye". + */ + public static void printExitScreen() { + System.out.println("All changes saved."); + System.out.println("Bye. Hope to see you again soon!" + System.lineSeparator()); + } +} From c28a47df880842ddfaa9d2d8204ccd353ced438b Mon Sep 17 00:00:00 2001 From: lhydl Date: Sat, 3 Oct 2020 12:30:12 +0800 Subject: [PATCH 013/360] Add Parser class to parse user inputs --- src/main/java/seedu/duke/Parser.java | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/main/java/seedu/duke/Parser.java diff --git a/src/main/java/seedu/duke/Parser.java b/src/main/java/seedu/duke/Parser.java new file mode 100644 index 0000000000..d05fdf11ea --- /dev/null +++ b/src/main/java/seedu/duke/Parser.java @@ -0,0 +1,60 @@ +package seedu.duke; + +import java.util.ArrayList; + +/** + * Parses user input + */ +public class Parser { + protected static boolean exit = false; + + public static void parse(String input, ArrayList modList) { + String[] command = input.trim().split(" "); + + switch (command[0].toLowerCase()) { + case "addmod": + case "addtime": + case "addexp": + ModuleList.add(input); + break; + case "deletemod": + //methods + break; + case "deleteexp": + //methods + break; + case "minus": + //methods + break; + case "compare": + //methods + break; + case "list": + //methods; + break; + case "help": + //methods + break; + case "exit": + if(input.trim().length()>4) { + Ui.printInvalidCommand(); + } else { + Ui.printExitScreen(); + exit = true; + } + break; + default: + System.out.println("Sorry, I don't understand"); + } + } + + /** + * Returns true if user types in "bye". + * + * @return status of exit + */ + public static boolean isExit() { + return exit; + } + +} From cfe007345281fc9549778fb3d32b66cf3449de1e Mon Sep 17 00:00:00 2001 From: lhydl Date: Sat, 3 Oct 2020 12:36:15 +0800 Subject: [PATCH 014/360] Optimise the code in Duke class --- src/main/java/seedu/duke/Duke.java | 43 ++++++++++------------------ src/main/java/seedu/duke/Parser.java | 6 ++-- src/main/java/seedu/duke/Ui.java | 11 +++++++ 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 1a6b4e2971..032bea1bcb 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,41 +1,28 @@ package seedu.duke; +import java.util.Scanner; +import java.util.ArrayList; import java.util.Scanner; +/** + * Main entry-point for the java.duke.Duke application. + */ public class Duke { - /** - * Main entry-point for the java.duke.Duke application. - */ - //private static ArrayList modList = new ArrayList<>(); - - public static void printList() { - for (int i = 0; i < ModuleList.modList.size(); i++) { - System.out.println(ModuleList.modList.get(i)); - } - } + private static ModuleList t; public static void main(String[] args) { - String logo = " ____ _ \n" - + "| _ \\ _ _| | _____ \n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; - System.out.println("Hello from\n" + logo); - System.out.println("What is your name?"); - + Ui.printWelcomeScreen(); Scanner in = new Scanner(System.in); System.out.println("Hello " + in.nextLine()); + run(t); + } - String input = in.nextLine(); - while (!input.equals("bye")) { - if (input.startsWith("add")) { - ModuleList.add(input); - } else { - System.out.println("Sorry, I don't understand"); - } - input = in.nextLine(); + public static void run(ModuleList t) { + boolean isExit = false; + while (!isExit) { + String input = Ui.readCommand(); + Parser.parse(input, ModuleList.modList); + isExit = Parser.isExit(); } - printList(); - System.out.println("Bye"); } } diff --git a/src/main/java/seedu/duke/Parser.java b/src/main/java/seedu/duke/Parser.java index d05fdf11ea..8276402dd7 100644 --- a/src/main/java/seedu/duke/Parser.java +++ b/src/main/java/seedu/duke/Parser.java @@ -3,7 +3,7 @@ import java.util.ArrayList; /** - * Parses user input + * Parses user input. */ public class Parser { protected static boolean exit = false; @@ -30,13 +30,13 @@ public static void parse(String input, ArrayList modList) { //methods break; case "list": - //methods; + Ui.printList(modList); break; case "help": //methods break; case "exit": - if(input.trim().length()>4) { + if (input.trim().length() > 4) { Ui.printInvalidCommand(); } else { Ui.printExitScreen(); diff --git a/src/main/java/seedu/duke/Ui.java b/src/main/java/seedu/duke/Ui.java index 04afdbfeaa..ce3c0b20d2 100644 --- a/src/main/java/seedu/duke/Ui.java +++ b/src/main/java/seedu/duke/Ui.java @@ -25,6 +25,17 @@ public static void printInvalidCommand() { System.out.println("OOPS!!! I'm sorry, but I don't know what that means :-(" + System.lineSeparator()); } + /** + * Prints out the task list. + * + * @param modList task list + */ + public static void printList(ArrayList modList) { + for (int i = 0; i < ModuleList.modList.size(); i++) { + System.out.println(ModuleList.modList.get(i)); + } + } + /** * Prints the welcome screen when the program starts. */ From bf6f99c8dbbe71139e6483e1305a319cb6b7ca64 Mon Sep 17 00:00:00 2001 From: lhydl Date: Sat, 3 Oct 2020 13:45:35 +0800 Subject: [PATCH 015/360] Bug fixes and improve in code quality --- src/main/java/seedu/duke/Duke.java | 7 +------ src/main/java/seedu/duke/Parser.java | 2 +- src/main/java/seedu/duke/Ui.java | 13 +++++++++++++ text-ui-test/input.txt | 3 ++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 032bea1bcb..1821089530 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -1,9 +1,5 @@ package seedu.duke; -import java.util.Scanner; -import java.util.ArrayList; -import java.util.Scanner; - /** * Main entry-point for the java.duke.Duke application. */ @@ -12,8 +8,7 @@ public class Duke { public static void main(String[] args) { Ui.printWelcomeScreen(); - Scanner in = new Scanner(System.in); - System.out.println("Hello " + in.nextLine()); + Ui.printNamePrompt(); run(t); } diff --git a/src/main/java/seedu/duke/Parser.java b/src/main/java/seedu/duke/Parser.java index 8276402dd7..677cc1b04a 100644 --- a/src/main/java/seedu/duke/Parser.java +++ b/src/main/java/seedu/duke/Parser.java @@ -44,7 +44,7 @@ public static void parse(String input, ArrayList modList) { } break; default: - System.out.println("Sorry, I don't understand"); + Ui.printInvalidCommand(); } } diff --git a/src/main/java/seedu/duke/Ui.java b/src/main/java/seedu/duke/Ui.java index ce3c0b20d2..a2de47562a 100644 --- a/src/main/java/seedu/duke/Ui.java +++ b/src/main/java/seedu/duke/Ui.java @@ -46,7 +46,20 @@ public static void printWelcomeScreen() { + "| |_| | |_| | < __/\n" + "|____/ \\__,_|_|\\_\\___|\n"; System.out.println("Hello from\n" + logo); + } + + public static void printNamePrompt() { + Scanner scan = new Scanner(System.in); System.out.println("What is your name?"); + String name = scan.nextLine(); + if (name.isEmpty()) { + Ui.printInvalidCommand(); + printNamePrompt(); + } else { + System.out.println(""); + System.out.println("Hello " + name); + System.out.println("What can I do for you?" + System.lineSeparator()); + } } /** diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index f6ec2e9f95..1329553ca2 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1 +1,2 @@ -James Gosling \ No newline at end of file +James Gosling +bye \ No newline at end of file From b905fd25f59ed3212fad2406f535d9ba1a86657c Mon Sep 17 00:00:00 2001 From: lhydl Date: Sat, 3 Oct 2020 13:59:25 +0800 Subject: [PATCH 016/360] Add JavaDoc comments to printNamePrompt method in Ui class --- src/main/java/seedu/duke/Ui.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/seedu/duke/Ui.java b/src/main/java/seedu/duke/Ui.java index a2de47562a..2bbea62954 100644 --- a/src/main/java/seedu/duke/Ui.java +++ b/src/main/java/seedu/duke/Ui.java @@ -48,6 +48,9 @@ public static void printWelcomeScreen() { System.out.println("Hello from\n" + logo); } + /** + * Prompts the user to enter his/her name. + */ public static void printNamePrompt() { Scanner scan = new Scanner(System.in); System.out.println("What is your name?"); From bc4cf36c4d031621c4f522e55a06465a4f31f894 Mon Sep 17 00:00:00 2001 From: lhydl Date: Sat, 3 Oct 2020 15:41:27 +0800 Subject: [PATCH 017/360] Bug fixes and update in text-ui-test --- src/main/java/seedu/duke/Duke.java | 4 +--- src/main/java/seedu/duke/Ui.java | 3 +-- text-ui-test/EXPECTED.TXT | 11 +++++++++-- text-ui-test/input.txt | 3 ++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 1821089530..4beec340dc 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -13,11 +13,9 @@ public static void main(String[] args) { } public static void run(ModuleList t) { - boolean isExit = false; - while (!isExit) { + while (!Parser.isExit()) { String input = Ui.readCommand(); Parser.parse(input, ModuleList.modList); - isExit = Parser.isExit(); } } } diff --git a/src/main/java/seedu/duke/Ui.java b/src/main/java/seedu/duke/Ui.java index 2bbea62954..850c1cb365 100644 --- a/src/main/java/seedu/duke/Ui.java +++ b/src/main/java/seedu/duke/Ui.java @@ -52,9 +52,8 @@ public static void printWelcomeScreen() { * Prompts the user to enter his/her name. */ public static void printNamePrompt() { - Scanner scan = new Scanner(System.in); System.out.println("What is your name?"); - String name = scan.nextLine(); + String name = in.nextLine(); if (name.isEmpty()) { Ui.printInvalidCommand(); printNamePrompt(); diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 892cb6cae7..83ad3d7cf2 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,9 +1,16 @@ Hello from - ____ _ -| _ \ _ _| | _____ + ____ _ +| _ \ _ _| | _____ | | | | | | | |/ / _ \ | |_| | |_| | < __/ |____/ \__,_|_|\_\___| What is your name? + Hello James Gosling +What can I do for you? + +CS2113T is added +All changes saved. +Bye. Hope to see you again soon! + diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 1329553ca2..ecaeb74a72 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,2 +1,3 @@ James Gosling -bye \ No newline at end of file +addmod CS2113T +exit \ No newline at end of file From 52984d83ad3d04d4b84d879db4a130580cec7ccd Mon Sep 17 00:00:00 2001 From: limgl1998 Date: Sun, 4 Oct 2020 22:32:45 +0800 Subject: [PATCH 018/360] Added View Added functions to viewing of contents in the module list These functions are to be called by the UI class to display the specified content Added getters in the Module class --- src/main/java/seedu/duke/Module.java | 24 +++++-- src/main/java/seedu/duke/View.java | 95 ++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 src/main/java/seedu/duke/View.java diff --git a/src/main/java/seedu/duke/Module.java b/src/main/java/seedu/duke/Module.java index b9164ce8d3..af0097aba0 100644 --- a/src/main/java/seedu/duke/Module.java +++ b/src/main/java/seedu/duke/Module.java @@ -1,24 +1,38 @@ package seedu.duke; public class Module { - protected String modulecode; + protected String moduleCode; protected int exp = -1; //create an array here for actual workload + protected double[] actualTime = new double[13]; public Module(String mod) { - this.modulecode = mod; + this.moduleCode = mod; } public Module(String mod, String exp) { - this.modulecode = mod; + this.moduleCode = mod; this.exp = Integer.parseInt(exp); } public String toString() { if (this.exp == -1) { - return this.modulecode; + return this.moduleCode; } else { - return this.modulecode + " " + this.exp; + return this.moduleCode + " " + this.exp; } } + + + public String getModuleCode() { + return moduleCode; + } + + public int getExpectedWorkload() { + return exp; + } + + public double[] getActualTime() { + return actualTime; + } } diff --git a/src/main/java/seedu/duke/View.java b/src/main/java/seedu/duke/View.java new file mode 100644 index 0000000000..c820d5e881 --- /dev/null +++ b/src/main/java/seedu/duke/View.java @@ -0,0 +1,95 @@ +package seedu.duke; + +import java.util.ArrayList; + +public class View { + /** + * Displays all the modules taken by the user. + * + * @param modList list containing all the modules taken. + * @return a list containing all the modules. + */ + public ArrayList viewMods(ArrayList modList) { + ArrayList output = new ArrayList<>(); + for (Module m : modList) { + output.add(m.getModuleCode()); + } + return output; + } + + /** + * Displays the expected workload for the specified module. + * + * @param modList list containing all the modules taken. + * @param moduleCode specified module code. + * @return expected workload. + */ + public int viewExpWorkLoad(ArrayList modList, String moduleCode) { + int output = -1; + for (Module m : modList) { + if (m.getModuleCode().equalsIgnoreCase(moduleCode)) { + output = m.getExpectedWorkload(); + } + } + if (output == -1) { + //print error msg of mod not found + } + return output; + } + + /** + * shows time spent for week 1 up to present. + * which week is not specified. + * + * @param modList list containing all the modules taken. + * @param moduleCode specified module code. + * @param week the week that the user wishes to view actual amount of time spent. + * @return amount of time spent on the specified module for the particular week. + */ + public double viewActualTime(ArrayList modList, String moduleCode, int week) { + double output = -1; + double[] actualTime = new double[13]; + for (int i = 0; i < 13; i++) { + actualTime[i] = -1; + } + for (Module m : modList) { + if (m.getModuleCode().equalsIgnoreCase(moduleCode)) { + actualTime = m.getActualTime(); + } + } + if (actualTime[0] == -1) { + //print error msg of mod not found. + } else { + output = actualTime[week]; + } + + return output; + } + + /** + * shows time spent for week 1 up to present. + * which week is not specified. + * + * @param modList list containing all the modules taken. + * @param moduleCode specified module code. + * @return a list of amount of time spent on the specified module for the week 1 up to present. + */ + public double[] viewActualTime(ArrayList modList, String moduleCode) { + double[] actualTime = new double[13]; + for (int i = 0; i < 13; i++) { + actualTime[i] = -1; + } + for (Module m : modList) { + if (m.getModuleCode().equalsIgnoreCase(moduleCode)) { + actualTime = m.getActualTime(); + } + } + if (actualTime[0] == -1) { + //print error msg of mod not found. + } + + return actualTime; + } + + +} From cddbfb0e74ce977e41455d458fa530a154186181 Mon Sep 17 00:00:00 2001 From: KennethEer <59533849+KennethEer@users.noreply.github.com> Date: Mon, 5 Oct 2020 14:43:27 +0800 Subject: [PATCH 019/360] Refactor code and improve code quality --- src/main/java/seedu/duke/Duke.java | 8 ++++---- src/main/java/seedu/duke/Module.java | 11 ++++++----- src/main/java/seedu/duke/ModuleList.java | 24 ++++++++++++++---------- src/main/java/seedu/duke/Parser.java | 10 +++++++--- src/main/java/seedu/duke/Ui.java | 4 ++-- text-ui-test/EXPECTED.TXT | 5 ++++- text-ui-test/input.txt | 8 ++++++-- 7 files changed, 43 insertions(+), 27 deletions(-) diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index 4beec340dc..dcf6084461 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -4,18 +4,18 @@ * Main entry-point for the java.duke.Duke application. */ public class Duke { - private static ModuleList t; + private static ModuleList modules; public static void main(String[] args) { Ui.printWelcomeScreen(); Ui.printNamePrompt(); - run(t); + run(modules); } - public static void run(ModuleList t) { + public static void run(ModuleList modules) { while (!Parser.isExit()) { String input = Ui.readCommand(); - Parser.parse(input, ModuleList.modList); + Parser.parse(input, modules); } } } diff --git a/src/main/java/seedu/duke/Module.java b/src/main/java/seedu/duke/Module.java index b9164ce8d3..174ecd5d1a 100644 --- a/src/main/java/seedu/duke/Module.java +++ b/src/main/java/seedu/duke/Module.java @@ -2,23 +2,24 @@ public class Module { protected String modulecode; - protected int exp = -1; + protected int expected = -1; //create an array here for actual workload public Module(String mod) { this.modulecode = mod; } - public Module(String mod, String exp) { + public Module(String mod, String expected) { this.modulecode = mod; - this.exp = Integer.parseInt(exp); + this.expected = Integer.parseInt(expected); } + @Override public String toString() { - if (this.exp == -1) { + if (this.expected == -1) { return this.modulecode; } else { - return this.modulecode + " " + this.exp; + return this.modulecode + ", Expected Workload: " + this.expected + "h"; } } } diff --git a/src/main/java/seedu/duke/ModuleList.java b/src/main/java/seedu/duke/ModuleList.java index 8c778e9d5e..4acc13a8a9 100644 --- a/src/main/java/seedu/duke/ModuleList.java +++ b/src/main/java/seedu/duke/ModuleList.java @@ -6,16 +6,20 @@ public class ModuleList { public static ArrayList modList = new ArrayList<>(); - public static ArrayList add(String input) { - if (input.startsWith("addmod")) { - Module s = new Module(input.substring(7)); - modList.add(s); - System.out.println(s + " is added"); - } else if (input.startsWith("addexp")) { - Module s = new Module(input.substring(7, 13), input.substring(14)); - modList.add(s); - System.out.println(s + " is added"); - } + public static void addMod(String input) { + Module s = new Module(input.substring(7)); + modList.add(s); + System.out.println(s + " is added"); + } + + public static void addExp(String input) { + String[] modInfo = input.split(" ", 3); + Module s = new Module(modInfo[1], modInfo[2]); + modList.add(s); + System.out.println(s + " is added"); + } + + public static ArrayList getData() { return modList; } } diff --git a/src/main/java/seedu/duke/Parser.java b/src/main/java/seedu/duke/Parser.java index 677cc1b04a..7f565c046d 100644 --- a/src/main/java/seedu/duke/Parser.java +++ b/src/main/java/seedu/duke/Parser.java @@ -8,14 +8,18 @@ public class Parser { protected static boolean exit = false; - public static void parse(String input, ArrayList modList) { + public static void parse(String input, ModuleList t) { String[] command = input.trim().split(" "); switch (command[0].toLowerCase()) { case "addmod": + t.addMod(input); + break; case "addtime": + //methods + break; case "addexp": - ModuleList.add(input); + t.addExp(input); break; case "deletemod": //methods @@ -30,7 +34,7 @@ public static void parse(String input, ArrayList modList) { //methods break; case "list": - Ui.printList(modList); + Ui.printList(t.getData()); break; case "help": //methods diff --git a/src/main/java/seedu/duke/Ui.java b/src/main/java/seedu/duke/Ui.java index 850c1cb365..1943228f5b 100644 --- a/src/main/java/seedu/duke/Ui.java +++ b/src/main/java/seedu/duke/Ui.java @@ -31,8 +31,8 @@ public static void printInvalidCommand() { * @param modList task list */ public static void printList(ArrayList modList) { - for (int i = 0; i < ModuleList.modList.size(); i++) { - System.out.println(ModuleList.modList.get(i)); + for (int i = 0; i < modList.size(); i++) { + System.out.println(modList.get(i)); } } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 83ad3d7cf2..5b36175672 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -10,7 +10,10 @@ What is your name? Hello James Gosling What can I do for you? -CS2113T is added +CS1000 is added +CS2113t is added +CS3000, Expected Workload: 6h is added +CS3200, Expected Workload: 8h is added All changes saved. Bye. Hope to see you again soon! diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index ecaeb74a72..9650931673 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -1,3 +1,7 @@ James Gosling -addmod CS2113T -exit \ No newline at end of file +addmod CS1000 +addmod CS2113t +addexp CS3000 6 +addexp CS3200 8 +exit + From ab390f7cf15ac6ca9d77420c3512f76f86aedf69 Mon Sep 17 00:00:00 2001 From: KennethEer <59533849+KennethEer@users.noreply.github.com> Date: Mon, 5 Oct 2020 14:50:56 +0800 Subject: [PATCH 020/360] Rename variables --- src/main/java/seedu/duke/ModuleList.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/seedu/duke/ModuleList.java b/src/main/java/seedu/duke/ModuleList.java index 4acc13a8a9..f6cfed7218 100644 --- a/src/main/java/seedu/duke/ModuleList.java +++ b/src/main/java/seedu/duke/ModuleList.java @@ -7,16 +7,16 @@ public class ModuleList { public static ArrayList modList = new ArrayList<>(); public static void addMod(String input) { - Module s = new Module(input.substring(7)); - modList.add(s); - System.out.println(s + " is added"); + Module currentModule = new Module(input.substring(7)); + modList.add(currentModule); + System.out.println(currentModule + " is added"); } public static void addExp(String input) { String[] modInfo = input.split(" ", 3); - Module s = new Module(modInfo[1], modInfo[2]); - modList.add(s); - System.out.println(s + " is added"); + Module currentMod = new Module(modInfo[1], modInfo[2]); + modList.add(currentMod); + System.out.println(currentMod + " is added"); } public static ArrayList getData() { From 0e0df35647c845756c333b70e13848540dfb130f Mon Sep 17 00:00:00 2001 From: lhydl Date: Mon, 5 Oct 2020 19:54:51 +0800 Subject: [PATCH 021/360] Change the welcome screen display and improve code structure --- src/main/java/seedu/duke/Module.java | 10 +++++----- src/main/java/seedu/duke/ModuleList.java | 4 ++-- src/main/java/seedu/duke/Ui.java | 16 ++++++++++------ text-ui-test/EXPECTED.TXT | 19 +++++++++++++------ 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/main/java/seedu/duke/Module.java b/src/main/java/seedu/duke/Module.java index 174ecd5d1a..0c30cd9c85 100644 --- a/src/main/java/seedu/duke/Module.java +++ b/src/main/java/seedu/duke/Module.java @@ -1,25 +1,25 @@ package seedu.duke; public class Module { - protected String modulecode; + protected String moduleCode; protected int expected = -1; //create an array here for actual workload public Module(String mod) { - this.modulecode = mod; + this.moduleCode = mod; } public Module(String mod, String expected) { - this.modulecode = mod; + this.moduleCode = mod; this.expected = Integer.parseInt(expected); } @Override public String toString() { if (this.expected == -1) { - return this.modulecode; + return this.moduleCode; } else { - return this.modulecode + ", Expected Workload: " + this.expected + "h"; + return this.moduleCode + ", Expected Workload: " + this.expected + "h"; } } } diff --git a/src/main/java/seedu/duke/ModuleList.java b/src/main/java/seedu/duke/ModuleList.java index f6cfed7218..e2d4a9b2f4 100644 --- a/src/main/java/seedu/duke/ModuleList.java +++ b/src/main/java/seedu/duke/ModuleList.java @@ -9,14 +9,14 @@ public class ModuleList { public static void addMod(String input) { Module currentModule = new Module(input.substring(7)); modList.add(currentModule); - System.out.println(currentModule + " is added"); + System.out.println(currentModule + " is added" + System.lineSeparator()); } public static void addExp(String input) { String[] modInfo = input.split(" ", 3); Module currentMod = new Module(modInfo[1], modInfo[2]); modList.add(currentMod); - System.out.println(currentMod + " is added"); + System.out.println(currentMod + " is added" + System.lineSeparator()); } public static ArrayList getData() { diff --git a/src/main/java/seedu/duke/Ui.java b/src/main/java/seedu/duke/Ui.java index 1943228f5b..f4f78a70a8 100644 --- a/src/main/java/seedu/duke/Ui.java +++ b/src/main/java/seedu/duke/Ui.java @@ -34,18 +34,22 @@ public static void printList(ArrayList modList) { for (int i = 0; i < modList.size(); i++) { System.out.println(modList.get(i)); } + System.out.println(""); } /** * Prints the welcome screen when the program starts. */ public static void printWelcomeScreen() { - String logo = " ____ _\n" - + "| _ \\ _ _| | _____\n" - + "| | | | | | | |/ / _ \\\n" - + "| |_| | |_| | < __/\n" - + "|____/ \\__,_|_|\\_\\___|\n"; + String logo = "|\\\\ /| |====== ||\n" + + "||\\\\ / | __ __| || __ ___ ___ || ___ ____\n" + + "|| \\\\ / |// \\// | ||// \\/ |/ ||// / _ \\ // \\\n" + + "|| \\\\ / ||| || | ||| || || ||\\\\ | __/ ||\n" + + "|| \\\\/ |\\\\__/\\\\__| ||| \\\\__|\\___ || \\\\\\___| ||\n" + + "*****************************************************|\n"; + System.out.println("Hello from\n" + logo); + System.out.println("User guide available at: https://ay2021s1-cs2113t-f12-4.github.io/tp/" + System.lineSeparator()); } /** @@ -59,7 +63,7 @@ public static void printNamePrompt() { printNamePrompt(); } else { System.out.println(""); - System.out.println("Hello " + name); + System.out.println("Hello " + name + "!"); System.out.println("What can I do for you?" + System.lineSeparator()); } } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index 5b36175672..ed5e6e1809 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -1,19 +1,26 @@ Hello from - ____ _ -| _ \ _ _| | _____ -| | | | | | | |/ / _ \ -| |_| | |_| | < __/ -|____/ \__,_|_|\_\___| +|\\ /| |====== || +||\\ / | __ __| || __ ___ ___ || ___ ____ +|| \\ / |// \// | ||// \/ |/ ||// / _ \ // \ +|| \\ / ||| || | ||| || || ||\\ | __/ || +|| \\/ |\\__/\\__| ||| \\__|\___ || \\\___| || +*****************************************************| + +User guide available at: https://ay2021s1-cs2113t-f12-4.github.io/tp/ What is your name? -Hello James Gosling +Hello James Gosling! What can I do for you? CS1000 is added + CS2113t is added + CS3000, Expected Workload: 6h is added + CS3200, Expected Workload: 8h is added + All changes saved. Bye. Hope to see you again soon! From bc876bef9d3645be20a4af885a22ef50c4276719 Mon Sep 17 00:00:00 2001 From: limgl1998 Date: Mon, 5 Oct 2020 20:52:31 +0800 Subject: [PATCH 022/360] Improved code readability Added some functions to make queries easier --- src/main/java/seedu/duke/Module.java | 9 ++- src/main/java/seedu/duke/View.java | 91 ++++++++++++++++++---------- 2 files changed, 64 insertions(+), 36 deletions(-) diff --git a/src/main/java/seedu/duke/Module.java b/src/main/java/seedu/duke/Module.java index e5a2cc8a28..593cb88bcd 100644 --- a/src/main/java/seedu/duke/Module.java +++ b/src/main/java/seedu/duke/Module.java @@ -1,22 +1,25 @@ package seedu.duke; +import java.util.Arrays; + public class Module { - protected String moduleCode; + protected String moduleCode; protected int expected = -1; - //create an array here for actual workload protected double[] actualTime = new double[13]; public Module(String mod) { this.moduleCode = mod; + Arrays.fill(actualTime, -1); } - public Module(String mod, String expected) { this.moduleCode = mod; this.expected = Integer.parseInt(expected); + Arrays.fill(actualTime, -1); } + @Override public String toString() { if (this.expected == -1) { return this.moduleCode; diff --git a/src/main/java/seedu/duke/View.java b/src/main/java/seedu/duke/View.java index c820d5e881..466987e974 100644 --- a/src/main/java/seedu/duke/View.java +++ b/src/main/java/seedu/duke/View.java @@ -1,6 +1,7 @@ package seedu.duke; import java.util.ArrayList; +import java.util.Arrays; public class View { /** @@ -25,21 +26,21 @@ public ArrayList viewMods(ArrayList modList) { * @return expected workload. */ public int viewExpWorkLoad(ArrayList modList, String moduleCode) { - int output = -1; - for (Module m : modList) { - if (m.getModuleCode().equalsIgnoreCase(moduleCode)) { - output = m.getExpectedWorkload(); - } - } - if (output == -1) { - //print error msg of mod not found + int output; + Module mod; + + if (doesModuleExist(modList, moduleCode)) { + mod = getModule(modList, moduleCode); + output = mod.getExpectedWorkload(); + } else { + //print error msg of mod not found. + output = -1; } return output; } /** - * shows time spent for week 1 up to present. - * which week is not specified. + * shows time spent for specified week. * * @param modList list containing all the modules taken. * @param moduleCode specified module code. @@ -47,22 +48,18 @@ public int viewExpWorkLoad(ArrayList modList, String moduleCode) { * @return amount of time spent on the specified module for the particular week. */ public double viewActualTime(ArrayList modList, String moduleCode, int week) { - double output = -1; - double[] actualTime = new double[13]; - for (int i = 0; i < 13; i++) { - actualTime[i] = -1; - } - for (Module m : modList) { - if (m.getModuleCode().equalsIgnoreCase(moduleCode)) { - actualTime = m.getActualTime(); - } - } - if (actualTime[0] == -1) { - //print error msg of mod not found. + double output; + double[] actualTime; + Module mod; + + if (doesModuleExist(modList, moduleCode)) { + mod = getModule(modList, moduleCode); + actualTime = mod.getActualTime(); + output = actualTime[week - 1]; } else { - output = actualTime[week]; + //print error msg of mod not found. + output = 0; } - return output; } @@ -72,24 +69,52 @@ public double viewActualTime(ArrayList modList, String moduleCode, int w * * @param modList list containing all the modules taken. * @param moduleCode specified module code. - * @return a list of amount of time spent on the specified module for the week 1 up to present. + * @return an array of amount of time spent on the specified module for the week 1 to week 13. */ public double[] viewActualTime(ArrayList modList, String moduleCode) { + Module mod; double[] actualTime = new double[13]; - for (int i = 0; i < 13; i++) { - actualTime[i] = -1; + + if (doesModuleExist(modList, moduleCode)) { + mod = getModule(modList, moduleCode); + actualTime = mod.getActualTime(); + } else { + //print error msg of mod not found. + Arrays.fill(actualTime, -1); } + return actualTime; + } + + /** + * Checks if the specified module exists in the module list. + * + * @param modList list containing all the modules taken. + * @param moduleCode specified module code. + * @return whether the module exists in the list + */ + protected boolean doesModuleExist(ArrayList modList, String moduleCode) { for (Module m : modList) { if (m.getModuleCode().equalsIgnoreCase(moduleCode)) { - actualTime = m.getActualTime(); + return true; } } - if (actualTime[0] == -1) { - //print error msg of mod not found. - } - - return actualTime; + return false; } + /** + * Looks for the specified module in the given list. + * + * @param modList list containing all the modules taken. + * @param moduleCode specified module code. + * @return the specified module from the given list. + */ + protected Module getModule(ArrayList modList, String moduleCode) { + for (Module m : modList) { + if (m.getModuleCode().equalsIgnoreCase(moduleCode)) { + return m; + } + } + return null; + } } From bb2ce812f94fc16aae85fb62698abd56a5dcda97 Mon Sep 17 00:00:00 2001 From: limgl1998 Date: Mon, 5 Oct 2020 23:47:16 +0800 Subject: [PATCH 023/360] Added a function to print all the module information Prints the week number, module code, expected workload and actual time spent in the specified week for all the modules taken. --- src/main/java/seedu/duke/Parser.java | 9 +-- src/main/java/seedu/duke/Ui.java | 11 ++++ src/main/java/seedu/duke/View.java | 83 ++++++++++++++++++++++++++-- text-ui-test/EXPECTED.TXT | 11 ++++ text-ui-test/input.txt | 1 + 5 files changed, 107 insertions(+), 8 deletions(-) diff --git a/src/main/java/seedu/duke/Parser.java b/src/main/java/seedu/duke/Parser.java index 7f565c046d..18743471a0 100644 --- a/src/main/java/seedu/duke/Parser.java +++ b/src/main/java/seedu/duke/Parser.java @@ -1,7 +1,5 @@ package seedu.duke; -import java.util.ArrayList; - /** * Parses user input. */ @@ -34,7 +32,8 @@ public static void parse(String input, ModuleList t) { //methods break; case "list": - Ui.printList(t.getData()); + //Ui.printList(t.getData()); + Ui.printTable(t.getData(), Integer.parseInt(command[1])); break; case "help": //methods @@ -53,7 +52,9 @@ public static void parse(String input, ModuleList t) { } /** - * Returns true if user types in "bye". + * Prints the week number, module code, expected workload and actual time spent + * in the specified week for all the modules taken. + * GL testing stuff * * @return status of exit */ diff --git a/src/main/java/seedu/duke/Ui.java b/src/main/java/seedu/duke/Ui.java index f4f78a70a8..634801a055 100644 --- a/src/main/java/seedu/duke/Ui.java +++ b/src/main/java/seedu/duke/Ui.java @@ -75,4 +75,15 @@ public static void printExitScreen() { System.out.println("All changes saved."); System.out.println("Bye. Hope to see you again soon!" + System.lineSeparator()); } + + /** + * Prints the a table. + * + * @param modList list of modules. + * @param week specified week number. + */ + public static void printTable(ArrayList modList, int week) { + View view = new View(); + view.printAllModuleInformation(modList,week); + } } diff --git a/src/main/java/seedu/duke/View.java b/src/main/java/seedu/duke/View.java index 466987e974..4c2e18940a 100644 --- a/src/main/java/seedu/duke/View.java +++ b/src/main/java/seedu/duke/View.java @@ -4,13 +4,16 @@ import java.util.Arrays; public class View { + + private static final int LENGTH_OF_MODULE_CODE = 6; + /** * Displays all the modules taken by the user. * * @param modList list containing all the modules taken. * @return a list containing all the modules. */ - public ArrayList viewMods(ArrayList modList) { + public ArrayList getModuleCode(ArrayList modList) { ArrayList output = new ArrayList<>(); for (Module m : modList) { output.add(m.getModuleCode()); @@ -25,7 +28,7 @@ public ArrayList viewMods(ArrayList modList) { * @param moduleCode specified module code. * @return expected workload. */ - public int viewExpWorkLoad(ArrayList modList, String moduleCode) { + public int getExpWorkLoad(ArrayList modList, String moduleCode) { int output; Module mod; @@ -47,7 +50,7 @@ public int viewExpWorkLoad(ArrayList modList, String moduleCode) { * @param week the week that the user wishes to view actual amount of time spent. * @return amount of time spent on the specified module for the particular week. */ - public double viewActualTime(ArrayList modList, String moduleCode, int week) { + public double getActualTime(ArrayList modList, String moduleCode, int week) { double output; double[] actualTime; Module mod; @@ -71,7 +74,7 @@ public double viewActualTime(ArrayList modList, String moduleCode, int w * @param moduleCode specified module code. * @return an array of amount of time spent on the specified module for the week 1 to week 13. */ - public double[] viewActualTime(ArrayList modList, String moduleCode) { + public double[] getActualTime(ArrayList modList, String moduleCode) { Module mod; double[] actualTime = new double[13]; @@ -117,4 +120,76 @@ protected Module getModule(ArrayList modList, String moduleCode) { return null; } + /** + * Prints the week number, module code, expected workload and actual time spent + * in the specified week for all the modules taken. + * + * @param modList list containing all the modules taken. + * @param week specified week number. + */ + public void printAllModuleInformation(ArrayList modList, int week) { + ArrayList moduleCodes = getModuleCode(modList); + + if (week < 1 || week > 13) { + //print error message + return; + } + + int maxLength = 0; + + for (String s : moduleCodes) { + if (s.length() > maxLength) { + maxLength = s.length(); + } + } + + int extraCharsToBeAdded = maxLength - LENGTH_OF_MODULE_CODE; + StringBuilder dashToBeAdded = new StringBuilder(); + StringBuilder spaceToBeAdded = new StringBuilder(); + StringBuilder crossToBeAdded = new StringBuilder(); + for (int i = 0; i < extraCharsToBeAdded; i++) { + dashToBeAdded.append("-"); + spaceToBeAdded.append(" "); + crossToBeAdded.append("X"); + } + + String border = "+------+-" + dashToBeAdded + "-------+----------+----------+\n"; + String header = "| Week | Module " + spaceToBeAdded + "| Expected | Actual |\n"; + String contents = "| WK | XXXXXX" + crossToBeAdded + " | YY | ZZZZ |\n"; + + System.out.print(border + header + border); + + for (Module m : modList) { + String out = contents; + String crosses = "XXXXXX" + crossToBeAdded; + String weekNum = ((week > 10) ? "" : "0") + Integer.toString(week); + out = out.replace("WK", weekNum); + StringBuilder moduleCode = new StringBuilder(m.getModuleCode()); + while (moduleCode.length() < crosses.length()) { + moduleCode.append(" "); + } + out = out.replace(crosses, moduleCode.toString()); + if (m.getExpectedWorkload() != -1) { + String expectedWorkLoad = ((m.getExpectedWorkload() > 10) ? "" : " ") + + Integer.toString(m.getExpectedWorkload()); + out = out.replace("YY", expectedWorkLoad); + } else { + out = out.replace(" YY ", " No Input "); + } + double actualTime = m.getActualTime()[week - 1]; + if (actualTime != -1) { + actualTime = round(actualTime, 1); + String actualWorkLoad = ((actualTime > 10) ? "" : " ") + Double.toString(actualTime); + out = out.replace("ZZZZ", actualWorkLoad); + } else { + out = out.replace(" ZZZZ ", " No Input "); + } + System.out.print(out + border); + } + } + + private double round(double value, int decimalPlaces) { + int scale = (int) Math.pow(10, decimalPlaces); + return (double) Math.round(value * scale) / scale; + } } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT index ed5e6e1809..4aaa340ca3 100644 --- a/text-ui-test/EXPECTED.TXT +++ b/text-ui-test/EXPECTED.TXT @@ -21,6 +21,17 @@ CS3000, Expected Workload: 6h is added CS3200, Expected Workload: 8h is added ++------+---------+----------+----------+ +| Week | Module | Expected | Actual | ++------+---------+----------+----------+ +| 02 | CS1000 | No Input | No Input | ++------+---------+----------+----------+ +| 02 | CS2113t | No Input | No Input | ++------+---------+----------+----------+ +| 02 | CS3000 | 6 | No Input | ++------+---------+----------+----------+ +| 02 | CS3200 | 8 | No Input | ++------+---------+----------+----------+ All changes saved. Bye. Hope to see you again soon! diff --git a/text-ui-test/input.txt b/text-ui-test/input.txt index 9650931673..a53c6974df 100644 --- a/text-ui-test/input.txt +++ b/text-ui-test/input.txt @@ -3,5 +3,6 @@ addmod CS1000 addmod CS2113t addexp CS3000 6 addexp CS3200 8 +list 2 exit From b28940ae37cd6ce45ac4c0250b2fd961dae6e64f Mon Sep 17 00:00:00 2001 From: lhydl Date: Wed, 7 Oct 2020 14:41:39 +0800 Subject: [PATCH 024/360] Implement help command, UI update --- src/main/java/seedu/duke/Duke.java | 8 +++---- src/main/java/seedu/duke/HelpList.java | 32 ++++++++++++++++++++++++++ src/main/java/seedu/duke/Parser.java | 17 +++++++++----- src/main/java/seedu/duke/Ui.java | 21 ++++++++++++----- src/main/java/seedu/duke/View.java | 1 + text-ui-test/EXPECTED.TXT | 6 +++-- 6 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 src/main/java/seedu/duke/HelpList.java diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index dcf6084461..095d8e997d 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -8,14 +8,14 @@ public class Duke { public static void main(String[] args) { Ui.printWelcomeScreen(); - Ui.printNamePrompt(); - run(modules); + String name = Ui.printNamePrompt(); + run(modules, name); } - public static void run(ModuleList modules) { + public static void run(ModuleList modules, String name) { while (!Parser.isExit()) { String input = Ui.readCommand(); - Parser.parse(input, modules); + Parser.parse(input, modules, name); } } } diff --git a/src/main/java/seedu/duke/HelpList.java b/src/main/java/seedu/duke/HelpList.java new file mode 100644 index 0000000000..f31d0cbd7e --- /dev/null +++ b/src/main/java/seedu/duke/HelpList.java @@ -0,0 +1,32 @@ +package seedu.duke; + +/** + * Stores a list of all the commands available. + */ +public class HelpList { + + /** + * Prints the full list of commands available. + */ + public static void listCommands() { + System.out.println("Available Commands:\n" + + "1. addmod \n" + + " example: addmod CS2113T\n" + + "2. addexp \n" + + " example: addexp CS2113T 5\n" + + "3. addtime \n" + + " example: addtime CS2113T 2 1\n" + + "4. list \n" + + " example: list 2\n" + + "5. deletemod \n" + + " example: deletemod CS2113T\n" + + "6. deleteexp \n" + + " example: deleteexp CS2113T\n" + + "7. minus