-
Notifications
You must be signed in to change notification settings - Fork 141
[CS2113-W12-4] Java Ninja #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 98 commits
b0f7177
3762a79
6d60f0d
c29ce34
362cc66
b0df5ff
739921d
51f249d
825cecc
5a113d8
358370b
1bd80ca
7d61399
54b56dc
31c2ac4
fcc0af0
ca534ca
e135e6c
8b14a31
6576093
5986b4b
b0df621
788034f
345837a
e468440
a6832dc
5133953
8fb5f7b
67eebfc
e5fdb23
63933b5
c17a752
8e5a7fb
57670ab
eaf50e0
1397281
7403edc
ed46e6b
add93a5
4b25995
cc78146
628fc9c
48a134c
6b937d5
4321fa9
8f594fe
9bb672d
e37ee1a
9a5a8fb
59731bb
54d9e82
8b921fa
6beb167
389f905
9a1c5e6
4045634
e26ca29
55fad9e
85eee5d
0d9a78e
de91e2f
6327ad3
ceeb3f1
d39c8ad
acd7681
e35d4c4
e5714aa
233ff52
fff8d0a
5a61f99
b05dddd
0a940e6
6e90f1c
3621ada
ec651f3
7027537
370971d
120d561
5df27e6
50d8c04
e8a4353
957245b
66c3ffc
387cb26
8437c22
d750134
bd86634
c93269b
d0bdcf2
fe97b88
a5ed651
ffb2cb2
ff105c2
d5b91a5
7714c8e
bb2b82a
886e998
08b7b5f
1b23672
24e444a
3909415
575b378
7816248
4625e1f
b7aac5a
9c2c31d
d186e2f
47db21c
e3358e1
afb17f3
66e8ed9
1a67bbf
43b788b
60b8ceb
9f64ddb
d835360
bca6590
73c335f
7506dc6
64a255e
c13cb6e
19db943
5e1ba04
7fb77fa
d35691f
a8107e3
785befe
a822dce
4578bbc
2ffbd64
409aa8c
3d2fa5d
601bb8f
1551bbf
b271b92
57c798a
3caa28d
ce03a2c
a0d3203
85364d7
9915f1d
e7b0a3f
580bc20
1fbca53
d2450e1
1a64ddf
945a129
1f57364
9cacaf3
ad00004
6855703
02f0ef0
35be1e0
27b338e
a1ba81b
efd079a
fc05394
1d9cdfa
5c82e3c
62aa9b4
5159e60
ee1049c
71687b8
1157141
2603cfe
65e49b5
ea5a18a
1e34a21
317d5b7
9c759bc
a3928ac
2d5cc91
66d4d87
54da0c7
1db1038
5bfda3f
1a00e81
6247254
ea4d0ca
2a65ebc
49d9b72
fe9cb64
87b69fe
d184b73
518fb60
be94b9c
f98285d
984889f
651322b
e83bad7
7703d6a
c5cc389
928d053
1b2b04f
00512c4
f449406
28554e7
d0d2d35
6800731
8aac613
c2beda2
14ba0d5
c9f79a9
71483db
644f813
f75b6c7
4453284
008998e
675558b
fa321d3
fe7fa75
61d8e3f
9939f4e
30f4d0b
98488ab
41b67d3
8a654df
9651713
8196ac4
db874ae
e7f1ba2
59f14fd
7a95e61
a200375
bf0dabe
a36a0cb
67533b0
f8e411d
5b61aa7
d6c95c3
e022434
4b8b672
bca25f9
2320e35
36b5392
9b82f73
0a72dda
a7946fe
45e28d5
e0a9e10
79f2640
a0f6d9d
5cf8800
10d028b
33b2a7d
4eabd67
74665b7
f87b4c7
2ba645d
d8e679f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Manifest-Version: 1.0 | ||
| Main-Class: seedu.javaninja.JavaNinja | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| Loops | TrueFalse | Java is a programming language. | true | ||
| Loops | TrueFalse | A while loop will execute at least once. | false | ||
| Loops | TrueFalse | A for loop is used when the number of iterations is known. | true | ||
| Loops | TrueFalse | A do-while loop will execute its body before checking the condition. | true | ||
| Loops | TrueFalse | A for-each loop is primarily used for iterating over collections. | true | ||
| Loops | TrueFalse | A while loop is best used when the number of iterations is known. | false | ||
| Loops | TrueFalse | A break statement can be used to exit a loop early. | true | ||
| Loops | TrueFalse | A continue statement skips the current iteration of a loop. | true | ||
| Loops | TrueFalse | A do-while loop will never execute if the condition is false initially. | false | ||
| Loops | TrueFalse | Infinite loops can only be created using a while loop. | false | ||
| Loops | TrueFalse | You can nest loops inside one another in Java. | true | ||
| Loops | Mcq | Which of the following is a loop structure in Java? | b | a) if-else | b) for | c) switch | d) try-catch | ||
| Loops | Mcq | Which loop guarantees at least one iteration? | a | a) do-while | b) for | c) while | d) for-each | ||
| Loops | Mcq | Which keyword is used to exit a loop early? | c | a) continue | b) return | c) break | d) stop | ||
| Loops | Mcq | Which type of loop is used when the number of iterations is fixed? | b | a) while | b) for | c) do-while | d) foreach | ||
| Loops | Mcq | What is the correct syntax for a for loop in Java? | a | a) for (int i = 0; i < 10; i++) | b) for (i = 0; i < 10; i++) | c) for int i : range(10) | d) foreach (int i in range(10)) | ||
| Loops | Mcq | Which of the following loop types can be infinite? | a | a) while | b) do-while | c) for | d) All of the above | ||
| Loops | Mcq | Which of the following loops is suitable for iterating over a collection? | d | a) while | b) do-while | c) simple for | d) for-each | ||
| Loops | Mcq | What happens if the condition in a for loop is omitted? | c | a) Compilation error | b) Infinite loop | c) The loop continues until it is explicitly broken | d) None of the above | ||
| Loops | Mcq | Which keyword can be used to skip to the next iteration of a loop? | a | a) continue | b) skip | c) next | d) pass | ||
| Loops | Mcq | What is the output of an infinite while loop without a condition? | b | a) Compilation error | b) Loop continues indefinitely | c) Loop runs once | d) None of the above | ||
| FITB | FillInTheBlank | The keyword used to declare a method that does not return a value is `____`. | void | ||
| FITB | FillInTheBlank | The `____` keyword is used to create a new object in Java. | new | ||
| FITB | FillInTheBlank | In Java, the method that runs when the program starts is called `____`. | main | ||
| FITB | FillInTheBlank | The access modifier `____` allows visibility within the same package and subclasses. | protected | ||
| FITB | FillInTheBlank | The `____` statement is used to terminate the execution of a method and return a value. | return | ||
| FITB | FillInTheBlank | To compare two strings in Java, you use the `____` method. | equals | ||
| FITB | FillInTheBlank | In Java, arrays have a fixed `____` once they are initialized. | size | ||
| FITB | FillInTheBlank | A `____` is a block of code that can be called with a set of arguments and performs a specific task. | method | ||
| FITB | FillInTheBlank | The `____` keyword is used to inherit properties and methods from another class. | extends | ||
| FITB | FillInTheBlank | The keyword `____` is used to implement an interface in a class. | implements | ||
| FITB | FillInTheBlank | The keyword used to define a class is `____`. | class | ||
| FITB | FillInTheBlank | A constructor in Java is used to create an instance of a `____`. | object | ||
| FITB | FillInTheBlank | The keyword used to declare a constant in Java is ___ | final |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| # About us | ||
|
|
||
| Display | Name | Github Profile | Portfolio | ||
| --------|:----:|:--------------:|:---------: | ||
|  | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
|  | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
|  | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
|  | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
|  | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
|
|
||
| Display | Name | Github Profile | Portfolio | ||
| --------|:-------------:|:--------------:|:---------: | ||
|  | Naveen | [Github](https://github.com/naveen42x) | [Portfolio](docs/team/naveen42x.md) | ||
|  | Zhang Zhitong | [Github](https://github.com/Zhang-Zhitong) | [Portfolio](docs/team/ZhangZhitong.md) | ||
|  | Shaun Goh | [Github](https://github.com/shaunngoh) | [Portfolio](docs/team/shaunngoh.md) | ||
|  | Wang Yubo | [Github](https://github.com/YubotKwng) | [Portfolio](docs/team/yubotkwng.md) | ||
|  | Jinlin Wang | [Github](https://github.com/Lucky-Yuan00) | [Portfolio](docs/team/johndoe.md) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,30 @@ | |
|
|
||
| ## Design & implementation | ||
|
|
||
| ### Design | ||
|
|
||
| #### Architecture | ||
|
|
||
| Main components of the architecture: | ||
|
|
||
| `Main` (consisting of class `JavaNinja`) is in charge of the app launch and shut down. | ||
| 1. At app launch, it initialises the components in the correct order and connects them with each other | ||
| 2. At shut down, it shuts down the other components and invokes cleanup methods | ||
|
|
||
| The bulk of the app's work is done by the respective components: | ||
| 1. `Cli`: It handles the user interface of the app | ||
| 2. `Parser`: The command executor | ||
| 3. `QuizManager`: Holds the data of the App in memory | ||
| 4. `Storage`: Reads data from, and writes data to, the hard disk. | ||
|
|
||
| `Commons` represent a collection of classes used by other components. | ||
|
|
||
| How the architecture components interact with each other: | ||
|
||
|
|
||
| The Sequence Diagram below shows how the components interact with each other for the scenario where the user issues the command `add Flashcard /q what's 2+3 /a 5` | ||
|
|
||
|
||
|  | ||
|
||
|
|
||
| {Describe the design and implementation of the product. Use UML diagrams and short code snippets where applicable.} | ||
|
|
||
|
|
||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package seedu.javaninja; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Scanner; | ||
|
|
||
| /* Manages input by user */ | ||
| public class Cli { | ||
| private QuizManager quizManager; | ||
| private Scanner scanner; | ||
|
|
||
| public Cli() { | ||
| quizManager = new QuizManager(); | ||
| scanner = new Scanner(System.in); | ||
| } | ||
|
|
||
| public void start() throws IOException { | ||
| System.out.println("Welcome to Java Ninja!"); | ||
| System.out.println("'view' to view topics"); | ||
| System.out.println("'select [topic]' to select a topic"); | ||
| System.out.println("'review' to review past results"); | ||
| System.out.println("'help' for a list of commands"); | ||
| System.out.println("'quit' to exit the program"); | ||
| System.out.println("'exit' to exit the quiz, activate only while doing the quiz"); | ||
|
|
||
| while (true) { | ||
| System.out.print("> "); | ||
| String input = scanner.nextLine().trim(); | ||
| String command = processCommand(input); | ||
|
|
||
| if (command.equals("quit")) { | ||
| break; | ||
| } | ||
|
|
||
| switch (command) { | ||
| case "view": | ||
| quizManager.printTopics(); | ||
| break; | ||
| case "select": | ||
| selectTopic(input); | ||
| break; | ||
| case "review": | ||
| System.out.println("Reviewing your past results:"); | ||
| System.out.println(quizManager.getPastResults()); | ||
| break; | ||
| case "help": | ||
| printHelp(); | ||
| break; | ||
| case "add": | ||
| quizManager.addQuestionByUser(input); | ||
| break; | ||
| default: | ||
| System.out.println("Invalid input. Type 'help' for a list of commands."); | ||
| } | ||
| } | ||
| System.out.println("Goodbye!"); | ||
| scanner.close(); | ||
| } | ||
|
|
||
| private void selectTopic(String input) { | ||
| String[] parts = input.split(" ", 2); | ||
| if (parts.length < 2) { | ||
| System.out.println("Please specify a topic to select."); | ||
| } else { | ||
| quizManager.selectTopic(parts[1], scanner); | ||
| } | ||
| } | ||
|
|
||
| public String processCommand(String input) { | ||
| return input.split(" ")[0].toLowerCase(); | ||
| } | ||
|
|
||
| // Help message | ||
| private void printHelp() { | ||
| System.out.println("List of available commands:"); | ||
| System.out.println("'view' - View available topics"); | ||
| System.out.println("'select [topic]' - Start a quiz on a specific topic"); | ||
| System.out.println("'review' - Review all your quiz results"); | ||
| System.out.println("'help' - Show this help message"); | ||
| System.out.println("'quit' - Exit the program"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package seedu.javaninja; | ||
|
|
||
| public class FillInTheBlank extends Question { | ||
|
|
||
| public FillInTheBlank(String question, String answer) { | ||
| super(question, answer); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean checkAnswer(String answer) { | ||
| // Normalize the user's answer and the correct answer for comparison | ||
| String normalizedUserAnswer = normalizeAnswer(answer); | ||
| String normalizedCorrectAnswer = normalizeAnswer(correctAnswer); | ||
| return normalizedUserAnswer.equals(normalizedCorrectAnswer); | ||
| } | ||
|
|
||
| @Override | ||
| public void printOptions() { | ||
| // No options to print for fill-in-the-blank questions | ||
| ; | ||
| } | ||
|
|
||
| // Method to normalize the answer for comparison | ||
| private String normalizeAnswer(String answer) { | ||
| if (answer == null) { | ||
| return ""; | ||
| } | ||
| // Convert to lowercase and strip any leading or trailing whitespace | ||
| return answer.toLowerCase().trim(); | ||
| } | ||
|
|
||
| public String getQuestionType() { | ||
| return "FITB"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package seedu.javaninja; | ||
|
|
||
| public class Flashcard extends Question { | ||
|
|
||
| public Flashcard(String question, String answer) { | ||
| super(question, answer); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean checkAnswer(String answer) { | ||
| return correctAnswer.equalsIgnoreCase(answer); | ||
| } | ||
|
|
||
| @Override | ||
| public void printOptions() { | ||
| ; | ||
| } | ||
|
|
||
| public String getQuestionType () { | ||
| return "FC"; | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package seedu.javaninja; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class JavaNinja { | ||
|
|
||
| public static void main(String[] args) throws IOException { | ||
| Cli cli = new Cli(); | ||
| cli.start(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package seedu.javaninja; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Mcq extends Question { | ||
| private List<String> options; | ||
|
|
||
| public Mcq(String text, String correctAnswer, List<String> options) { | ||
| super(text, correctAnswer); | ||
| this.options = options; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean checkAnswer(String answer) { | ||
| return correctAnswer.equalsIgnoreCase(answer); | ||
| } | ||
|
|
||
| @Override | ||
| public void printOptions() { | ||
| for (String option : options) { | ||
| System.out.println(option); | ||
| } | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package seedu.javaninja; | ||
|
|
||
| /* Represents a question that could be of different types (MCQ / True or False) */ | ||
|
|
||
| public abstract class Question { | ||
| protected String text; | ||
| protected String correctAnswer; | ||
|
|
||
| public Question(String text, String answer) { | ||
| this.text = text; | ||
| this.correctAnswer = answer; | ||
| } | ||
|
|
||
| public String getText() { | ||
| return this.text; | ||
| } | ||
|
|
||
| public abstract boolean checkAnswer(String answer); | ||
|
|
||
| public abstract void printOptions(); | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps there could have been more illustration to show the correct order of initialisation.