GE Assignment COMP8702

GE Assignment COMP8702– Semester 1, 2021
Math Helper
Please ensure you read and understand the entire document before undertaking this assignment.
If you require clarification on the specification within, please seek this as soon as possible.
Learning Outcomes
• Comprehend basic program control constructs of sequence, selection, and iteration;
• Use integrated development environments and tools within a programming and version
control context;
• Understand the basics of code management systems;
• Translate pseudo-code into a readable, working program;
• Apply programming principles to solve domain-specific problems;
• Apply your knowledge and skills within the context of professional contributions to a
defined information space.
Submission and Assessment
The assignment is comprised of six parts that each will require you to complete a series of steps to
construct a Java program that adheres to the described specification. Remember to analyse the
problem as necessary and design a solution that suits the deliverables. You need to determine
the structures you will use. This is an application that will reuse elements significantly and as
such your development should consider this. At the conclusion of each task, you will be asked
to address several questions and report on the approach you have taken to complete the steps.
Treat this as a professional activity, so in-line comments, documentation and application output
should be presented appropriately for the target audience. Furthermore, your report should be
presented in a manner suitable for a professional audience.
Failure to use the supplied code repository will result in zero marks for this
assignment.
It is suggested that at a minimum you commit your code, with an appropriate comment, after
the completion of each task. That way if you do not complete all tasks you still have working
code for the final submission.
You will be awarded marks for the level of completion of your program (including answers to
the questions in each section). This assignment will be marked out of a total of 150 marks as
follows:
TASK : MARKS
Task 1 : 10
Task 2 : 30
Task 3 : 20
Task 4 : 20
Task 5 : 20
Task 6 : 30
Style (coding conventions and white-space) : 20
1
GE Assignment COMP8702– Semester 1, 2021
Development should be consistent with the IntelliJ environment, any issues running a program
developed in another IDE will result in a penalty of 50% of your grade.
HOW TO submit the code and revision number
On your final commit to the repository you need to take note of what the revision number i s. You
can see this in the versioning window in IntelliJ or do a “Subversion → Search History” and see
what the final commit revision number i s. Once you have that you can submit your assignment
and enter the final r evision n umber a long w ith y our P DF t o t he a ssignment s ubmission box
on FLO. The final r evision number g oes i nto t he O nline t ext e ntry, i n F igure 1 t he revision
number is 1234
You will need to submit your final revision number and your report as a single PDF document
on FLO by 5pm, Friday 4th June, 2021 (week 12).
Figure 1: How to submit your assignment on FLO
Academic Integrity
As required by Flinders University policy, a report on your submission will be generated by
the TurnItIn text-matching software, which compares your work with a large body of material
and generates a report of any similarities. Each student should carefully ensure that the work
they submit is their own and that any material directly sourced from the work of others is
properly acknowledged. A Drafts hand-in is available on FLO so you can check your work
before your final submission. Information on academic integrity, including the use of TurnItIn
and interpreting its reports, is available on the Academic Integrity for Students FLO page.
Please familiarise yourself with the policy.
2
GE Assignment COMP8702– Semester 1, 2021
Specification
You have been approached by a local education company to provide a software solution to help
students at all levels with their mathematics studies. The company requires an application
that produces random arithmetic expressions tailored to the level appropriate for the student.
This should be an application that is easy to use for students from Reception level to Year 7
(5 years old to 12 years old). It should be a text based application that presents an expression
and allows the user to type the answer. The application will confirm if the supplied answer is
correct or incorrect immediately and also keep track of the overall percentage for the student.
This overall percentage is reported at the end of the session with an appropriate statement of
feedback. The length of a session should be defined at the start of each session and can include
10, 20, 30, 40, or 50 questions. The following issues should be considered at the start of each
session, addressed by numbered menus:
• What is the level of the student?
Reception: only addition
Years 1 – 2: addition and subtraction
Years 3 – 4: addition, subtraction, multiplication, division (without remainder)
Years 5 – 6: addition, subtraction, multiplication, division (without remainder), negative
numbers
Year 7: addition, subtraction, multiplication, division (without remainder), division (with
remainder – presented as xry, where x is the result of the division and y is the
remainder, ie 10 % 3 = 3r1), negative numbers
• What is the length of the session?
– 10 questions
– 20 questions
– 30 questions
– 40 questions
– 50 questions
The year level that the user supplies will determine what number ranges are used.

