CSCI 490E/680K Assignment 5 - Android Programming - Spring 2012
04/09/2012
Overview
For this assignment you will write an Android app that presents a multiple choice quiz. The quiz contents will be encoded in an xml file of your design and will be read by the app which will parse the xml file and build Java object(s) to represent the quiz contents within the program. This program will also implement a simple options menu that will allow the user to
take the quiz,
invoke a Web browser to study for the quiz, or
view an About screen
Each of these screens will be implemented as a separate Activity class.
In addition, there will be a simple "goodbye" screen/Activity which will be presented after the last question has been answered.
In order to keep the complexity of this project within reason, the following conditions and limitations will pertain:
the quiz can have any number (1 - many) questions. If the number of questions is changed in the xml file, the program will not change in any way but the displayed quiz will have more or fewer questions.
the number of answer choices for each question will be exactly 4.(You should make and use a single named final constant with a value of 4. You will never code '4' except in the declaration of this single constant.)
the program can assume that an xml file of the proper structure exists. (You will have to create it, of course.) If the name of this file were to change, a change to a single String constant in the program would be all that is necessary for the program to work properly.
The main (launch) activity will display a suitable title in a moderately large font and the message "Press Menu key to begin". Then the options menu will allow the user to make any one of the three 'jump to screen' choices listed above in the bulleted list. Only the opening screen will have the menu - the user will use the device's back button to come back to this opening screen to make a different choice.
The Quiz Activity will use a RadioButton group to display the question and the answer choices. Each new question will use the same RadioButton Group and RadioButtons to present the new question and answers (Just change the texts). This screen will also show two Buttons: Judge and Next. Judge will tell the user if the current choice is correct or not by means of a "Toast" message. Next will display the next question or will present a "Toast" message that the quiz is finished and will transfer control to the Goodbye Activity screen. This Activity will display a quiz percentage (based on two values passed to it). and a Goodbye message. You should disable the Next Button each time a new question is presented, and enable it only after the test-taker has answered the question correctly.
The Web browser Activity should specify the course home web page (http://www.seasite.niu.edu/cs680Android/default.htm) as the Url to display. See the textbook's Chapter 15 on the Webkit Browser for details on how to do this. Do not forget to specify internet permission in the Android Manifest file. After the <manifest> attributes, as a child element of <manifest> add:
<uses-permission android:name="android.permission.INTERNET"/>
The About Activity will display a multiline message with a Title, a Version number, the author(s)' Name(s), and the message "To quit, press your device's 'Home' button".
The Goodbye Activity will simply present a new screen
with a large-ish message indicating that the quiz is over, the quiz percentage
correct, and instructions to press the device's Home key.
This Activity will be invoked using the startActivity() method with an
Intent object naming the Goodbye Activity class, passing the 2 numbers
need to calculate and display the percentage correct..
The Quiz xml File & Processing
You are to write an xml file to represent the quiz data. This file must be stored in your project's \res\xml directory. It should include the following:
1. A top-level element representing the whole quiz with a name attribute. This name will be displayed at the top of the quiz screen.
2. Since a quiz is made of many questions, a repeated element will represent a question. (That is, this question element will be repeated multiple times in the file, each time with different values/data, of course.) This element type should have three attributes:
name - the value can just be an index number 01, 02, etc. We will not actually use it in this program.
text - the value is the text of the question, e.g. "What is the Android class name of textual label?"
correct answer - either a, b, c, or d.
3. Each question has 4 answer choices. So an answer choice should be a repeated element, coded as 4 child-elements within each question. Values should start with "a)" or "b) etc. for clarity, followed by the candidate answer, e.g. "a) EditText" or "b) Label" etc. The only data within these elements will be the text of the answer choice.
Although we have not studied xml specifically, you have seen enough samples of xml to enable you to do this. If you have questions, write out your best try (neatly) and bring it to my office for assistance.
In order to use this data in your program you will need to read the xml file and extract the (String) data to build a set of Question objects. You will also need to devise a suitable design for Question objects so that the program will be able to extract the data to set the question and answer texts on the Quiz Activity screen, and to determine if the user's answer is correct or not.
Fortunately, there is a class (XmlPullParser) that can help with the parsing of the xml file. An example of its use will be given in class and is in the Lecture Notes Part 6.
Note that although the example uses XmlPullParser.START_TAG to figure out when a new element has just been encountered, there is also an XmlPullParser.END_TAG that can tell you, for example, when a question's data has ended (so you can build a Question object with data you've saved).
Once you are getting all the data and understand how the parsing works, you can begin to think about how to build Question objects. You should ultimately put the Question objects into a Arraylist, since the program can make no assumption about the number of questions in the quiz. This step (reading, parsing, building objects) should be done in the Quiz Activity, since it is difficult to pass complex structured data to other Activities.
Hand in printed copies of all source code as well as the xml file for the quiz screen layout and the actual quiz data.