Class Variables and Instance Variables

Lines 20–32 of Fig. 3.11 declare class MainActivity’s variables. The NumberFormat objects (lines 20–23) are used to format currency values and percentages, respectively. NumberFormat static method getCurrencyInstance returns a NumberFormat object that formats values as currency using the device’s default locale. Similarly, static method getPercentInstance formats values as percentages using the device’s default locale.

The bill amount entered by the user into amountEditText will be read and stored as a double in billAmount (line 25). The custom tip percentage (an integer in the range 0–30) that the user sets by moving the Seekbar thumb will be multiplied by 0.01 to create a double for use in calculations, ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.