-
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 143 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 | ||
| Loops | FillInTheBlank | The keyword used to declare a method that does not return a value is `____`. | void | ||
| Loops | FillInTheBlank | The `____` keyword is used to create a new object in Java. | new | ||
| Loops | FillInTheBlank | In Java, the method that runs when the program starts is called `____`. | main | ||
| Loops | FillInTheBlank | The access modifier `____` allows visibility within the same package and subclasses. | protected | ||
| Loops | FillInTheBlank | The `____` statement is used to terminate the execution of a method and return a value. | return | ||
| Loops | FillInTheBlank | To compare two strings in Java, you use the `____` method. | equals | ||
| Loops | FillInTheBlank | In Java, arrays have a fixed `____` once they are initialized. | size | ||
| Loops | FillInTheBlank | A `____` is a block of code that can be called with a set of arguments and performs a specific task. | method | ||
| Loops | FillInTheBlank | The `____` keyword is used to inherit properties and methods from another class. | extends | ||
| Loops | FillInTheBlank | The keyword `____` is used to implement an interface in a class. | implements | ||
| Loops | FillInTheBlank | The keyword used to define a class is `____`. | class | ||
| Loops | FillInTheBlank | A constructor in Java is used to create an instance of a `____`. | object | ||
| Loops | FillInTheBlank | The keyword used to declare a constant in Java is ___ | final |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Score: 8%, Comment: Better luck next time! | ||
| Score: 23%, Comment: Better luck next time! |
| 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 |
|---|---|---|
| @@ -1,22 +1,145 @@ | ||
| # Developer Guide | ||
| # JavaNinja Developer Guide | ||
| Java Ninja is a command-line interface (CLI) learning tool focused on helping beginner programmers enhance their understanding of fundamental programming concepts. | ||
|
|
||
| - [Design & implementation](#design-&-implementation) | ||
| - [Product scope](#product-scope) | ||
| - [Target user profile](#target-user-profile) | ||
| - [Value proposition](#value-proposition) | ||
| - [User Stories](#user-stories) | ||
| - [Non-Functional Requirements](#non-Functional-Requirements) | ||
| - [Glossary](#Glossary) | ||
| - [Instructions for manual testing](#Instructions-for-manual-testing) | ||
|
|
||
| ## Acknowledgements | ||
|
|
||
| {list here sources of all reused/adapted ideas, code, documentation, and third-party libraries -- include links to the original source as well} | ||
| - [Apache Commons Lang Library](https://commons.apache.org/proper/commons-lang/) - Used for string utilities. | ||
| - [JUnit 5](https://junit.org/junit5/) - Used for testing. | ||
| - Code adapted from [AddressBook-Level3](https://github.com/se-edu/addressbook-level3). | ||
|
|
||
| JavaNinja uses the following tools for development: | ||
| - JUnit - Used for testing. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was there a need to repeat the mention of JUnit test here? |
||
| - Gradle - Used for build automation. | ||
|
|
||
| ## Design & implementation | ||
|
|
||
| ### Design | ||
|
|
||
| {Describe the design and implementation of the product. Use UML diagrams and short code snippets where applicable.} | ||
| #### 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` | ||
|
|
||
|
||
|  | ||
|
||
|
|
||
|
|
||
| ### True/False Feature Implementation | ||
|
||
|
|
||
| The `TrueFalse` class is responsible for handling true/false questions within the quiz application. This section describes its design, implementation details, and the rationale behind design choices. | ||
|
|
||
| #### Feature Overview | ||
| The `TrueFalse` class represents a true/false question. It stores the question text and the correct answer as a boolean. Additionally, it includes methods to validate user answers and display answer options. | ||
|
|
||
| #### Implementation Details | ||
|
|
||
| 1. **Attributes**: | ||
| - `boolean correctAnswer`: Stores the correct answer for the question. | ||
|
|
||
| 2. **Constructor**: | ||
| - `TrueFalse(String questionText, boolean correctAnswer)`: | ||
| Initializes the question text and the correct answer. The constructor checks that `questionText` is non-null and non-empty, ensuring a valid question is always provided. | ||
|
|
||
| 3. **Methods**: | ||
| - `checkAnswer(String userAnswer)`: | ||
| This method converts the user's input (`"true"` or `"false"`) into a boolean and compares it to the correct answer. It throws an `IllegalArgumentException` for invalid inputs, ensuring only `"true"` or `"false"` strings are accepted. | ||
| - `printOptions()`: | ||
| Displays answer choices ("1. True" and "2. False") for the user. This makes it clear what options are available for true/false questions. | ||
| - `toString()`: | ||
| Returns a string representation of the question with a "(True/False)" label to indicate its type. | ||
|
|
||
|
||
| #### Design Rationale | ||
|
|
||
| - **Boolean Storage for Correct Answer**: Storing the answer as a boolean simplifies the process of validating the user’s response since the comparison is a straightforward boolean check. | ||
| - **Input Validation in `checkAnswer`**: This method ensures only `"true"` or `"false"` strings are accepted as valid answers, which prevents user input errors. | ||
| - **Assertion Usage**: Assertions check that the question text and user answer are valid. This adds an additional layer of error handling during development. | ||
|
|
||
| #### Alternative Considerations | ||
|
|
||
| An alternative approach considered was to store `correctAnswer` as a `String` (`"true"` or `"false"`), which would simplify displaying it as text but would complicate validation. Using `boolean` was chosen for its simplicity and efficiency in logic checks. | ||
|
|
||
| #### UML Class Diagram | ||
|
|
||
|  | ||
|
||
|
|
||
| The class diagram above shows the structure of the `TrueFalse` class, including its attributes and methods, and its inheritance relationship with the `Question` superclass. | ||
|
|
||
| ### Topic Class Implementation | ||
| The `Topic` class is responsible for organizing questions under specific programming topics in the quiz application. It allows for modular storage of questions, making it easy for users to select topics and for developers to manage quiz content. | ||
|
|
||
| #### **Feature Overview** | ||
| The `Topic` class encapsulates a programming topic along with its related questions. It helps in grouping relevant questions, enabling quizzes to be topic-based, and provides essential methods to add and access questions within each topic. | ||
|
|
||
| #### **Implementation Details** | ||
|
|
||
| 1. **Attributes**: | ||
| - `String name`: Stores the name of the topic. | ||
| - `List<Question> questions`: Holds a list of questions related to this topic. | ||
|
|
||
| 2. **Constructor**: | ||
| - `Topic(String name)`: | ||
| Initializes the topic with a specified name and creates an empty list to hold its questions. Ensures that the `name` is non-null to prevent invalid topics. | ||
|
|
||
| 3. **Methods**: | ||
| - `addQuestion(Question question)`: | ||
| Adds a `Question` object to the topic’s question list. | ||
| - `List<Question> getQuestions()`: | ||
| Returns the list of questions under the topic. | ||
| - `String getName()`: | ||
|
||
| Returns the name of the topic as a string. | ||
|
||
|
|
||
| #### **Design Rationale** | ||
|
|
||
| - **Encapsulation**: Storing questions inside a `Topic` object allows better separation of concerns and makes the quiz system more modular and extendable. | ||
| - **Modularity for Scalability**: Organizing questions by topics makes the quiz system scalable, as more topics and questions can be easily added. | ||
| - **Single Responsibility Principle (SRP)**: The `Topic` class focuses only on managing a single topic and its related questions, adhering to SRP. | ||
|
|
||
| #### **Alternative Considerations** | ||
|
|
||
| 1. **Global List for Questions**: | ||
| - *Drawback*: Having a global list would make it harder to categorize questions logically and efficiently. | ||
|
|
||
| 2. **Direct Integration into QuizManager**: | ||
| - *Drawback*: This would tightly couple topic management with quiz functionality, making the code harder to maintain and less reusable. | ||
|
|
||
| #### UML Class Diagram | ||
| Below is the class diagram for the `Topic` class, illustrating its attributes and methods. | ||
|  | ||
|
||
|
|
||
| {Describe the design and implementation of the product. Use UML diagrams and short code snippets where applicable.} | ||
|
|
||
| ## Product scope | ||
| ### Target user profile | ||
|
|
||
| {Describe the target user profile} | ||
| Beginner programmers looking to improve their proficiency in Java and command-line skills. | ||
|
||
|
|
||
| ### Value proposition | ||
|
|
||
| {Describe the value proposition: what problem does it solve?} | ||
| This tool will offer an interactive learning experience through a series of tasks and challenges designed to deepen users' understanding and proficiency in both command-line operations and Java language. | ||
|
|
||
| ## User Stories | ||
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there more user stories? |
||
|
|
@@ -27,7 +150,10 @@ | |
|
|
||
| ## Non-Functional Requirements | ||
|
|
||
| {Give non-functional requirements} | ||
| 1. Technical Requirements: Any mainstream OS, i.e. Windows, macOS or Linux, with Java 17 installed. | ||
| 2. Project Scope Constraints: The application should only be used for practice and reviewing score progress | ||
| 3. Project Scope Constraints: Data storage is only to be performed locally. | ||
| 4. Quality Requirements: The application should be able to be used effectively by a novice with little experience with CLIs. | ||
|
|
||
| ## Glossary | ||
|
|
||
|
|
@@ -36,3 +162,9 @@ | |
| ## Instructions for manual testing | ||
|
|
||
| {Give instructions on how to do a manual product testing e.g., how to load sample data to be used for testing} | ||
|
|
||
| ### Manual Testing | ||
| View the [User Guide](https://AY2425S1-CS2113-W12-4.github.io/tp/UserGuide.html) for the full list of UI commands and their related use case and expected outcomes. | ||
|
|
||
| ### JUnit Testing | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps you can give some instructions, or even include the gradle tests. |
||
| JUnit tests are written in the subdirectory `test` and serve to test key methods part of the application. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| @startuml | ||
| class Question { | ||
| - text : String | ||
| + Question(String text) | ||
| + getText() : String | ||
| + checkAnswer(String userAnswer) : boolean | ||
| + printOptions() : void | ||
| + toString() : String | ||
| } | ||
|
|
||
| class TrueFalse { | ||
| - correctAnswer : boolean | ||
| + TrueFalse(String questionText, boolean correctAnswer) | ||
| + checkAnswer(String userAnswer) : boolean | ||
| + printOptions() : void | ||
| + toString() : String | ||
| } | ||
|
|
||
| TrueFalse --|> Question : extends | ||
| @enduml |
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.
Should this placeholder be removed since you have already added the necessary acknowledgements below?