IOS objective-c代写:CSCI-UA.0480 – iOS Programming – Fall 2016 – MAKEUP TEST

NAME______________________________

CSCI-UA.0480 – iOS Programming – Fall 2016 – MAKEUP TEST

Midterm – Written Portion

51. (40 points) Write a Sample ATM App:

This ATM app consists of actions implemented via UIButtons:
Withdraw – mapped to an IBOutlet withdrawButton – used for withdrawal
Deposit – mapped to an IBOutlet depositButton – used for deposit
Multiple Transactions – mapped to an IBOutlet multipleTransactionsButton – used for multiple transactions of withdrawal and deposit. Also when pressed it disables Close Account button, enables done button and itself gets disabled.
Done – mapped to an IBOutlet withdraw – Disabled initially and is enabled when Multiple Transactions is pressed. On pressing the button, it indicates that multiple transactions are completed and displays computed result. It also gets disabled when pressed.
Close Account – mapped to an IBOutlet closeAccountButton – Used to close the account and remove the userDetails. Disabled when Multiple Transaction is pressed.

and three text Fields:

Username Password Amount

A dictionary called “userDetails” needs to be created which contains the Password and Balance for the corresponding accounts. A subset of this dictionary might look like:

Key – UserName(NString) Steve
Tim
Wozniak

Bill Larry Sergey

Value{Password, Balance} (NSObject) {Apple, 10000}
{DestroyApple, 1000}
{T echno, 23}

{Microsoft, 15000} {Google, 3000} {Google, 3000}

You can obviously add your own names to the subset.

The ATM appallows withdrawals and deposits. Note that the account also allows a negative balance to occur. Additionally, a user can do multiple transactions which are recorded and processed when they have all been input, which lessens the delay at each step of transaction. The multiple Transaction Button facilitates the same thing.

The user can also close his or her account by clicking the close account button.
Assuming the button actions have already been correctly defined and the actions make use of

your methods to do operations, please code your methods.

There are five methods to write on the following pages. Assume the Main.storyboard has already been built for you.

The methods check for the text from username and password in the userDetails dictionary. If it doesn’t exist in the dictionary, or doesn’t match the dictionary, it then invokes a method called incorrectUserNameOrPassword. Please include the check wherever it is needed.

Hint : the above needs to be done whenever using any particular account data: Use the getter for the UI.

ATMViewController.h

#import <UIKit/UIKit.h>
@interface ATMViewController : UIViewController

@property (nonatomic) IBOutlet UITextField *userName; @property (nonatomic) IBOutlet UITextField *password;

@property (nonatomic) IBOutlet UITextField *ammount;
@property (nonatomic) IBOutlet UIButton * closeAccountButton; @property (nonatomic) IBOutlet UIButton * closeAccountButton; @property (nonatomic) IBOutlet UIButton * withdrawButton; @property (nonatomic) IBOutlet UIButton * depositButton;
@property (nonatomic) IBOutlet UIButton * multipleTransactionsButton; @property (nonatomic) IBOutlet UIButton * doneButton;
@property (nonatomic) IBOutlet UIButton * closeAccountButton;

-(IBAction)withdraw :(id) sender; -(IBAction)deposit :(id) sender; -(IBAction)MultipleTransactions :(id) sender; -(IBAction)Done :(id) sender; -(IBAction)CloseAccount :(id) sender; -(void) inCorrectUserNameOrPassword;

@end *****************

ATMViewController.m

#import “ATMViewController.h”
@implementation ATMViewController
@property (nonatomic,retain) NSDictionary *userDetails;

– (void)viewDidLoad
{ [super viewDidLoad];
[self createATMUI];
_userDetails = [self createDictionary]; }

51a. (10 pts) WRITE THE WithdrawOrDeposit METHOD – given the Amount and the operation which is sent to you.
* This function takes the Amount and operation type(deposit/withdraw) as input
* and returns the balance amount in the account. It also checks if the value in Username * and password exist in the dictionary, and matches correctly. It then uses the

* balance from this user to calculate final balance.

-(int)WithdrawOrDeposit:(int)Amount:(NSString *) Type{

}

51b. (10 pts) WRITE THE MultipleTransactions METHOD
* This function inputs an array of amounts and an array of strings
* Each string is the type of operation(deposit/withdraw) which then invokes * WithdrawOrDeposit and returns the final balance

-(int)MultipleTransactions:(NSArray*)Amount:(NSArray*)Type{

}

51c. (15 pts) WRITE THE createDictionary METHOD
* In this method, the user creates and returns a dictionary that associates

the Username with the password and the balance in account for the given users

-(NSDictionary*) createDictionary {

return userDetails; // return the dictionary }

51d.(5pts) WRITE the CloseAccount METHOD
* This method removes a pre-existing account. It checks for correctness of username

and password. Note that it should print an error if no such account exists.

-(void)CloseAccount{

}