MathHelper Report
MathHelper Report
Task 1:
1. One minor issue I had was when I was taking user input. The system was shutting whenever the
user input was out of the range of what we set. E.g. Questions could be chosen from 1 to 5 so
anyone entering anything else shut the system. To fix this, I created a loop that would keep the
user in it until he enters the right answer. I was also thinking about adding quit option on it so
that the user can quit, however, it was not mentioned in the specifications. Hence, I avoided
that idea.
2. The only issue I have identified right now is that there should be an option for the user to quit
the game.
3. I had to call the displayYearMenu(), displayWelcome(), and displayQuestionMenu() function in
the letsPlay() function.
4. I created a for loop that would keep the user in it until he enters the right answer within the
range (1 to 5 for Questions and 0 to 7 for YearLever).
Task 2:
1. All I will have to do for year level 4 to include negative numbers and year level 6 questions to
include modulo division is add changes in some functions. For level 4 to have negative numbers,
I will go to the getmin() function and add an if condition like this:
private int getMin(int year){
int i = 0;
if (year == 5 || year == 6) {
i = -999;
return i;
} else if (year == 7) {
i = -9999;
return i;
}
return i;
}
If(yearLevel==4){
i= -999;
}
For yearLevel 6 to have modulo, I will change the if condition in getOper() function. With
yearLevel7 I will also add year Level 6 like this:
private int getOper(int year){
int operatorBounds =0;
if(year == 0) {
operatorBounds = 1;
}
else if (year == 1 || year == 2) {
operatorBounds = 2;
}
else if (year >2 && year < 6) {
operatorBounds = 4;
} else if (year == 7 || year ==6) {
operatorBounds = 5;
}
2. To add question number in the code, I will add a printOutput function in the for loop which is
generating question after the increase in counter and before calling
generateQuestion(yearLevel) function and concatenate Q with String.valueOf(counter) like this:
for (int j = 0; j <= Qs; j++) {
counter++;
printOutput(“Q” + String.valueoF(counter));
generateQuestion(yearLevel);
userIn = scan.next();
checkQuit();
checkHint();
evaluateAnswer(result);
calculatedPercentage = ((double) correct * 100) / counter;
changeDifficulty();
}
Task 3:
1. To evaluate answer, I created a private variable named result. To make the code as simple as
possible, I calculated the result in the generateQuestions() function where I kept saving the
result. After that I created an evaluateAnswer(String Result) function. This function also contains
a local variable of double type named percentage, which we used to find percentage. To identify
whether the user have entered the right input, we created an if condition which compared the
two strings (userIn.equals(Result)). If the condition was true, we printed correct and used the
correct and counter variables to calculate percentage.
2. The count of correct is added in the evaluate answer and increased after every correct answer.
private void evaluateAnswer(String result) {
double percentage;
if(userIn.equals(result)){
correct++;
printOutput("Correct! Well Done! \n" );
percentage = ((double)correct*100)/counter;
printOutput("Your current percentage is ", percentage);
printOutput("%");
printOutput("\n");
}
Task 4:
1. I created a changeDifficulty() function and added it after evaluateAnswer and percentage
calculation inside the for loop. I used this place because the percentage was calculated
beforehand so I did not need to calculate percentage and it was only sensible to put it after the
evaluateAnswer function as we would not be able to change difficulty if we did not know if the
user is doing good or bad. Putting this function inside for loop let the program get details on
every question which removed any possibility of error.
2. Changing the frequency of the questions to 7 would be little difficult as it is not completely
divisible by multiple of tens like 5. However, it can still be done by just changing the argument is
if condition to (counter%7==0).
Task 5:
1. The biggest difficulty yet a very foolish one I had was not being able to create the empty dashes
before the hint. It took me a little too much time even though it was quite a simple thing.
Perhaps my analytical skills were not working well when I completed this task.
Task 6:
1. To capture user input, I used the PrintWriter.println(userIn) function. Inside the brackets, I
entered the String that is taking user input.
Note: Intellij was indicating that an exception was needed, hence I added an exception with the help of
Intellij.
2. The program can definitely not be used as it is because it needs proper GUI. To create GUI we
will need to import Javafx library or other GUIs. A lot of things will have to be changed then. A
stage will be set up, a scene will be created, layouts will be done accordingly, user inputs are
taken quite differently in javafx then in a simple java program. There a lot of things will have to
rewritten.