Home > Articles > Programming > Java

Building an Android Tip Calculator App

  • Print
  • + Share This
This chapter shows you how to create an interactive Android app: the Tip Calculator. It provides step-by-step instructions covering the GUI, coding, and debugging.
This chapter is from the book

Introducing GridLayout, LinearLayout, EditText, SeekBar, Event Handling, NumberFormat and Defining App Functionality with Java

3.1. Introduction

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

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.

  • + Share This
  • 🔖 Save To Your Account