Exercises

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

a) String literals should be placed in the strings.xml file in the app’s _________ folder.

b) A component’s _________ specifies its relative importance with respect to other components.

c) Class _________ of package android.app provides the basic lifecycle methods of an app.

d) Interface _________ of package android.text allows you to change the content and markup of text in a GUI.

e) You implement interface _________ of package android.widget to respond to the user moving the SeekBar’s thumb.

f) Android apps have four types of components—activities, services, content providers and _________.

g) Throughout its life an activity can be in one of several states—active (or running), paused or _________. The activity transitions between these states in response to various events.

h) Class _________ (nested in class R)—contains constants for the GUI components in your XML layout files.

i) Method setContentView uses a received constant to load the corresponding XML document, which is then parsed and converted into the app’s GUI. This process is known as _________ the GUI.

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

a) By default, a Seekbar allows you to select values from 0 to 255.

b) A GUI component can span multiple columns in a GridLayout.

c) Every Activity subclass must override the Construct method.

d) A paused activity is visible on the screen and has the focus.

e) Time-consuming initializations should be done in an onCreate method instead of the background process.

f) You override the onStart method to initialize the app when it’s launched.

3.5 (Enhanced Tip Calculator App) Make the following enhancements to the Tip Calculator app:

a) Add an option to calculate the tip based on either the price before tax or after tax.

b) Allow the user to enter the number of people in the party. Calculate and display the amount owed by each person if the bill were to be split evenly among the party members.

3.6 (Mortgage Calculator App) Create a mortgage calculator app that allows the user to enter a purchase price, down payment amount and an interest rate. Based on these values, the app should calculate the loan amount (purchase price minus down payment) and display the monthly payment for 10, 20 and 30 year loans. Allow the user to select a custom loan duration (in years) by using a SeekBar and display the monthly payment for that custom loan duration.

3.7 (College Loan Payoff Calculator App) A bank offers college loans that can be repaid in 5, 10, 15, 20, 25 or 30 years. Write an app that allows the user to enter the amount of the loan and the annual interest rate. Based on these values, the app should display the loan lengths in years and their corresponding monthly payments.

3.8 (Car Payment Calculator App) Typically, banks offer car loans for periods ranging from two to five years (24 to 60 months). Borrowers repay the loans in monthly installments. The amount of each monthly payment is based on the length of the loan, the amount borrowed and the interest rate. Create an app that allows the customer to enter the price of a car, the down-payment amount and the loan’s annual interest rate. The app should display the loan’s duration in months and the monthly payments for two-, three-, four- and five-year loans. The variety of options allows the user to easily compare repayment plans and choose the most appropriate.

3.9 (Miles-Per-Gallon Calculator App) Drivers often want to know the miles per gallon their cars get so they can estimate gasoline costs. Develop an app that allows the user to input the number of miles driven and the number of gallons used and calculates and displays the corresponding miles per gallon.

3.10 (Body Mass Index Calculator App) The formulas for calculating the BMI are

Image

or

Image

Create a BMI calculator app that allows users to enter their weight and height and whether they are entering these values in English or Metric units, then calculates and displays the user’s body mass index. The app should also display the following information from the Department of Health and Human Services/National Institutes of Health so the user can evaluate his/her BMI:

BMI VALUES
Underweight: less than 18.5
Normal:      between 18.5 and 24.9
Overweight:  between 25 and 29.9
Obese:       30 or greater

3.11 (Target-Heart-Rate Calculator App) While exercising, you can use a heart-rate monitor to see that your heart rate stays within a safe range suggested by your trainers and doctors. According to the American Heart Association (AHA), the formula for calculating your maximum heart rate in beats per minute is 220 minus your age in years (http://bit.ly/AHATargetHeartRates). Your target heart rate is a range that is 50–85% of your maximum heart rate. [Note: These formulas are estimates provided by the AHA. Maximum and target heart rates may vary based on the health, fitness and gender of the individual. Always consult a physician or qualified health care professional before beginning or modifying an exercise program.] Write an app that inputs the person’s age, then calculates and displays the person’s maximum heart rate and target-heart-rate range.

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

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