Tuesday, September 22nd — 11:59pm
This project is designed to give you some hands on experience with…
- Using Xcode as a development environment
- Using Interface Builder to create iPhone user interfaces
- Declaring and wiring up outlets
- Declaring and wiring up actions
- Testing applications in the iPhone Simulator
For this assignment you will be writing a basic tip calculator program app for the iPhone. Your application must contain the following elements…
- An overall title label noting that the app is a tip calculator
- A label and corresponding text input to enter the amount of the check
- A label and corresponding text input to enter the tip percentage
- A button that calculates the tip amount based on the specified check amount and tip
- A label (or set of labels) that are used to identify and display the tip amount in dollars
- A label (or set of labels) that are used to identify and display the overall total in dollars
An example user interface is shown below.
When your app initially loads it should look similar to the image shown below.
When a user clicks on either of the text fields, they should automatically be presented with the numbers and punctuation keyboard so the user can enter a floating point amount. The “Return” key should be changed so that it says “Done” — additionally, when the user presses this key, the keyboard should automatically go away.
If the user presses the button to calculate the tip, the computed tip amount and overall check amount should be set, neatly formatted to 2 decimal places with a leading dollar sign. Additionally, the text fields should be cleaned up and displayed with 2 places after the decimal.
Since we haven’t yet learned how to restrict and format the text fields in real-time as the user types, these fields could really contain anything once the user is done with the keyboard. As such, we need to be prepared to account for a user that has entered non-numeric input. One such error handling strategy is detailed below.
Let’s say that the user entered some bad text into one of the text fields as illustrated below.
When the user presses the calculate button, we validate both of the text fields to ensure that they are floating point numbers. If they are not, we could replace the contents of the bad text field with an error message, and clear out the calculated tip amount and overall check amount.
You will need to turn the string representations of check amount and tip percentage into actual numbers for performing both validation and then computation. There are several techniques available to achieve this — though for this assignment, I’d recommend using the NSScanner class. This class can extract numerical (and other) values out of strings (similar to Java’s java.util.Scanner class).
The following items are provided as thoughts as to how you might extend or improve the project beyond the basic requirements. You are not required to implement any of these.
- Try out alternate color combinations — just don’t make my eyes bleed
- Feel free to play with the layout and style of elements — just be sure that things are neatly aligned and that there is at least some justifiable method to your madness
- Add an image to the app if you think it will improve the look and feel of the application
Create a new project by selecting File → New Project… then under iPhone OS select View-based Application. Select Choose…
Feel free to name the project as you see fit — though remember that things such as the app name and class names will get generated based on the name you give the overall project.
Your projects will be graded on the following criteria:
- Correctness of application
- Appearance of application
- Adherence to Objective-C and iPhone coding conventions
- Neatly formatted and indented code
- Well documented header files
- Absence of significant performance issues
- Absence of memory leaks
Like the previous assignment, you are required to submit a zip file of your project directory. Be sure to manually remove the build directory before zipping things up.
To submit the assignment, open up a terminal, navigate to your zip file then issue the command:
submit cs491i assignment2 Assignment2.zip
If developing on your own Mac, you’ll need to transfer the file into your GL account (via SCP), then SSH into GL and issue the submit command.