units
units
tens
hundreds
(0 → 9)
(-9 → 9)
(-99 → 99)
(-999 → 999)
[ At Reception]
[ From Reception ]
[ From year 2 ]
[ From year 4 ]
thousands (-9999 → 9999) [ At year 7 ]
Example output could be as follows (user input in bold green):
+————————————————————————+
|
|
|
Welcome to the Maths Helper! |
|
|
Use this application to test your knowledge of mathematics
This program is intended for children from reception to year 7

+————————————————————————+
What is your year level?
Choose an option from the list below:
(where: + = addition, – = subtraction, * = multiplication,
3
GE Assignment COMP8702– Semester 1, 2021
/ = division, % = division with remainder)
[0] Reception [+]
[1] Year 1 [+, -]
[2] Year 2 [+, -]
[3] Year 3 [+, -, *, /]
[4] Year 4 [+, -, *, /]
[5] Year 5 [+, -, *, /, negative numbers]
[6] Year 6 [+, -, *, /, negative numbers]
[7] Year 7 [+, -, *, /, %, negative numbers]
3
How many questions would you like to attempt?
Choose an option from the list below:
[1] 10 questions
[2] 20 questions
[3] 30 questions
[4] 40 questions
[5] 50 questions
4
You are a year 3 student and want to do 40 questions. Is this correct (Y/N)? Y
Let’s begin … (press ‘Q’ at any time to quit)
If the student indicates that the information entered was incorrect then they should be prompted
to re-enter their details. Both menus should be displayed again until the user enters the correct
options.
A standard session will generate a random expression (random numbers and random operator)
and output the expression as a string to the terminal window. The application will wait for
a user response to the expression and once entered will assess the correctness of the input. A
string indicating the correctness of the student’s answer will be displayed and then the next
expression generated and displayed. This process will continue until all the questions in that
session have been answered.
Example output could be as follows (user input in bold green):
64 + 12 = 76
Correct! Well Done! Your current percentage is 100%
10 + 97 = 107
Correct! Well Done! Your current percentage is 100%
5 * 39 = 159
Bad luck that was incorrect. The correct answer was 195.
Your current percentage is 66.67%
22 / 58 = 0
Correct! Well Done! Your current percentage is 75%

Your total percentage was 72%. Well done. That was a good effort.
Did you want to have another go with the same settings (Y/N)? N
Did you want to start a new Session or Quit (S/Q)? S
+————————————————————————+

|
|
|
Welcome to the Maths Helper!
Use this application to test your knowledge of mathematics
This program is intended for children from reception to year 7
|
|
|

4
GE Assignment COMP8702– Semester 1, 2021
+————————————————————————+
What is your year level?
Choose an option from the list below:
(where: + = addition, – = subtraction, * = multiplication,
/ = division, % = division with remainder)
[0] Reception [+]
[1] Year 1 [+, -]
[2] Year 2 [+, -]

You are a Reception student and want to do 10 questions. Is this correct (Y/N)? Y
Let’s begin … (press ‘Q’ at any time to quit)
9 + 2 = Q
Thanks for playing.
Goodbye.
By entering the character ‘H’ the user is able to ask for a hint to be supplied. This hint should
display the last digit in the answer preceded by a ‘-’ for each extra digit in the answer. Any
subsequent requests for a hint will reveal the preceding digit. A student can continue to request
help for the expression until all digits are revealed. If this happens then this question should
be graded as incorrect. Example output could be as follows (user input in bold green):
84 * 7 = H
84 * 7 = –8: H
84 * 7 = -88: 588
Correct! Well Done! Your current percentage is 100.00%
104 * 58 = H
104 * 58 = —2: H
104 * 58 = –32: H
104 * 58 = -032: H
104 * 58 = 6032
Bad luck that has been marked incorrect because you used all of your hints.
Your current percentage is 66.67%
The application should respond to the user during a session. If they are finding the tasks too
difficult then the level of complexity should be reduced. The reverse is true if they are finding
it too easy – the level of difficulty should be increased. This evaluation should take place after
each lot of 5 questions. If the user has an overall percentage of more than 75% then increase
the level of difficulty by 1 year level. However, if the user has an overall percentage of less than
30% then reduce the level of difficulty by 1 year level. Difficulty cannot be increased above year
7 level or reduced below reception level.
Tasks
While the steps described below should be completed sequentially you should also pause during
your development to test recent changes and fix problems as they arise. Don’t leave testing
until you complete Task 6.
Task 1 – Initial Presentation
First, if you have not done so already, you will need to download and install a version of SVN
on your system so that you can connect to the repository and download the files using IntelliJ.
5
GE Assignment COMP8702– Semester 1, 2021
There is information on the FLO page on how to do this for both Windows and
Mac.
HOW TO: Configuring I ntelliJ t o c onnect t o t he repository
Before you begin, you will need to download (or check out) the template project from the
topic version control repository that has been setup for this assignment. In CP1, we are using
Subversion, a popular centralised code management system, for this purpose. Subversion is
commonly abbreviated as SVN. If you take further programming topics at Flinders, you will
likely work with version control systems more closely. For now, you will just focus on configuring
IntelliJ to connect to the repository so you can download the required files.
Open IntelliJ. From the welcome screen, choose Get from Version Control (see Figure 2). On
the window that appears, select Subversion from the dropdown list. Click the plus button or
the link in the centre of the window (if it is available), see Figure 3, and type in the following
repository location, replacing FAN with your own FAN (please put your FAN in lower-case!).
https://topicsvn.flinders.edu.au/svn-repos/COMP8702/FAN
Figure 2: Accessing the repository via the New Project screen
Click OK. You will likely be prompted to authenticate with the repository server. Enter your
University FAN and password to proceed. The repository location should now be listed (see
Figure 4). Expand the URL, select the MathHelper project, and click Check Out. Choose
a location on your machine to save the project from the SVN Checkout Options window that
appears and click OK. This will create a folder in the location you specified containing the
project files. If prompted for a working format, leave 1.8 selected and click OK. Once the check
out process has completed, the project should automatically open in IntelliJ. You can click
Add to any prompts regarding adding files to Subversion. You are now ready to begin.
You can now commit and update from the repository as you see fit (e.g. at the end of each
phase). The markers will also have access to this repository for assessment purposes.
You can browse the repository using an internet browser. However, it is expected that you
will use IntelliJ to access the repository (as in Figures 2, 3 and 4) for opening a project,
checking out and performing updates and commits. This is accessible both on and off campus
and it is expected that you will commit often to the repository.
6
GE Assignment COMP8702– Semester 1, 2021
Figure 3: The result of checking out from the
repository
Figure 4: Checking out the subversion
repository
Open the project in IntelliJ and take some time to read through the existing code and the
comments.
Once you have loaded the project into IntelliJ you should see several methods defined:
• displayWelcome()
• displayYearMenu()
• displayQuestionMenu()
As well as these methods that have content within their body there are also methods that
require further definition by you.
• letsPlay()
• printOutput(String str)
• confirmSessionDetails(int year, int questions)
Your task is to display the content to the user, capture their input and verify with the user that
the information they have provided is correct.
Looking at the displayWelcome() method you should see that it makes use of many calls
to the method printOutput(String str). You will need to define the operation of the
printOutput(String str) method. Looking at the JavaDoc comments above the method you
should be able to determine the functionality of this method. Printing the content to a file will be
handled in Task 6 of this assignment, however you will need to provide code to print the strings
to the console screen. Take note of the strings that are being passed to printOutput(String
str) to determine whether to use the print() or the println() method.
Once you have modified printOutput(String str) to print the string str to the screen you
will need to invoke the methods in the correct sequence. Add the necessary statements to the
letsPlay() method to enable this. When you run the program, output from these changes
should look like the following:
7
GE Assignment COMP8702– Semester 1, 2021
+————————————————————————+

|
|
|
Welcome to the Maths Helper!
Use this application to test your knowledge of mathematics
This program is intended for children from reception to year 7
|
|
|

