Exercises

5.3 Fill in the blanks in each of the following statements:

a) When the user selects an item from a Menu, Activity method ______ is called to respond to the selection.

b) To delay an action, we use a(n) ______ (package android.os) object to execute a Runnable after a specified delay.

c) You can specify the number of times an animation should repeat with Animation method ______ and perform the animation by calling View method startAnimation (with the Animation as an argument) on the ImageView.

d) A(n) ______ is a collection of animations which make up a larger animation.

e) Android supports ______ animations which allow you to animate any property of any object.

f) For the android:fromXDelta attribute, specifying the value -5%p indicates that the View should move to the______ by 5% of the parent’s width (indicated by the p).

g) We use the ______ attribute of the application element to apply a theme to the application’s GUI.

5.4 State whether each of the following is true or false. If false, explain why.

a) The base class of all fragments is BaseFragment (package android.app).

b) Like an Activity, each Fragment has a life cycle.

c) Fragments can be executed independently of a parent Activity.

Project Exercises

5.5 (Enhanced Flag Quiz App) Make the following enhancements to the Flag Quiz app:

a) Count the number of questions that were answered correctly on the first try. After all the questions have been answered, display a message describes how well the user performed on first guesses.

b) Keep track of the score as the user proceeds through the app. Give the user the most points for answering correctly on the first guess, fewer points for answering correctly on the next guess, etc.

c) Use a SharedPreferences file to save the top five high scores.

d) Add multiplayer functionality.

e) If the user guesses the correct flag, include a “bonus question” asking the user to name the capital of the country. If the user answers correctly on the first guess, add 10 bonus points to the score; otherwise, simply display the correct answer, then allow the user to proceed to the next flag.

f) After the user answers the question correctly, include a link to the Wikipedia for that country so the user can learn more about the country as they play the game. In this version of the app, you may want to allow the user to decide when to move to the next flag.

5.6 (Twitter Searches App with Fragments) Reimplement the Twitter Searches app of Chapter 4 using a Fragment. Rather than having the Activity extend ListActivity, create a subclass of List-Fragment, then host an object of your new subclass in the class’s MainActivity.

5.7 (Road Sign Quiz App) Create an app that tests the user’s knowledge of road signs. Display a random sign image and ask the user to select the sign’s name. Visit http://mutcd.fhwa.dot.gov/ser-shs_millennium.htm for traffic sign images and information.

5.8 (U.S. State Quiz App) Using the techniques you learned in this chapter, create an app that displays an outline of a U.S. state and asks the user to identify the state. If the user guesses the correct state, include a “bonus question” asking the user to name the state’s capital. If the user answers correctly, add 10 bonus points to the score; otherwise, simply display the correct answer, then allow the user to proceed to the next state. Keep score as described in Exercise 5.5(c).

5.9 (Country Quiz App) Using the techniques you learned in this chapter, create an app that displays an outline of a country and asks the user to identify its name. If the user guesses the correct country, include a “bonus question” asking the user to name the country’s capital. If the user answers correctly, add 10 bonus points to the score; otherwise, simply display the correct answer, then allow the user to proceed to the next country. Keep score as described in Exercise 5.5(c).

5.10 (Android Programming Quiz App) Using the Android knowledge you’ve gained thus far, create a multiple-choice Android programming quiz using original questions that you create. Add multiplayer capabilities so you can compete against your classmates.

5.11 (Movie Trivia Quiz App) Create a movie trivia quiz app.

5.12 (Sports Trivia Quiz App) Create a sports trivia quiz app.

5.13 (Custom Quiz App) Create an app that allows the user to create a customized true/false or multiple-choice quiz. This is a great study aid. The user can input questions on any subject and include answers, then use it to study for a test or final exam.

5.14 (Lottery Number Picker App) Create an app that randomly picks lottery numbers. Ask the user how many numbers to pick and the maximum valid number in the lottery (set a maximum value of 99). Provide five possible lottery-number combinations to choose from. Include a feature that allows the user to easily pick from a list of five popular lottery games. Find five of the most popular lottery games in your area and research how many numbers must be picked for a lottery ticket and the highest valid number. Allow the user to tap the name of the lottery game to pick random numbers for that game.

5.15 (Craps Game App) Create an app that simulates playing the dice game of craps. In this game, a player rolls two dice. Each die has six faces—we’ve provided die images with the book’s examples. Each face contains one, two, three, four, five or six spots. After the dice have come to rest, the sum of the spots on the two top faces is calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3 or 12 on the first throw (called “craps”), the player loses (the “house” wins). If the sum is 4, 5, 6, 8, 9 or 10 on the first throw, that sum becomes the player’s “point.” To win, a player must continue rolling the dice until the point value is rolled. The player loses by rolling a 7 before rolling the point.

5.16 (Craps Game App Modification) Modify the craps app to allow wagering. Initialize the variable balance to 1000 dollars. Prompt the player to enter a wager. Check that wager is less than or equal to balance, and if it’s not, have the user reenter wager until a valid wager is entered. After a correct wager is entered, run one game of craps. If the player wins, increase balance by wager and display the new balance. If the player loses, decrease balance by wager, display the new balance, check whether balance has become zero and, if so, display the message "Sorry. You busted!"

5.17 (Computer-Assisted Instruction App) Create an app that will help an elementary school student learn multiplication. Select two positive one-digit integers. The app should then prompt the user with a question, such as

How much is 6 times 7?

The student then inputs the answer. Next, the app checks the student’s answer. If it’s correct, display one of the following messages:

Very good!

Excellent!

Nice work!

Keep up the good work!

and ask another question. If the answer is wrong, display one of the following messages:

No. Please try again.

Wrong. Try once more.

Don't give up!

No. Keep trying.

and let the student try the same question repeatedly until the student gets it right. Enhance the app to ask addition, subtraction and multiplication questions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset