COIT20245 Programming Assignment 3
COIT20245 Programming Assignment 3
FINAL PROJECT
Quiz questions
(Assessment item 3)
Student ID Student Name This coversheet must be completed with your submission.
Please check (X) to indicate that you have satisfied these requirementsThis work and my programming submission are my original work and no part of it has been copied from any other students work or any other source.
No part of this work or my code has been written for me by any other person/student/software program.
I have taken proper and reasonable care to prevent this work and my code from being copied by another student.
I acknowledge that it is my responsibility to check that the file submitted is readable and complete and that the code submitted can be uploaded in NetBeans and will compile and run correctly.
I understand that plagiarism also includes the act of assisting or allowing another person to plagiarise or to copy my own work.
Instructions
This Word document is to be submitted in the Project Part 1 submission link. It must have your 10, original, quiz questions in the format described below.
This document is to contain the following information about each of your 10 quiz questions:
The concept being tested by the question.
The week the question relates to (the week the concept was covered in lectures and/or tutorials). Each question must test a concept from a different week.
An explanation of the correct answer.
The quiz questions can be either multiple choice, true/false or fill in the missing word type questions. However, remember that:
Answers are restricted to a single token a letter, a word or true/false respectively.
Your questions (and answers) must be pitched at an appropriate level for Masters students. In particular, an excess of straightforward recall questions will be penalizedMultiple choice questions must contain a minimum of 4 choices and a maximum of 6 choices.
You must have at least 6 multiple choice questions.
The format should be as follows:
Question: <question number>Week: <week number>Concept: <concept tested>
<The question>
Answer: <answer>
Reason: <explanation of the answer>
An example question is provided in the assignment specification.
Remove this line and the instructions above from your final submission.
COIT20245 Programming Assignment 3
FINAL PROJECT
(This is the program report template a separate template is provided for your quiz questions.)
(Assessment item 3)
Student ID Student Name This coversheet must be completed with your submission.
Please check (X) to indicate that you have satisfied these requirements:
This work and my programming submission are my original work and no part of it has been copied from any other students work or any other source.
No part of this work or my code has been written for me by any other person/student/software program.
I have taken proper and reasonable care to prevent this work and my code from being copied by another student.
I acknowledge that it is my responsibility to check that the file submitted is readable and complete and that the code submitted can be uploaded in NetBeans and will compile and run correctly.
I understand that plagiarism also includes the act of assisting or allowing another person to plagiarise or to copy my own work.
Instructions
A description of what is required in each section is shown in italics. Please remove all the instructions from your final report.
Description of the Program and Phase Completed
<this is to be a brief description of the completed, working phase you have submitted. It is to describe the functionality of the submitted program. It is not intended to be for a programmer, but for a user or a customer. >
For example:
Phase 2 all phase 2 functionality has been completed. (Although, ideally you should be submitting a completed final phase.)
This program .. <a description of what the program does goes here>
Testing
<This section is to have the description of your test plan and then the results showing the actual behaviour of your program when you carry out the tests. Always show the test data used and if your application uses files, include the data in input/output files.>
Different phases will have different checks/tests that will be required (including a repeat of the checks from earlier phases to make sure earlier functionality is still working when you complete a new phase). As a result, this list of test cases will increase as you develop each phase.
Test Plan
<You are to list all the test cases that you will employ to convince yourself that your program is working correctly (both general/normal and special conditions). Explain how you will perform the test (including any test data used) and the expected behaviour and output / results>
Test Output (result of testing)
<Screenshots of each of your tests to demonstrate the different functions are working as specified and the result of the test (i.e. pass/fail) i.e. was the actual output the same as the expected output for that data). Include test cases that show special cases behave correctly (e.g. screenshots with error/warning messages for the boundary/special conditions and checks that any data validation is carried out correctly as well as general cases. (For e.g. if searching for something in a list you should have cases to test item found, item not found, item is the first element in a list, item is the last element in a list, item is an element in the middle of the list and the program behaves sensibly with an empty list.)>
Bugs and Limitations
Bugs
<Either state no known bugs or describe any bugs you are aware of in your code>
For example, you may have statements similar to the following:
Either
No known bugs
Or
you may still have problem (s)/bugs that you have to report if you did not have time to fix a bug.
Hopefully you will have no known bugs to report, but if you do have bugs and do not report them here, you will lose marks for the bug in the code and you will lose marks for inadequate testing (as well as losing the mark for not documenting known bugs)
Limitations
<any limitations in your program>
Additional Future Work
<What extensions would be useful in this application in the future?>
COIT20245
Assignment 3
-19050379730Final Project
Due: Monday of week 13. Check the exact date and time in the submission area on the unit website.
Weighting: 50%
To be Submitted:
There are two separate submission areas for this assessment item - one for each of the following:
The Word document with your 10 Quiz questions
The program (in a NetBeans project) and the report.
Note that:
Your program must be submitted as a NetBeans project that uses Java 17 or the marker will not be able to test your work and no marks will be awarded.
No marks will be awarded if the assignment does not compile and run. Markers must be able to run and test your code to mark it. It is therefore essential that you develop the code incrementally and maintain a backup of your last working phase. If your last phase does not compile and run, then you must submit the previous phase that does compile and run. In addition, always check that you have submitted the correct work. (A good test is to download your submission and check it on a different machine.)
Contents
TOC o "1-3" h z u Introduction PAGEREF _Toc145764572 h 3The UML class Diagram PAGEREF _Toc145764573 h 4Summary of the classes (and their methods) in the UML class diagram. PAGEREF _Toc145764574 h 5Implementation Phases PAGEREF _Toc145764575 h 7Phase 0: Preparation PAGEREF _Toc145764576 h 7Phase 1: Ask each question once PAGEREF _Toc145764577 h 7Phase 2: Allow multiple attempts PAGEREF _Toc145764578 h 9Phase 3: Add Logging PAGEREF _Toc145764579 h 10Phase 4: Save the log data to a file PAGEREF _Toc145764580 h 11Phase 5: Read the quiz questions from a text file PAGEREF _Toc145764581 h 12To Be submitted PAGEREF _Toc145764582 h 13Marking Criteria PAGEREF _Toc145764583 h 14Appendix 1 Example quiz question for Word document submission PAGEREF _Toc145764584 h 15Appendix 2 Format of a quiz question in the input file for the quiz application PAGEREF _Toc145764585 h 16Appendix 3 Example of questions in arrays PAGEREF _Toc145764586 h 17Appendix 4 Sample output for the complete application PAGEREF _Toc145764587 h 18
IntroductionIn this assignment, you are to write, test and document a command line quiz application for use in COIT20245. Quiz questions can be of the following form:
Multiple choice
Fill in the missing wordTrue or false
and can span multiple lines. Answers are restricted to a single token a letter, a word or true/false respectively.
There are two parts to the assignment:
Part 1 (10%) Development of 10 quiz questions that illustrate your understanding of key concepts in the unit. You are to provide a set of 10 questions with each question relating to the unit content from a different week (from weeks 1-11).
This is to be submitted in the Project Part 1 submission area which is separate from the submission area for part 2 (the quiz program that you develop). The format of this submission is different to the .txt file used as input to your program. It must have additional information for the marker (i.e. the week being tested, the concept being tested, the answer and justification for the answer). More details about the format of this file can be found in Appendix 1.
Your questions (and answers) must be pitched at an appropriate level for Masters students. In particular, an excess of straightforward recall questions will be penalised, as will multiple questions on the same weekly content.
Your quiz must have at least 6 multiple choice questions (i.e. 4 of the questions could be a combination of true/false or fill in the missing word questions).
To use your questions to test your program you would first have to add them to a text file with the format specified in Appendix 2.
Note: You should commence building your 10 question quiz from week 2 of the unit. After you have studied the new content for a week and completed the tutorial work you should write an appropriate quiz question to test a key concept from the new work studied. It is important to develop your quiz questions during the term - at the end of the term you will need to focus on development of the software application to allow a user to take the quiz. However, it is also important to understand the new content before you write the quiz question.
Part 2 (40%) Development of the application to allow a user to take the quiz. This must be developed using Apache NetBeans. The zip file of the NetBeans project and the unzipped Word document with the program report are to be submitted in the Project Part 2 submission area.
The application is to run in one of two modes:
questions (and answers) are loaded from a text filequestions (and answers) are specified using array initializersThe file format to be used in mode 1 is described in Appendix 2. For mode 2, you are to use Java text blocks, which will be discussed in the lectures in week 10. Example question and answer arrays that use textblocks and can be used to build the questions array are provided in Appendix 3.
If a question is answered incorrectly, the user is given a second chance. If that answer is incorrect, then the correct answer is displayed. The number of attempts per question and the result for each question is to be recorded. On completion of the quiz, a detailed report is saved to a file and a summary of the report will be displayed on the console. A sample run is presented in Appendix 4.
The UML class DiagramA UML class diagram for the application is provided in Figure 1. Your application must conform to this design or you will not be given a passing grade for the assignment. In this regard, note that no additional classes and/or public methods / variables are permitted. Public methods must have the same names, parameter lists and return types shown in the diagram. Accessors (public/private) must also correspond to the class diagram. You may add private helper methods (or additional private members although if you need them you may not have understood the design). If you believe that there is something missing in the diagram please discuss this with the unit coordinator.
Figure 1. The UML diagram for the quiz application
Summary of the classes (and their methods) in the UML class diagram.Note that for all the classes, you can write private helper methods. For example, I had a private ask() method in the Manager class that was called by the public takeQuiz() method to ask a question and check its correctness etc.
The App Class
This is the application class with the main() method. The main() method is to:
Construct the Quiz object. If the no argument constructor is used then the questions array is to be built using a private method that uses question and answer arrays that are specified using array initializers. The questions are to be specified using Java text blocks. See Appendix 3 for an example.
Construct the Manager object. The Manager classs constructor is to be passed a reference to the quiz object and the number of attempts allowed for a question. In your final submission this value should be 2. However, the code should also work if a different number of attempts was passed into the constructor i.e. if 1, then only one attempt should be allowed, if 3 then 3 attempts should be allowed etc.
Starts the quiz by invoking the manager objects takeQuiz() method.
The Quiz Class
An object of this class is to have the array of quiz questions to be asked. It must also keeps track of the current question being asked. It has a firstQuestion() method that is to return the first question in the quiz (and set current to the first question). It has a nextQuestion() method that is to return the next question (and set current to that next question). If there is no next question nextQuestion() is to return null to indicate that there are no more questions to be asked. The Quiz class has two constructors. The no argument constructor populates the questions array using array initialisers. The second constructor takes a filename and reads the questions and answers to populate the questions array from a file. The laboratory/tutorial questions in week 10 should help you with this.
The Manager Class
An object of this class manages the quiz. It has a takeQuiz() method that is to use the quiz objects getFirst() method (to get the first question in the quiz) and nextQuestion() method to iterate through the quiz questions asking the user the question, getting their response, checking their answer (using the question objects mark() method), allowing a second attempt if necessary and logging the result for the question. For each question the log object stores whether or not the question was answered correctly and the number of attempts. At the end of the quiz, the manager object is to display a summary of the number of correct answers and the number of attempts on the console (see the sample output in Appendix 4). It can obtain this information using the log objects correct() and attempts() methods that are to return the number of correct answers and the number of attempts respectively.
In addition to the summary, the information about the users performance in each question is to be saved at the end of the quiz. Initially this log information is to be displayed on the console and then in a subsequent phase it is to be saved in a file.
The Question Class
An object of this class is to store the question and answer for a single quiz question. It has the following methods:
getQuestion() and getAnswer()to return the question and answer respectively
mark() which is to mark the question. It checks whether or not the users response is equal to the answer and returns true or false depending on whether or not the answer was correct.
The Log Class
An object of this class is used to store/log the results for each question. It does this using an ArrayList of Entry objects. It has a save method that is used to output the log information to a file after the quiz is complete. As discussed, this is to be invoked at the end of the takeQuiz() method in the Manager class. The methods in the Log class are as follows:
Log() is the no argument constructor
add() is to add a new entry to the answers log (details of the users result for the question and number of attempts)
attempts() is to return the total number of attempts to answer the questions in the quiz
correct() is to return the total number of questions the user got correct
numberOfQuestions() is to return the number of questions in the quiz
save() is to save the details in the answers array list to a file (final phase). In the earlier phases this is will display the information on the standard output. z
The Entry Class
For each quiz question completed an Entry object is constructed with the details about the users performance in that question (the question number, did the user get the correct answer or not and how many attempts were made). The Entry object is stored in the array list of the log object. (Note that Java now has records as well as classes. It would have been appropriate to use a record in this case. However, we have not covered records in the unit.)
Implementation PhasesThe application is to be developed incrementally in 5 phases, as indicated below:
Phase 0: PreparationRead Section 1 and the Appendices carefully and make sure that you understand how the classes defined in Figure 1 will contribute to the achievement of the requirements detailed in Section 1. If anything is unclear, discuss the matter with your tutor.
Phase 1: Ask each question onceImplement the App, Question, Quiz and Manager classes from Figure 1. Note that no logging/reporting is required in this phase only per question feedback is to be provided. Therefore, there is no need to include the Log and Entry classes in this phase. You should add the log instance variable to the Manager class later when it is needed in phase 3.
Each question is only to be asked once in this phase i.e. the user is not permitted any other attempts to answer the question if a wrong answer is given.
In this phase only the no argument constructor, is to be implemented in the Quiz class. It is to populate the questions array using data specified using array initializers that use textblocks.
You must use a private helper method (called load()) to populate/load the questions array. This load() method must be called from the Quiz classs no argument constructor so that the array of quiz questions gets built. The private load method is not shown in the UML class diagram. As you know you can add additional private methods to a class. However, you should not add additional public methods not shown in the class diagram. The start of the load() method with some sample test data is provided below:
private void load() {
String[] q = {
"""
Q1. Which of the following numbers is irrational?
a. pi
b. 22/7
c. 3.14159
d. all of the above
"""
,
"""
Q2. Which of the following numbers is rational?
a. pi
b. 22/7
c. 3.14159
d. none of the above
"""
,
"""
Q3. Two methods can be overloaded if they differ only in their return types.
true or false?
"""
,
"""
Q4. A variable must be ---- before it can be used.
"""
};
String[] a = {
"a" , // q1
"b" , // q2
"false", // q3
"declared" // q4
};
// TO DO: Add the code to create the Question array and to populate it with
// Question objects based on the data in the q and a arrays above
}
Iteration through the questions array is to be achieved using the methods firstQuestion() and nextQuestion(); null is to be returned by nextQuestion() If there is no question to return. (Hint: In the Quiz class the instance variable called current is to be used as the index into the array of questions. firstQuestion() should set current to 0 and return the first question in the array (i.e at index 0). nextQuestion() should increase the value of current by 1 so that it will be an index into the next question. nextQuestion() should return the next question or null if there are no more questions to be asked.)
The Manager object should have an instance variable that is a reference to the Quiz object (passed into the constructor). In the takeQuiz() method it should use and able to use the Quiz objects firstQuestion() and nextQuestion() methods to iterate through the quiz questions.
The algorithm for the takeQuiz() method is given below:
Set question number to 0 // used later when logging details about question attemptsquestion = Get the first question from the quiz (e.g. quiz.firstQuestion())
while (question != null)
ask the question get the answer from the user check the answer from the user (use the question.mark() method to check if the answer was
correct)
if the answer was correct
print correct
else
print incorrect
increment the question number
Although we are only going to ask each question once in this phase, you still need to pass a number as the second argument to the Managers constructor. You should pass in a value of 2 (i.e. 2 attempts) to the Manager constructor in readiness for subsequent phases.
Note: There is a laboratory/tutorial question in week 6 in which you are asked to complete a quiz application. However, the design and specification in week 6 is different to this assignment and the code will be of limited use.
A sample run of phase 1:
Console Output (user responses shown in bold below)
run:
Q1. Which of the following numbers is irrational?
a. pi
b. 22/7
c. 3.14159
d. all of the above
> b
Incorrect
Q2. Which of the following numbers is rational?
a. pi
b. 22/7
c. 3.14159
d. none of the above
> b
Correct
Q3. Two methods can be overloaded if they differ only in their return types.
true or false?
> true
Incorrect
Q4. A variable must be ---- before it can be used.
> declared
Correct
BUILD SUCCESSFUL (total time: 19 seconds)
Phase 2: Allow multiple attempts
In this phase you are to extend the application so that the user is allowed a number of attempts to answer the question. The number of attempts is specified by the second argument passed to the Manager objects constructor. My example test runs in this document from phase 2 onwards have a limit of 2 passed to the constructor, but your code should cater for whatever limit (or number of attempts allowed) is passed to the constructor.
Given that you now need a loop to iterate until the user gets the correct answer or the allowed number of attempts has been reached, I would recommend that you now put the code to loop around asking a specific question, getting the users answer and checking the answer into another method that gets called from inside the takeQuiz() loop. You could call that method processQuestion and pass it the question number and the question to be processed.
Why would it be a good idea to use a do while loop inside the method to process a single question?
Phase 3: Add LoggingIn this phase you will add the logging functionality.
You will now have to add the Log and Entry classes to your project and make the required changes to the Manager class so that the information about the users performance in each quiz question gets logged (i.e. stored in the array list in the log object) and so that the summary and log information is displayed at the end of the quiz.
At the end of the loop to process a single question use the Log objects add method to add an entry to the ArrayList of Entry objects that gets stored in the Log object. The add method needs to create a new Entry object and add it to the array list. This is where we are logging the information about each question question number, number of user attempts at that question and whether it was answered correctly (or not).
When the takeQuiz() method has no further questions to ask, it is to use the Log object to get
the number of questions that were correct (using the Log objects correct() method)
the total number of attempts in the quiz (using the Log objects attempts() method.
the number of questions in the quiz (there should be an entry for each question in the log)
This summary information is to be displayed after the quiz completes i.e. at the end of the takeQuiz() method after all the questions have been asked/processed. See the sample output for this phase below.
Ultimately (in phase 4) It is also to use the log objects save() method to save the results for each question in a file. However, in this phase the log objects save() method is to initially display the log data to the console rather than to a file.
The summary information in the sample run below indicates that the user got 3 questions correct out of 4 questions and that there were a total of 6 attempts answering the 4 questions
Sample output for this phase is shown below:
Console Output (user responses shown in bold below)
run:
Q1. Which of the following numbers is irrational?
a. pi
b. 22/7
c. 3.14159
d. all of the above
> b
Incorrect
> c
Incorrect
Q2. Which of the following numbers is rational?
a. pi
b. 22/7
c. 3.14159
d. none of the above
> b
Correct
Q3. Two methods can be overloaded if they differ only in their return types.
true or false?
> false
Correct
Q4. A variable must be ---- before it can be used.
> named
Incorrect
> declared
Correct
Correct answers : 3/4
Attempts : 6/4
Question Correct Attempts
1 false 2
2 true 1
3 true 1
4 true 2
BUILD SUCCESSFUL (total time: 31 seconds)
Phase 4: Save the log data to a fileChange the save() method in the Log class to save the log information to a text file, rather than displaying the log information on the console.
Note that the summary information with number of questions correct and number of attempts is still to be displayed on the console. A fixed filename is to be used for the file. It is to be called report.txt. As we are not going to specify a path it will be written to the NetBeans project directory with the src folder. You can view its contents using a simple text editor such as Notepad. A sample run for this phase is shown below:
Sample output for this phase is shown below:
Console Output (user responses shown in bold below)
run:
Q1. Which of the following numbers is irrational?
a. pi
b. 22/7
c. 3.14159
d. all of the above
> b
Incorrect
> c
Incorrect
Q2. Which of the following numbers is rational?
a. pi
b. 22/7
c. 3.14159
d. none of the above
> b
Correct
Q3. Two methods can be overloaded if they differ only in their return types.
true or false?
> false
Correct
Q4. A variable must be ---- before it can be used.
> named
Incorrect
> declared
Correct
Correct answers : 3/4
Attempts : 6/4
BUILD SUCCESSFUL (total time: 31 seconds)
In this phase the following log information should be able to be viewed in the report.txt file:
Question Correct Attempts
1 false 2
2 true 1
3 true 1
4 true 2
Phase 5: Read the quiz questions from a text fileIMPORTANT: If you complete phase 5, do NOT remove the no argument Quiz constructor or the private load() method that loads the quiz from hardwired tables using textblocks. The markers must still be able to view and test that code to be able to award marks for that part of the work completed in phase 1.
Provide the Quiz class with a Quiz(String file) constructor, which will load the questions array from data stored in a text file. The file format to be used is specified in Appendix 2. A fixed filename is to be used for the file. The file is to be called quiz.txt. As we are not going to specify a path it must be located in the same directory as the src folder for the project. The tutorial questions in week 10 should help with this part of the assignment but take care as there are some differences. For example, we do not build an array of Question objects for the quiz in the week 10 tutorial. In the tutorial we read the questions into a questions array of type String and the answers array into an answers array of type String. In the assignment these arrays will be built, but you then need use them to build the array of Question objects.
Note that the format of the file to be read by your program is NOT the same format that is to be used for the separate submission of your quiz questions for marking (worth 10%). The submission of 10 questions for marking must Be the format shown in the template document and must include the information about the week, the concept being tested and the explanation/justification for the answer. See an example of this in Appendix 1.
To Be submittedIn the submission area for the quiz questions (Project Part 1 Quiz Questions) you are to submit:
A Word document with your 10 quiz questions. For each question you are to clearly show the week, the concept, the question, the answer and an explanation for the answer. An example for one question is given in Appendix 1 and a template that you must use for this submission is provided under this assignment specification.
In the Project Part 2 (Program and Report) submission area you are to submit:
A zip file with your NetBeans project. If you have completed phase 5, this must also include a quiz.txt file that you used to test your program (see Appendix 2 for the format of this file).
The report for your program clearly showing your test plan and results of testing your program. A template that you must use for this submission is provided under this assignment specification.
Make sure that:
your source code is documented using Javadoc for the comments before class and method headers; the layout is correct;you follow the coding guidelines and good practices for Java programming provided on the unit website.
Details of marking criteria are as discussed already in assessment items 1 and 2 (i.e. layout, good programming practices, testing etc.)
The mark breakdown for this assignment is in the following table:
Marking CriteriaThis assessment item is worth 50% of your overall mark for the unit.
Part 1: The set of 10 Quiz questions (10%)
These will be marked based on the following:
quality, correctness, appropriateness of the level of the question (i.e. testing concepts not just basic recall /definitions)
questions are from 10 different weekseach question must show clearly the week and the concept being tested, the answer and the justification for the answera minimum of 6 multiple choice questions (4-6 choices). There can be a combination of up to 4 true/false and/or missing word questionsPart 2: The code and report (testing, limitations etc.) (40%)
Functionality
(and correct use of programming constructs)
Follows Design specified Code Documentation
& Layout Good coding practices
(Naming conventions, meaningful names, efficient code - see guide) Report
Limitations and Testing
(includes thorough test plan and test results) Total
Phase 1
(asks each question once) 10 4 1 6 21
Phase 2
(allows multiple attempts) 5 1 1 2 9
Phase 3
(Logs information and summarises) 9 3 1 2 15
Phase 4
(writes logs to a file) 2 1 1 2 6
Phase 5
(reads questions from a file) 4 1 1 3 9
Total 30 10 5 15 60
Note: The final mark for this part of the assignment will be converted to a mark out of 40. This part of the assessment item is worth 40% of your marks.
The code must follow the design specified and must compile and run to be awarded marks.
Appendix 1 Example quiz question for Word document submissionAn example quiz question illustrating the format and information to be included for each question is provided below.
The 10 quiz questions are to be submitted in a Word document in the Project Part 1 submission area. The format for the quiz question submission is not the same format as the input file used to test your program. Note that you must write your own questions. The Word document will go through Turnitin.
As you can see in the example below, each question is to include the following:
the week the question relates to ( the week the concept was covered in lectures and/or tutorials). Each question must test content from a different week.
the concept being tested by the questionan explanation of the correct answer.
Multiple choice questions normally have 4 options, but may have between 4 and 6 options. There must not be less than 4 or more than 6 options.
Your program must be able to handle true/false and missing word questions. However, you must have at least 6 multiple choice questions in your quiz.
Example Question showing format for presenting the required information for each question:
Question: 1 Week: 5Concept: Shadowing and the keyword this
Q1. In the following code for an Account class constructor, the word this may have been used in a place or places where it is not required.
public class Account{ String type; String id; double balance; int customerId; public Account(String type, String acctId, double balance, int id){
this.type = type;
this.id = acctId; this.balance = balance;
this.customerId = id;
}
}
Which line or lines of code (if any) do not need to use this to reference the instance variables of the class.
A. line 7 does not require the keyword this.
B. line 8 does not require the keyword this.
C. line 9 does not require the keyword this.
D. line 10 does not require the keyword this.
E. None of the above. It is needed in all cases.
Answer: D
Reason: customerId is the only instance variable identifier not shadowed by one of the parameter identifiers.
Appendix 2 Format of a quiz question in the input file for the quiz applicationNote: this is not the format for your separate submission of your 10 quiz questions for 10%. The submission of 10 questions for marking must be the format shown in the template and include the information about the week, the concept being tested and the explanation/justification for the answer. An example of the requirements for the submission of 10 quiz questions was shown in Appendix 1.
For Phase 5, questions and answers are to be provided in a text file. A fixed pathname could be used for the file. However, in the assignment you are just to specify the filename. In that case the file must be located in the same directory as the src folder for the NetBeans project. Call your file quiz.txt. The data can be entered into the file using a simple text editor such as Notepad.
The format of the file is described below.
The first record in the file is the number of questions in the quiz. This is then followed with sets of two records, corresponding to a question and its answer. Questions are delimited by lines containing QS (question start) and QE (question end). Answers are delimited by lines containing AS and AE. Questions can consist of multiple lines. Answers are restricted to a single letter or word. Blank lines are permitted for formatting purposes.
A sample file with three questions is shown below:
3
QS
Q1. Which of the following numbers is irrational?
a. pi
b. 22/7
c. 3.14159
d. all of the above
QE
AS
a
AE
QS
Q2. 0 is a natural number. true or false?
QE
AS
false
AE
QS
Q3. A ---- number can be expressed as p/q, where p and q are
both integers and q does not equal 0
QE
AS
rational
AE
Appendix 3 Example of questions in arraysExample question and answer arrays used to build the questions array in phase 1. The array q is the array of questions and array a is the array of corresponding answers.
String[] q = {
"""
Q1. Which of the following numbers is irrational?
a. pi
b. 22/7
c. 3.14159
d. all of the above
"""
,
"""
Q2. 0 is a natural number. true or false?
"""
,
"""
Q3. A ---- number can be expressed as p/q, where p and q are
both integers and q does not equal 0
"""
};
String[] a = {
"a" , // q1
"false" , // q2
"rational", // q3
};
Appendix 4 Sample output for the complete applicationSample output for the completed application.
Console Output (user responses shown in bold below)
run:
Q1. Which of the following numbers is irrational?
a. pi
b. 22/7
c. 3.14159
d. all of the above
> a
Correct
Q2. 0 is a natural number. true or false?
> true
Incorrect
> flaseIncorrect
Q3. A ---- number can be expressed as p/q, where p and q are
both integers and q does not equal 0
> rational
Correct
Correct answers : 2/3
Attempts : 4/3
BUILD SUCCESSFUL (total time: 34 seconds)
The contents of the log file(report.txt) is as follows:
Question Correct Attempts
1 true 1
2 false 2
3 true 1