+————————————————————————+
What is your year level?
Choose an option from the list below:
(where: + = addition, – = subtraction, * = multiplication,
/ = division, % = division with remainder)
[0] Reception [+]
[1] Year 1 [+, -]
[2] Year 2 [+, -]
[3] Year 3 [+, -, *, /]
[4] Year 4 [+, -, *, /]
[5] Year 5 [+, -, *, /, negative numbers]
[6] Year 6 [+, -, *, /, negative numbers]
[7] Year 7 [+, -, *, /, %, negative numbers]
How many questions would you like to attempt?
Choose an option from the list below:
[1] 10 questions
[2] 20 questions
[3] 30 questions
[4] 40 questions
[5] 50 questions
Now you will need to process user input and verify that the user is happy with the menu
selections that they have made.
A Scanner object scan has already been defined for your needs. Make use of the Scanner
operations to capture the user input. An instance variable yearLevel should be used to store
the user’s response to the year menu and a local variable numQuestions used to store the user
input from the questions menu.
Note that the confirmSessionDetails() method is a boolean type method; this means the
method is required to return a true or false value to the calling code.
Within the confirmSessionDetails() method you need to present the following information
to the user:
You are a yearName student and want to do questions questions. Is this correct
(Y/N)?
,where the bold values are determined based on user input.
At the moment you are capturing two integers from the user and passing them to
confirmSessionDetails(). Complete the following steps to fill in the necessary information
for the prompt above:
• You need to analyse the year value and if it is equal to 0 then yearName should be
Reception, otherwise yearName should be year year (where bold year represents the
integer passed to the method, i.e. if the user supplied option 5 from the year menu,
this would result in year 5).
• The value of questions is based on the menu selection, i.e. 1 for 10 questions, 2 for
8
GE Assignment COMP8702– Semester 1, 2021
20 questions, 3 for 30 questions . . . You should use this relationship to provide a suitable
number for questions to the prompt seen above.
Finally for the confirmSessionDetails() method you need to capture user input and if they
supply either a ‘Y’ or ‘y’ then they are happy with the input they provided otherwise the
program will need to repeat the presentation of both menus to the user and capture a fresh set
of inputs for yearLevel and numQuestions.
To achieve this you will need to return appropriate values (true or false) from the method.
Think about the process that you are asking the user to engage in:
Do the following:
What is your year level?
Get user input
How many questions?
Get user input
Is this information correct?
Get user input
While the information is NOT correct.
By following the above process you are locking the user into a loop until they provide a response
indicating that they have supplied the correct information (in this case either ‘Y’ or ‘y’). This
is achieved through a prompt and test process where you want the program to run through
the prompt at least once and then verify the user is happy with their input. The loop needs
to wrap around the displayYearMenu and displayQuestionMenu method invocations in the
main method. The return value you generate from confirmSessionDetails will control the
repetition of the loop. If the user has not provided the right details then repeat the loop, if
they have provided the correct details then end the loop.
At this point you should be able to present all the welcome details to the user and have them
make selections from each menu and then confirm the information provided is correct.
REPORT TASK
Your final task for this part is to document what you have done. Answer the following
questions:
i. What issues (if any) did you encounter with the SVN program?
ii. Describe any issues with the code as initially downloaded from the repository.
iii. What did you have to fix in order to compile and run the code successfully in IntelliJ?
iv. What strategy did you employ to verify that the user provided valid menu item values?
9
GE Assignment COMP8702– Semester 1, 2021
Task 2 – Generating random questions
Now that you have gathered the necessary information from the user it is time to begin the
actual session – so start by displaying “Let’s begin!” to the user. Within the letsPlay method
but after the do loop you completed in the previous step invoke the printOutput method to
display the string to the console. To generate random questions there are three things that need
to be gathered:
• the minimum number for a value in the expression
• the maximum number for a value in the expression
• the range of operators for the expression
All of these values are based on the year level of the user. Once these elements have been
gathered a question is generated and presented to the user. The process for completing these
tasks may look something like:
Repeat for the number of questions
Add one to the count
Generate a question based on the year
Get the minimum value
Get the maximum value
Generate a random number num1 between the minimum and maximum
Generate a random number num2 between the minimum and maximum
Get the operator
Print num1, operator, num2 to the screen
End
There are many sub tasks that are required to complete the above steps. Overall, we need
to repeat these operations for the total number of questions the user has requested – we can
use a counting or for loop to achieve this. Define a for loop that repeats for the number of
questions and place it after the printOutput(“Let’s begin!”) statement in your letsPlay
method.
We need to work out the user’s percentage of correct answers for a later task in the assignment,
to help facilitate this we will use an instance variable called count and increment it each time
the loop repeats, i.e. count++;. Declare the instance variable as type int and set it to 0 and
then within the for loop you have just declared increment the value.
So we don’t clutter up the letsPlay method and also to help with readability and re-usability
we are going to make use of several methods to complete the above steps.
In the space below your existing methods but within the class (ie. before the last }) define a
new void type method called generateQuestion(int year):
private void generateQuestion(int year)

