Building an Android Tip Calculator App
- Feb 11, 2014
Introducing GridLayout, LinearLayout, EditText, SeekBar, Event Handling, NumberFormat and Defining App Functionality with Java
The Tip Calculator app (Fig. 3.1(a)) calculates and displays possible tips for a restaurant bill. As you enter each digit of a bill amount by touching the numeric keypad, the app calculates and displays the tip amount and total bill (bill amount + tip) for a 15% tip and a custom tip percentage (18% by default). You can specify a custom tip percentage from 0% to 30% by moving the SeekBar thumb—this updates the custom percentage shown and displays the custom tip and total (Fig. 3.1(b)). We chose 18% as the default custom percentage, because many restaurants in the United States add this tip percentage for parties of six people or more. The keypad in Fig. 3.1 may differ based on your AVD’s or device’s Android version, or based on whether you’ve installed and selected a custom keyboard on your device.
Fig. 3.1 | Entering the bill total and calculating the tip.
You’ll begin by test-driving the app—you’ll use it to calculate 15% and custom tips. Then we’ll overview the technologies you’ll use to create the app. You’ll build the app’s GUI using the Android Developer Tools IDE’s Graphical Layout editor and the Outline window. Finally, we’ll present the complete Java code for the app and do a detailed code walkthrough. We provide online an Android Studio version of Sections 3.2 and 3.4 at http://www.deitel.com/books/AndroidFP2.