-
Notifications
You must be signed in to change notification settings - Fork 248
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
[CS2113-F10-2] BadMaths #46
base: master
Are you sure you want to change the base?
Changes from 250 commits
89d5cf1
8f6864d
5f7e0e6
355c4b1
fee543b
1b80b65
8f9eb9d
54b3dfd
1704811
e8d1ef8
377beb4
3a8d181
c4e26b7
5976f10
2b72547
6fffb2c
fc3c8ec
683e833
d461feb
eb53ad7
43d46f9
46f1669
d02cf4f
c7b1455
c0a6d3a
557bd87
7e57b24
1c804df
c49bf6a
3a3dde4
2f11a3a
6239f16
3ea091c
0067039
57f9c28
852ffc3
ea2190e
6831858
08e91d5
81a7f8b
9fefef0
c32b2c4
dcc4edd
45e3d68
a466230
ada2687
e7e4b3b
13428cd
9a0f544
2c5f3fb
2084741
1eb66ed
1bc9e92
7526ec5
b0cc664
87849aa
016cdd7
0346c76
d40880e
6a98ef2
598b753
773405b
00831e6
18c1e3a
91eec50
d9067a7
f2e710c
ba41834
ffef03e
21fc161
00bb7fb
f155eab
67b35bb
ad5f292
5312aa6
373f635
61c96df
748d79f
1d2deed
67eaa81
2f9b64a
4d17726
2566718
b4aa697
b620c48
5d0655e
6f05e9e
21f67f5
3fef76f
b3e69c1
2c22682
cd290e1
0592c82
56af6b0
28613c4
2543b88
a4c0aa6
34196e7
568f637
4b122a4
28ced57
a428acc
721ece4
ebf9859
0f3484c
ad7b1a6
faec2da
a334a59
d1d62b4
555d18f
538fb6f
838da54
97de1e5
d12e8aa
21758c9
436c169
e76bc92
64f6316
b9e793d
d07b437
d6a75c6
95cca58
83ee6e8
4bae805
6d998f1
4769b65
627c505
92ecfde
da76d45
9bbad9d
6ca8002
c38ccbf
4142633
afb5057
f9d5897
1fa7c85
ab8829d
0693727
3da6820
8270ff6
831c837
017f1cd
fed2a4c
455a0a9
f76f41f
34f0330
995f8d2
687239a
e0d952f
3ef8200
25292ea
b11abe6
4220d6c
be22905
521cdef
ff8c533
e5d0580
652b4d0
14abae2
362a254
b68d8d4
b18bdac
343b5e4
2a3f0e0
eb96956
3c9335c
07b02b7
a9cd961
6d66f0a
8c64613
bac4701
acd614b
8cd149a
96d0797
173bc98
49b7b53
63e5156
967e0bb
ae45285
17bdd5c
b89eb09
305b46f
14b5a1e
8d49bb4
26b7abc
8bdbb75
6c3e850
16636bc
271077b
38cc0de
3c9ee23
791a143
b1c5a19
dafd829
dcc29cd
f05d350
d717b3f
18da3ef
69ce099
e7d38c6
3b661a3
f4cdc2a
36e675d
3743344
2b6f526
851a8a2
f0e7bd0
b9995f0
5d41923
bfa379a
042fae6
42483f6
092b43c
270bc43
0745ec5
b504fe3
88b83f1
3ae966a
741201f
29b4596
11ddfdb
6d7bf59
5ed0428
028412e
e7be577
446871d
d726cb4
eeac598
f15b2ec
c99999a
c346fc1
477be31
43fc0f9
a0dddb0
187283a
8c1692e
a35469d
1472079
5041060
9a629fd
989821c
195b515
42496d5
c726548
8105036
4fb9cb4
7823156
7586d3f
c4bc080
db52353
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 |
---|---|---|
|
@@ -15,3 +15,4 @@ bin/ | |
|
||
/text-ui-test/ACTUAL.TXT | ||
text-ui-test/EXPECTED-UNIX.TXT | ||
/data/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
# About us | ||
|
||
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) | 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) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
Display | Name | Github Profile | Portfolio | ||
--------|:------------------:|:--------------:|:---------: | ||
![](https://via.placeholder.com/100.png?text=Photo) | Wilson Lee Jun Wei | [Github](https://github.com/WilsonLee2000) | [Portfolio](docs/team/johndoe.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Khoo You Run | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Hui Yu Cong | [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) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Zeng Ziqiu | [Github](https://github.com/ZiqiuZeng) | [Portfolio](docs/team/AboutUs.md) | ||
![](https://via.placeholder.com/100.png?text=Photo) | Seungjun Lee | [Github](https://github.com/0nandon) | [Portfolio](docs/team/AboutUs.md) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,241 @@ | ||
# Developer Guide | ||
This developer guide will help you to get started with our product, badMaths! | ||
|
||
## Table of Contents | ||
|
||
1. [Acknowledgements](#acknowledgements) | ||
2. [Design & implementation](#design--implementation) | ||
- [Store Notes](#store-notes) | ||
- [Graph](#graph) | ||
- [Matrix](#matrix) | ||
2. [Product Scope](#product-scope) | ||
- [Target user profile](#target-user-profile) | ||
- [Value proposition](#value-proposition) | ||
3. [User Stories](#user-stories) | ||
4. [Non-Functional Requirements](#non-functional-requirements) | ||
5. [Glossary](#glossary) | ||
6. [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} | ||
|
||
|
||
## Design & implementation | ||
### Solving Quadratic Equations | ||
The Quadratic equation solver allows user to find the value of `x` in a simple quadratic equation. | ||
The function is started when `solveQuadratic()` is called in the Command class. | ||
Below is an example of how it would be called. | ||
``` | ||
Quadratic. 2x^2 + 3x + 1 | ||
``` | ||
Step 1. Parser class would split the user input into 2 parts, command and toDo. Command would be `Quadratic`, | ||
thus `executeCommand` would trigger `quadraticSolver`. toDo would be `2x^2 + 3x + 1`. | ||
|
||
Step 2. The general formula of quadratic equations is `ax^2 + bx + c`, thus `findA`, `findB`, `findC` | ||
would identify a, b and c from toDo. | ||
|
||
Step 3. To solve the quadratic equation, `quadraticFormula` is called with a, b and c as parameters. The output would be | ||
a ArrayList of Doubles that contain 2 values, the possible values of x. | ||
|
||
Step 4. `printAnswer` is then called which would call upon the `UI` class's method: `printQuadraticAnswer`. This would output | ||
the two x values. | ||
|
||
Step 5. If any exceptions are caught in the above steps, `printQuadraticFormulaError` would be called from UI to show an error message | ||
to the user. | ||
|
||
![img_3.png](img_3.png) | ||
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. DG for the line quadraticFormula(), I think it would be better to include the variables to become something like 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. Would it be better to also add return statements, such as the variables names the functions are returning for such as the findA(), findB(), and findC() fuctions |
||
|
||
### Store and Display Notes | ||
The Store and Display Notes functionality allows users to input notes | ||
which will be stored in a list, and to display a list of all notes | ||
stored by users. This functionality is achieved through the `Store.` and `List.` commands. | ||
|
||
![img_2.png](img_2.png) | ||
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. I think getCommand and getToDo for the DG at the top, the arrow should be the other way round cause it is badmaths that is calling parser's function, and the calls should have a separate activation bar 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. for trigoGraph(), Calculator() and Quadratic(), they are constructors which make a new object, would it be better to show it in the Sequence Diagram by linking it straight to the bar instead of those objects already existing? |
||
|
||
The syntax for the commands of this functionality is as follows: | ||
1. `Store. <item>` For storing of notes into the list, where `<item>` represents the note that | ||
users would like to store. | ||
Example: `Store. addition` | ||
2. `List.` For displaying of a list of all notes stored by users. | ||
Example: `List.` | ||
|
||
Below is an illustration of how the `Store.` and `List.` are used to allow | ||
users to input notes to a list and to display a list of all notes that are | ||
stored inside the list. | ||
1. This is step 1. | ||
2. This is step 2. | ||
|
||
### Help | ||
The Help feature allows users to view possible options by calling `Help.` which reads the content stored in the HelpManual.txt. | ||
|
||
The feature implemented involves reading the content from HelpManual.txt file and logging the result of read operation using the Java Logging API. | ||
|
||
#### HelpManual text: | ||
`HelpManual.txt` is a text file that contains the help manual for the application. It is located in the `src/main/resources` directory of the project. | ||
The purpose of this file is to provide users with helpful information on how to use the application. | ||
|
||
#### HelpManual class: | ||
Step 1. Define the HelpManual class: The HelpManual class is defined as a public class with two static fields: filePath and logFilePath. | ||
These fields contain the file path of the HelpManual.txt file and the name of the log file, respectively. | ||
|
||
Step 2. Setting up the Logger: The Logger is set up in the HelpManual class using the Java Logging API. | ||
The `setUpLogger()` method resets the LogManager, sets the logger's level to ALL, and creates a log file if it does not already exist. | ||
This method is called before the `readHelpManual()` method to ensure that the logger is properly configured. | ||
|
||
Step 3. Reading the file: | ||
The `readHelpManual()` method is implemented to read the content from the HelpManual.txt file. | ||
It first calls the setUpLogger() method to configure the logger. Then it obtains an InputStream object that reads the content from the | ||
file using the `getResourceAsStream()` method. Before reading the file, the `readHelpManual()` method asserts that the input stream is not null to ensure that the file exists and is readable. | ||
The file is then read line by line using a BufferedReader object, and each line is appended to a StringBuilder object. Otherwise, | ||
the `getResourceAsStream()` method will return a null value, and an `AssertionError` will be thrown. | ||
|
||
Step 4. Logging the result: After reading the file, the `readHelpManual()` method closes the BufferedReader and InputStream | ||
objects and logs the success or failure of the read operation using the logger. If the read operation is successful, a message | ||
is logged to the console and log file indicating that the HelpManual file was successfully read. If an exception occurs during | ||
the read operation, an error message is logged to the console and log file. | ||
|
||
|
||
### Graph | ||
The Graph feature allows users to analyse basic Trigonometry signals by calling `startGraphAnalysis()` which | ||
creates a new instance of `TrigoGraphAnalyser` named `analyser`. | ||
|
||
Below is an example usage scenario and how the `Graph` feature behaves at each step. | ||
|
||
When user enters an input: | ||
``` | ||
Graph. 2*sin(2*x+5)-1 | ||
``` | ||
#### Parser class, Command class: | ||
Step 1. Parser class will split the input into `Graph.` and `2*sin(2*x+5)-1`, which are `command` and `toDo` respectively. | ||
The command class creates a new instance of `TrigoGraph` and pass in `toDo` as a parameter for the constructor. It | ||
then executes `trigoGraph.startGraphAnalysis()`based on `command` using switch-case statements. | ||
|
||
#### TrigoGraph class: | ||
![img_1.png](img_1.png) | ||
Step 2. Constructor for the TrigoGraph class takes in `2*sin(2*x+5)-1` and assigns it to `trigoEqn` of type String. When `startGraphAnalysis()` | ||
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. I think you need to insert another newline before |
||
is called from the command class, a new instance of `TrigoGraphAnalyser` called `analyser` is created in TrigoGraph, which accepts `trigoEqn` | ||
as the parameter. | ||
|
||
Step 3. When `analyser.canStartAnalyser()` is true, it will print out the amplitude, frequency, phase and vertical shift | ||
to the user using the Ui class. Each of the method calls to the Ui class requires an input of type double which can | ||
be achieved by calling `analyser.getAmplitude()`, `analyser.getFreq()` and so on. | ||
|
||
#### TrigoGraphAnalyser class: | ||
Step 4. In the `canStartAnalyser()` method, the trigo equation is split into various parts, and there | ||
is a method call to create `setUpLogger()` to log exceptions when user enters | ||
invalid trigo equation. `canStartAnalyser()` returns false if an exception is reached, else it returns true. | ||
|
||
Step 5. `canStartAnalyser()` calls `splitAmplitudeFromTrigoEqn()`. This method will split | ||
the input into `2` and `sin(2*x+5)-1` using `*` as the regex. | ||
|
||
Step 6. 2 tests are ran within `splitAmplitudeFromTrigoEqn()` to check for negative amplitude and multiple asterisk. | ||
In this case, both checks will return false. | ||
|
||
Step 7. The separated String is passed into `String[] amplitudeAndEqn`. The string is then passed into `findAmplitude` | ||
to determine the amplitude. In `findAmplitude(eqn)`, `isAmplitudeEqualsToOne(eqn[0])` will check if the input string | ||
starts with `cos`, `sin` or `tan`, where `eqn[0]` is `2` and `eqn[1]` is `sin(2*x+5)-1`. | ||
If this is true, 1.0 will be assigned to `amplitude`. Else, string `2` will be converted to double `2.0` and assigned to | ||
`amplitude`. | ||
|
||
Step 8. After finding `amplitude`, `canStartAnalyser()` calls `splitTrigoAndVerticalShift(amplitudeAndEqn[1])`, where | ||
`amplitudeAndEqn[1]` is `sin(2*x+5)-1`. `splitTrigoAndVerticalShift` splits `sin(2*x+5)-1` into `sin(2*x+5` and `-1` | ||
based on `)` and returns the separated string to `trigoAndVerticalShift`. | ||
|
||
Step 9. `canStartAnalyser()` calls `findVerticalShift()` which takes in `sin(2*x+5` and `-1` as a string [] parameter. | ||
In `findVerticalShift()`, method call to `isVerticalShiftZero(-1)` is false and thus, | ||
`-1` is converted to double `-1.0` and assigned to `vertricalShift`. | ||
|
||
Step 10. In `canStartAnalyser()`, string `trigo` is assigned `sin(2*x+5`. | ||
|
||
Step 11. `canStartAnalyser()` calls `splitTrigoIntoPhasors()` and takes in `trigo` as the parameter. In `splitTrigoIntoPhasors()`, | ||
`startPosOfPhase` is 4 while `endPosOfPhase` is 9. A new String variable `phase` is assigned the substring of trigo from | ||
4 to 9, resulting in `2*x+5`. `splitPhasorsIntoFreq()` is called and it accepts string `2*x+5` as input. | ||
|
||
Step 12. In `splitPhasorsIntoFreq()`, `findFreqForPlus()` is called which takes in string `2*x+5` as input. | ||
|
||
Step 13. In `findFreqForPlus()`, `2*x+5` is split into `2*x` and `5` using the split function with `+` as the regex. | ||
`findPhase()` which accepts `5` and a boolean `false` as parameters, and `findFreq()` which accepts `2*x` and a boolean `false` are called. | ||
|
||
Step 14. In `findPhase()`, `phase` is assigned the double of `5` and in `findFreq()`, `2*x` is substring into `2` and converted | ||
to double `2.0`. `Freq` is assigned the double value of `2.0 / (2 * Math.PI)`. | ||
|
||
Step 15. Finally, `canStartAnalyser()` reaches the end and returns true. | ||
|
||
#### TrigoGraphVisualiser class: | ||
Step 16. The `TrigoGraphVisualiser` extends JPanel and overrides the `paintComponent()` method in JComponent. | ||
|
||
Step 17. A new instance of `TrigoGraphVisualiser` is created in `startGraphAnalysis` to assign corresponding values to the amplitude, phase, frequency, | ||
vertical shift, and the trigonometric function in `TrigoGraphVisualiser`. Next, `startVisualiser()` is called to create the frame | ||
for the graph. | ||
|
||
|
||
Step 18. The frame is set half of the screen size using `setSize()` and `getScreenSize()`. | ||
|
||
Step 19. When the frame is created, `paintComponent` will be called. It sets up the scale factors which will scale the values | ||
generated by the trigo function to that of the frame. It the sets up the x and y axis using `g.drawLine()`. | ||
|
||
Step 20. Using the switch-case statements. `drawSinCurve()` will be executed and amplitudes will be labelled on the axis. | ||
The for loop will run from `xMin` to `xMax`, which are the negative frequency and positive frequency for one period respectively. | ||
After getting the y value, both x and y are scaled to xPixel and yPixel respectively. A horizontal line is drawn at every pixel, which | ||
eventually forms the sine graph. | ||
|
||
//{Describe the design and implementation of the product. | ||
//Use UML diagrams and short code snippets where applicable.} | ||
|
||
### Matrix | ||
|
||
The Matrix feature supports various basic matrix calculations below: | ||
* Matrix multiplication | ||
* Matrix element wise product | ||
* Matrix addition | ||
* Matrix subtraction | ||
|
||
With calling `calculator.run()`, BadMaths parses the user's input and conducts the given command. | ||
|
||
Below is an example usage scenario and how the `Matrix` feature behaves at each step. | ||
|
||
When user enters an input: | ||
``` | ||
Matrix. [1,2;3,4] .* [5,6;7,8] | ||
``` | ||
#### Calculator class | ||
|
||
step 1. `run()` function in `Calculator.class` firstly get `toDo` as the argument which is `[1,2;3,4] .* [5,6;7,8]` in the above example. | ||
This `run()` function sequentially parses this string, executes the command and shows the result matrix to users. | ||
|
||
#### Parser class | ||
|
||
step 2. Firstly, `run()` function pass the `toDo` string to `parse()` function defined in `Parser.class`. | ||
This `parse()` function firstly identifies the type of the operator of this command with referring `toDo` string. | ||
And then, it divides the cases with this identified type with using `switch` statement. | ||
|
||
#### Execute class | ||
|
||
step 3. According to each case divided by operator types in the previous step, | ||
`parse()` function calls corresponding function defined in `Execute.class` for conducting calculation. | ||
In the case of the above example, `parse()` function calls `executeMul()` defined in `Execute.class` since the type of the | ||
operator is matrix multiplication. Finally, it passes the `toDo` string to `executeMul()` function as the argument. | ||
|
||
step4. `executeMul()` function firstly extracts two operands from `toDo` string. And pass these two operands to `executeTranspose()` | ||
in `Execute.class` respectively. | ||
|
||
step 5. In this `executeTranspose()` function, function checks whether there is transpose mark in the given operand, and parses this | ||
operand which is string type into `Tensor2D` type so that this operand could be internally calculated. In this parsing phase, | ||
`parseMatrix()` function defined in `Parser.class` is used. This function finally outputs this `Tensor2D` type operand to | ||
`executeMatrix()` function. | ||
|
||
step 6. Regarding these two operands with `Tensor2D` type, `executeMul` function calls `mul()` function defined in `calculate.class`. | ||
|
||
#### Calculate class | ||
|
||
step 7. `mul()` function defined in `Calculate.class` internally conducts matrix multiplication with nested for-loop | ||
and outputs the result which is `Tensor2D` type. | ||
|
||
{Describe the design and implementation of the product. Use UML diagrams and short code snippets where applicable.} | ||
step 8. This result is sequentially returned to `executeMul()`, `parse()` and `run()` function. Finally in the `run()` function, | ||
the result is printed in terminal. | ||
|
||
|
||
## Product scope | ||
## Product Scope | ||
### Target user profile | ||
|
||
{Describe the target user profile} | ||
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 include target user profile |
||
|
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.
Concise and clear explanation of what your features does in this section! Consider explaining why you implemented your feature logic this way, maybe even describing some alternative implementations you considered but ultimately dropped, which would strengthen the appeal of your features to a developer.