The first thing we need to do within this method is to get the minimum value for the expression
based on the user’s year level. Declare an int type variable called min that will hold this
minimum value. We will assign the returned value from another method to this variable. To
10
GE Assignment COMP8702– Semester 1, 2021
accomplish this you should complete the variable declaration with an initialization statement,
i.e.:
int min = getMin(year);
When you type this in you should see an indicator (small light bulb with red warning sign)
appear in the line number margin within IntelliJ. Clicking once on the indicator brings up a
small popup box with a message within that reads:
Create method “getMin(int)” in MathHelper
Clicking on this message will get IntelliJ to create a method declaration for this method.
Looking at the specification above you can see that all students from reception to year 4 have
a minimum value of 0, while students in year 5 and 6 have a minimum value of -999, and year
7 users have a minimum value of -9999. With this knowledge you could create a collection of if
statements or use a switch statement to get the right value for the year level. The pseudo code
below describes the type of decisions that could be made:
If year equal 0
Set min to 0
If year equals 1
Set min to 0
If year equals 2
Set min to 0
If year equals 3
Set min to 0
If year equals 4
Set min to 0
If year equals 5
Set min to -999
If year equals 6
Set min to -999
If year equals 7
Set min to -9999
However, we can simplify this, consider:
Set min to 0
If year equals 5 or 6
Set min to -999
If year equals 7
Set min to -9999
With the above pseudo code we are setting the starting value to 0 and if none of the conditions
are met then this min value is not changed. This essentially allows us to set min to 0 (no
negative numbers until year 5) for all year levels from reception to year 4 with one line of code.
Using this shorter example of pseudo code implement this as working Java code within your
getMin() method.
Based on the above discussion complete similar steps for the max value. Declare a local variable
called max and assign it a value returned from a getMax() method.
Once you have identified the maximum and minimum ranges to the numbers within the expression
you can then generate the appropriate random numbers.
11
GE Assignment COMP8702– Semester 1, 2021
Declare local variables called num1 and num2 to hold the random values generated.
The next step in our plan is to get the operator that is to be used for the expression. As with
the min and max values the range of operators that the expression can have is based on the year
level of the user. Reception students only have one operator (+) for their expressions, year 1
and 2 students can have possibly 2 operators (+, -), while year 3, 4, 5, and 6 students can have
4 operators (+, -, *, /) and finally year 7 students can have 5 operators (+, -, *, /, %). As the
operators should be generated randomly we need to create a process that identifies first how
many possible operators we have access to and then generate a random value within that range
that maps to the operators. Using the same principles as getMin and getMax we can base our
decision on the year level, i.e.:
Set operatorBounds to 1
If year equals 1 or 2
Set operatorBounds to 2
If year equals 3 or 4 or 5 or 6
Set operatorBounds to 4
If year equals 7
Set operatorBounds to 5
Once we have the bounds we can then generate a random number within these bounds.
Generate a random number between 1 and the operatorBounds and return this value to the
calling method and assign it to an int variable oper.
The final step is to convert the int oper into a character that represents the type of operation
that we want to perform in our expression. In your generateQuestion method create a switch
based on the oper value that will assign a character to the local char variable op, i.e:
oper == 1 → op = ‘+’
oper == 2 → op = ‘–’
oper == 3 → op = ‘*’
oper == 4 → op = ‘/’
oper == 5 → op = ‘%’
As with the count variable discussed earlier we are laying the ground work for future tasks
and so we are placing the logic within the generateQuestion method rather than the getOper
method to help with the calculation of results from the expression – covered in Task 3.
Now you should have two int values assigned to num1 and num2 and a char value assigned to
op. The last step for this task is to combine these values into a string and print the string
to the console using printOutput. This statement should be placed at the bottom of your
generateQuestion method.
Finally, add the method invocation generateQuestion(yearLevel) to the loop you defined at
the start of this task. When you run your code you should see output similar to the following:
user input bold green.
+————————————————————————+

|
|
|
Welcome to the Maths Helper!
Use this application to test your knowledge of mathematics
This program is intended for children from reception to year 7
|
|
|

