Lecture 6 — iPhone App Details

iPhone App Details

iPhone App Details

Advertisements

Assignment 2

Due Date

Tuesday, September 22nd — 11:59pm

Background

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

Task

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.

Tip Calculation App

Tip Calculation App

Behavior

When your app initially loads it should look similar to the image shown below.

Initinal App State

Initinal App State

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.

Keyboard Entry

Keyboard Entry

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.

Resulting Tip Calculation

Resulting Tip Calculation

Error Handling

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.

Entering Bad Input

Entering Bad Input

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.

Handling Bad Input

Handling Bad Input

String Parsing

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).

Additional Ideas

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

Getting Started

Create a new project by selecting File → New Project… then under iPhone OS select View-based Application. Select Choose…

Creating a View-based Application

Creating a View-based Application

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.

Grading

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

Submission

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.

Lecture 5 — iPhone App Basics

iPhone App Basics

iPhone App Basics

Header File Documentation

I’m posting to address a couple of questions as to the expected level of documentation. Basically I’m looking for your header file to serve as stand-alone documentation for your class and methods. If a developer were given your header file, they should have what they need to start using it.

For those wondering about a JavaDoc equivalent, there are primarily 2 options in the Objective-C world…

I’d recommend using either of the above tools as they are more than capable of generating good HTML documentation, though you are not required to use them. For this assignment, the minimal header documentation I’m looking for is along the lines of the code shown below. Implementation files need not be as detailed, instead comments should document code that is non-obvious.

#import <Cocoa/Cocoa.h>

/*
Person class consisting of a name and age.
*/
@interface Person : NSObject {
  (NSString *)name;
  (int)age;
}

/*
Returns a person with the given name and age.
newName - The name to assign to the Person.
newAge - The age to assign to the Person.
*/
-(id)initWithName:(NSString *)newName age:(int)newAge;

/*
Returns the name of the Person.
*/
-(NSString *)name;

/*
Sets the name of the Person to the specified name.
newName - The new name for the Person.
*/
-(void)setName:(NSString *)newName;

/*
Returns the age of the Person.
*/
-(int)age;

/*
Sets the age of the Person to the specified age.
newAge - The new age for the Person.
*/
-(void)setAge:(int)newAge;

@end

Testing Submit

Objective

To make sure each of you can submit a project using the submit program. This is not simply a test of whether you can follow the directions for submitting projects, but also to make sure that I have correctly setup an area for to each of you, individually, to hold your project files.

Submit Usage

The OIT project submission system will be used for submission of projects for this course. The submit system is comprised of a set of commands available on GL, that allows you to submit files electronically for grading. The submit commands available on GL are:

  • submit <course> <project> <file(s)> — submit assignments
  • submitls <course> <project> — lists files that you have submitted
  • submitrm <course> <project> <file(s)> — removes files that you have submitted

For this class the value of course will always be “cs491i”, so all commands will start with “submit cs491i”.

submit

The submit <course> <project> <file(s)> command is used to submit files. You can specify 1 file at a time, or multiple files at a time.

linux3[2]% submit cs491i assignment0 foo.txt
Submitting foo.txt...OK
linux3[3]% submit cs491i assignment0 bar.txt baz.txt
Submitting bar.txt...OK
Submitting baz.txt...OK
linux3[4]%

You can also use the submit <course> <project> <file(s)> to overwrite previously submitted files. It doesn’t hurt to submit what you have periodically, that way if for some reason you are unable to submit nearer the deadline (i.e. internet access or computer dies), you will at least have something submitted.

linux3[4]% submit cs491i test foo.txt
It seems you have already submitted a file named foo.txt.
Do you wish to overwrite? (y/n):
y
Submitting foo.txt...OK
linux3[5]%

submitls

You can check and see what files you have submitted using the submitls <course> <project> command.

linux3[5]% submitls cs491i assignment0
total 8
drwx------    2 dhood2   rpc          2048 Sep 13 16:04 .
drwx------   78 dhood2   rpc          4096 Sep 13 15:55 ..
-rw-------    1 dhood2   rpc             0 Sep 13 16:04 bar.txt
-rw-------    1 dhood2   rpc             0 Sep 13 16:04 baz.txt
-rw-------    1 dhood2   rpc             0 Sep 13 16:04 foo.txt
linux3[6]%

submitrm

If you accidentally submit a wrong file or you no longer need a file that is submitted, you can remove files using the submitrm <course> <project> <file(s)> command. Take note that when you do a submitrm, the file that you submitted is most likely gone for good and unable to be recovered.

linux3[5]% submitls cs491i assignment0
total 8
drwx------    2 dhood2   rpc          2048 Sep 13 16:04 .
drwx------   78 dhood2   rpc          4096 Sep 13 15:55 ..
-rw-------    1 dhood2   rpc             0 Sep 13 16:04 bar.txt
-rw-------    1 dhood2   rpc             0 Sep 13 16:04 baz.txt
-rw-------    1 dhood2   rpc             0 Sep 13 16:04 foo.txt
linux3[6]% submitrm cs491i assignment0 baz.txt
Deleting baz.txt
linux3[7]% submitls  cs491i assignment0
total 8
drwx------    2 dhood2   rpc          2048 Sep 13 16:04 .
drwx------   78 dhood2   rpc          4096 Sep 13 15:55 ..
-rw-------    1 dhood2   rpc             0 Sep 13 16:04 bar.txt
-rw-------    1 dhood2   rpc             0 Sep 13 16:04 foo.txt
linux3[8]%

Test Submission

To verify that everything is setup okay issue the following commands. Be sure to verify that you see the “Submitting testfile…OK” line. Also make sure that it actually shows up when using the submitls command.

linux3[1]% touch testfile
linux3[2]% submit cs491i assignment0 testfile
Submitting testfile...OK
linux3[3]% submitls cs491i assignment0
total 6
drwx------    2 dhood2   rpc          2048 Sep 13 16:18 .
drwx------   78 dhood2   rpc          4096 Sep 13 15:55 ..
-rw-------    1 dhood2   rpc             0 Sep 13 16:18 testfile
linux3[4]%

If you see something other than the results above send me an email ASAP so that I can get the problem resolved before it is time to submit a “real” assignment. Letting me know that there is a problem 2 minutes before midnight on the due date will probably result in you not being able to submit a project for grading.

Lecture 4 — Advanced OOP Topics in Objective-C

Advanced OOP Topics in Objective-C

Advanced OOP Topics in Objective-C

Assignment 1 — Properties

Due to the projector bulb burning out and running short on time tonight, we didn’t get chance to cover the section on properties from Lecture 3.

The count method in the Assignment 1 description references the use of properties. We’ll finish the rest of the Lecture 3 material (including properties) at the beginning of class on Thursday evening.