+————————————————————————+
What is your year level?
12
GE Assignment COMP8702– Semester 1, 2021
Choose an option from the list below:
(where: + = addition, – = subtraction, * = multiplication,
/ = division, % = division with remainder)
[0] Reception [+]
[1] Year 1 [+, -]
[2] Year 2 [+, -]
[3] Year 3 [+, -, *, /]
[4] Year 4 [+, -, *, /]
[5] Year 5 [+, -, *, /, negative numbers]
[6] Year 6 [+, -, *, /, negative numbers]
[7] Year 7 [+, -, *, /, %, negative numbers]
5
How many questions would you like to attempt?
Choose an option from the list below:
[1] 10 questions
[2] 20 questions
[3] 30 questions
[4] 40 questions
[5] 50 questions
2
You are a year 5 student and want to do 20 questions. Is this correct (Y/N)? y
Let’s begin!
107 / -10 = 635 + -884 = -737 + -560 = -90 * 940 = 290 / -151 = 113 / 594 = -464
* 73 = 826 – -924 = 271 / 478 = -471 * -666 = -885 + -542 = -107 * -666 = 922 –
769 = -96 + 996 = -728 / -704 = -553 – 372 = 472 * 917 = -451 – 982 = -920 + -500
= 77 / -389 =
You will notice that all the questions flow on to one and other on the same line. This will be
corrected during the next task where you will start to process user answers.
REPORT TASK
Answer the following questions:
i. The company has changed the specifications and would now like year level 4 to include
negative numbers and year level 6 questions to include modulo division. How would you
need to change the code to achieve this?
ii. The company has notified you that questions should now be output in a slightly different
format that includes a prefix identifying the question number in the format Qn where n
is the question number. For example, an addition question that is the first question in
the set should appear as:
Q1. 6 + 3 =
What would you need to change in the code to accomplish this?
13
GE Assignment COMP8702– Semester 1, 2021
Task 3 – Evaluating the answers
Now that the random questions are being generated we need to calculate the result of the
expression and confirm that the user has provided the correct a nswer. We will b e using strings
to do all our comparisons between the calculated result and the user supplied answer, so your
first task is to declare a local string variable result within the generateQuestion method and
assign it an empty string. Within the switch statement you defined i n t he l ast t ask ( used to
determine an operator) you should implement the appropriate calculation and assign the result
to the string variable.
If the operator is +
Set result to (num1 + num2)
If the operator is –
Set result to (num1 – num2)
If the operator is *
Set result to (num1 * num2)
. . . etc.
Remember that the output from the division with remainder should be XrY, where X is the
result of the division operation and Y is the result from the modulus operation. This is partly
the reason for defining result as a string.
Test your calculations by concatenating result to the end of your printOutput call at the bottom
of the generateQuestion method. The output you get should be testable with a calculator.
When you run your code you should see something like the following (I have concatenated an
additional space after result to break the expressions up, the following has been created for a
year 7 wanting 40 questions):
Let’s begin!
5591 – -5502 = 11093 9240 * 4355 = 40240200 7409 / -4570 = -1 -1157 * 1077 = –
1246089 5084 % 259 = 19r163 -3660 – -3298 = -362 -4008 / -2987 = 1 567 / -6323 =
0 2430 / -40 = -60 -129 / -1327 = 0 -445 * -4832 = 2150240 -6845 / -1975 = 3 813
* 4588 = 3730044 7825 * -1115 = -8724875 -2101 % 2410 = 0r-2101 8663 + -9640 = –
977 -9374 % -6708 = 1r-2666 -6683 % -9726 = 0r-6683 6171 % -542 = -11r209 -7067
* 3081 = -21773427 1022 / -762 = -1 5030 / 3358 = 1 9279 + 9013 = 18292 -1406 *
8914 = -12533084 -693 % 2860 = 0r-693 5130 / 5450 = 0 9873 * 6406 = 63246438 4432
/ -955 = -4 -4051 – 4732 = -8783 -1717 – -1628 = -89 2486 – 7542 = -5056 1905 *
-9607 = -18301335 8019 – 1058 = 6961 -8438 * -7187 = 60643906 -5321 + -3679 = –
9000 -8402 / 6044 = -1 464 / 2248 = 0 -2263 / -5231 = 0 6201 / -7971 = 0 1136 +
3690 = 4826
Once you are satisfied that the result is being calculated correctly remove the reference to result
from your printOutput method call.
Your task now is to evaluate whether the user has provided the correct answer. We will define
and call a method to complete this action. At the bottom of your generateQuestion method
write the following statement:
evaluateAnswer(result);
Use the process described previously to get IntelliJ to declare a new method with the appropriate
signature for the evaluateAnswer(result) method. Within this method we need to capture
the user input and compare it to the result the program generated. The following pseudo code
describes this process.
14
GE Assignment COMP8702– Semester 1, 2021
Set userIn to the user input
If userIn is the same as result
Increment correct
Print “Correct! Well Done!
Your current percentage is calculatedPercentage”
Otherwise
Print “Bad luck that was incorrect. The correct answer was result.
Your current percentage is calculatedPercentage”
Something that you should note – we are comparing strings for equality – use the appropriate
structures to assess this equality.
You will notice that there are two new things that have been described above: correct
and calculatedPercentage. correct should be an instance variable that gets initialised to
zero and then increments every time the student enters the correct answer. We can then
use this correct value combined with our count value defined previously to calculate the
calculatedPercentage, i.e. correct/count (remember this will be integer division but we
want a double value).
calculatedPercentage should be formatted to 2 decimal places. At the moment we are using
printOutput to send our strings to the output window, however, printOutput only accepts a
string as an argument. You will need to use an appropriate method to format the output as a
string percentage.
This means we cannot send this information to our current printOutput method (it only
accepts a single string as an argument). To deal with this we will overload the printOutput
method.
Declare a second void method called printOutput but declare formal parameters of type string
and double. Within this method make use of the method you determined above to display the
string and double appropriately formatted.
This will result in the output looking something like:
Correct! Well Done! Your current percentage is 100%
With the cursor waiting at the end of the line, which means the following expression will be
displayed on the same line, i.e.:
Correct! Well Done! Your current percentage is 100%50 + 72 =
Obviously this is not something that we want to happen; we want a percentage symbol after
100.00 and to place the cursor on a new line. To get the new lines we use the same use escape
sequences to introduce a new line as we have in the displayWelcome method.
At this point you should be able to run your program and have it present an expression to the
user and they should be able to provide a response. This response should then be evaluated
against the actual answer and then an appropriate message displayed to the user.
The last step for this task is to display a final message to the user when they have finished
the sequence of questions. This message should be based on their percentage achieved during
the session. When the loop generating questions has concluded you will need to calculate the
percentage and present this:
Your final score was calculatedPercentage%
Use the following pseudo code to define the next part of the message presented to the user:
If calculatedPercentage is less than 40
15
GE Assignment COMP8702– Semester 1, 2021
Print “Bad luck. Try practicing with some of the lower year levels to build your confidence and skills”
If calculatedPercentage is between 40 and 49
Print “That was a good effort but you may need to work on some of the expressions”
If calculatedPercentage is between 50 and 59
Print “Congratulations you passed. Keep practicing at this year level to improve your score”
If calculatedPercentage is between 60 and 74
Print “Well done. That was a good effort.”
If calculatedPercentage is between 75 and 84
Print “Good job. You should try the next year level in your next test”
If calculatedPercentage is more than 84
Print “Excellent work! You really know your stuff. Try the harder levels next time”
REPORT TASK
Answer the following questions:
i. Describe your implementation of the evaluateAnswer method. Explain how you read in
the user’s response to each question, check whether their answer is correct, and output
the appropriate feedback.
ii. The company has asked you to modify the program to include a count of the run of
correct answers and output encouraging messages for the length of the run.
How would you need to change the code to achieve this, and what foreseeable problems
may you encounter?
16
GE Assignment COMP8702– Semester 1, 2021
Task 4 – Adaptive Difficulty
For this task you should modify the program to respond to users who are either doing really
well or really poorly.
After each block of five questions if the calculated percentage is greater than 75% the program
should increase the difficulty by raising the yearLevel by one and displaying the message:
“You are doing well! Let’s increase the difficulty a little.”
However, if the calculated percentage is less than 30% then you should lower the yearLevel by
one and display the message:
“It seems your are having some difficulty. Let’s reduce the difficulty a little.”
You need to think about where the best place is to implement this test. Remember you have
an instance variable that tells you how many questions have been attempted during the session.
You should also be aware that the yearLevel cannot go below 0 or above 7.
REPORT TASK
Answer the following questions:
i. Describe why you chose the place to implement this test and what, if any, methods or
variables you were required to implement/create.
ii. Would it be easy to change the frequency of the check if required, i.e. after each block
of 7 questions?
Describe how this could be achieved.
Task 5 – Providing Hints and Quitting
TRICKY
With this task you will implement a system that allows the user to supply characters rather
than digits when answering each expression. The user will be able to type ‘q’ or ‘Q’ and quit
the application completely. They can also type ‘h’ or ‘H’ to receive a hint about the current
expression.
These user inputs will be caught at the same point where the user provides answers to each
expression. When you evaluate the answer you should define a statement that tests whether
the user has entered ‘q’ or ‘Q’, if they have then use the statement:
System.exit(0);
to close the program.
To get the hint functionality working you will need to lock the user into a loop that presents
a restructured expression every time they enter ‘h’ or ‘H’. For example, given the following
expression (user input in bold green):
-6804 + 2820 = h
If the user supplied ‘h’ for their answer then the expression should be restructured and display:
-6804 + 2820 = ––4:
and wait for the user to either supply an answer or request another hint or quit, for example:
17
GE Assignment COMP8702– Semester 1, 2021
-6804 + 2820 = —-4: h
-6804 + 2820 = —84: h
-6804 + 2820 = –984: -3984
Correct! Well Done! Your current percentage is 100%
If the user requests too many hints (i.e. a hint for every digit in the answer) then the guess
should be registered as incorrect and the normal process should follow.
To get the presentation of the hint correct you will need to keep track of how many hints have
been requested for the current expression. Use this value to display a string of “-” concatenated
together. This value you have used to hold the total number of hints can also be used to create
a substring that you should concatenate to the end of your string of “-”. Then display the
restructured expression to the user and retrieve their input. If the input is ‘h’ or ‘H’ then
repeat the process – use the following pseudo code to help:
Set hint to an empty string
Repeat while user asks for a hint
Repeat for (length of result – number of hints)
Set hint to hint + “-”
Set hint to hint + a substring of result starting at the character at position
(length of result – number of hints)
Print num1 + “ “ + op + “ “ + num2 + “ = ” + hint + “: ”
Get user input
If the user types in a digit then the normal processing should occur and the program should
test the correctness of the user’s answer.
REPORT TASK
Answer the following question:
i. Describe any difficulties you had in developing the solution to this task.
Task 6 – Logging and multiple sessions
For the last task you will need to implement a mechanism to allow for a log of all activity during
the session to be written out to a text file for later review by the teacher. You will need to use a
PrintWriter object to output to a text file. Each session should have its own unique text file –
the easiest way to complete this is to use the system time (in milliseconds) as the file name. To
get this value you can use the statement System.currentTimeMillis(). Concatenate a string
containing “.txt” to the time generated and assign this to a string called file. Use file as the
argument for the creation of a new PrintWriter. Now whenever you need to print something
to the screen you should also print the same content to the text file – this should be done within
your printOutput methods.
The challenge however is to capture user input and print this to the text file. Consider when
you capture this input and what you do with it.
When working with a file you need to be aware that your program may have difficulties
finding the file and you will also need to close the file when exiting your program (i.e. before
System.exit(0)).
Once you have this process working you should then set up your project to allow for multiple
18
GE Assignment COMP8702– Semester 1, 2021
sessions. These sessions should allow the user to repeat with the same settings (year level and
number of questions) or begin a new session with new settings. When you present the user with
their final score display the following message to the user:
“Did you want to have another go with the same settings (Y/N)?”
If the user supplies ‘y’ or ‘Y’ then print “Let’s begin!” and start generating new random
questions. If however the user supplies ‘n’ or ‘N’ then present them with the following message:
“Did you want to start a new session or quit (S/Q)?”
If they supply ‘s’ or ‘S’, then display the welcome message and the menus so they can define new
parameters for the next session. If they supply ‘q’ or ‘Q’ then quit the application. Your final
requirement is to ensure the user enters the correct information into the menus. If they enter
a value that is not recognized by the menu (i.e. a letter, symbol or digit outside the bounds of
the menu options) then present the menu to them again until they supply a legal value.
REPORT TASK
Answer the following questions:
i. Describe how you captured user input and printed this to the text file.
ii. The company has asked you to write a Graphical User Interface for the program you
have written. Could it be used as is, or would you need to rewrite parts of the code to
accomplish this? Discuss and explain.
19

CLAIM YOUR 50% OFF TODAY

X
Don`t copy text!
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
👋 Hi, how can I help?