Problem Solving For Programming
TMA
Name: Nikolay Stamatov| Course: Year One – Bsc Computing| Date: 23.11.2016
Task 1. Problem Decomposition
a)
The principal part (sub-problem):
-Get card from the user[IJ1]
-and ask for PIN.[IJ2]
-Check PIN.[IJ3]
-Get the amount from the user.[IJ4]
-Calculate the amount.[IJ5]
-Return card.
-Give out the cash.
Assumptions:
-There will always be enough money.
-There will always be power supply.
-Hardware never fails.
-£10 and £20 notes only.
-English language used.[IJ6]
-Connectivity to backend database resilliant \ high availability?
-Hardware is assisted technology compliant (for those who are blind)
-The hardware is secure (anti theft devices)
-Location (inside \ outside), waterproof?
-
b)
PROGRAM<AutomatedTellerMachine>
- Insert card;[IJ7]
- Request pin from user
- Enter pin;
- Query database and very PIN is correct
- Select cash amount;[IJ8]
- Verify cash amount (are you sure you want X amount)
- Eject card;
- Dispense cash;
END
Task 2. Start-up
PROGRAM<AutomatedTellerMachine>
- DECLARE boolean insertCard = false;[IJ9]
- Display message “Enter pin”;
- IF[IJ10]insertCard = true
- Enter pin;
- Select cash amount;
- Eject card;
- Dispense cash;
- ENDIF
END
Note:There would be an automatic positive response if the card is recognised by the ATM.
Task 3. PIN Entry
a)
Variables / Description / ValuepinRequired / Pin stored in the card / 1234
pinEntered[IJ11] / Does pin entered matches pin on card / 0
b)
PROGRAM<AutomatedTellerMachine>
- DECLARE boolean insertCard;
- DECLARE integer pinEntered=0;
- CONSTANT pinRequired = 1234; [IJ12]
- pinRequired = Get user PIN from database
- Display message “Enter pin”;
- IF insertCard
// entry pin number
- Enter pinEntered;[IJ13]
- WHILE (pinEntered != pinRequired)
- Display message “Wrong pin”;
- Re-enter pin;
- pinEntered = New PIN entered by user
- ENDWHILE
- Select cash amount;
- Eject card;
- Dispense cash;
- ENDIF
END
Note: I have used a WHILE Loop to allow the user of entering the PIN unlimited times until match the card PIN.
Task 4. Menu Choices
a)
Variable / Description / ValuedispenseAmount / Amount of cash to be dispense / £10-£200
menuOption / Withdraw or View Balance / 1 OR 2[IJ14]
b)
PROGRAM<AutomatedTellerMachine>
- DECLARE boolean insertCard;
- DECLARE integer pinEntered=0;
- DECLARE integer dispenseAmount = 10 to 200;[IJ15]
- CONSTANT pinRequired = 1234; //
- Display message “Enter pin”;
- IF insertCard
// entry pin number
- Enter pinEntered;
- WHILE (pinEntered != pinNumber)
- Display message “Wrong pin”;
- Re-enter pin;
- ENDWHILE
- IF (buttonOne is pressed[IJ16])
- Check balance;
- ENDIF
- IF (buttonTwo is pressed)
- Withdraw cash;
// withdrawal
- Select cash amount;
- IF (buttonThree is pressed)
- dispenseAmount = £10;
- ENDIF
- IF (buttonFour is pressed)
- dispenseAmount = £20;
- ENDIF
- IF (buttonFive is pressed)
- dispenseAmount = £50;
- ENDIF
- IF (buttonSix is pressed)
- dispenceAmount = £100;
- ENDIF
- IF (buttonSeven is pressed)
- dispenseAmount = £200;
- ENDIF
- Ejectcard;
- Dispense cash;
- ENDIF
END
Note: Simple command that shows Menu choices and amount of cash to be dispense.
Task 5. Dispencing Cash
a)
Variable / Description / ValuerequiredAmount / Amount of Cash / £10-£200
10NotesToDispense / Integer Number of £10 notes to dispense / 1,2,3,4,5
20 NotesToDispense / Integer Number of £20 notes to dispense / 1,2,3,4,5
b)
PROGRAM<AutomatedTellerMachine>
- DECLARE boolean insertCard;
- DECLARE integer pinEntered=0;
- DECLARE integer dispenseAmount = 10 to 200;[IJ17]
- DECLARE integer requiredAmount = 10 to 200;
- Declare 10NotesToDispense = 0
- Declare 20NotesToDispense = 0
- CONSTANT pinRequired = 1234;
- Display message “Enter pin”;
- IF insertCard
// entry pin number
- Enter pinEntered;
- WHILE (pinEntered != pinRequired)
- Display message “Wrong pin”;
- Re-enter pin;
- ENDWHILE
// withdrawal
- Select cash amount;
- IF (requiredAmount = 10)
- dispenseAmount = (1 x £10);
- 10NotesToDispense = 1
- ELSE IF (requiredAmount = 20)
- dispenseAmount = (1 x £20);
- 20NotesToDispense = 1
- ELSE IF (requiredAmount = 50)
- dispenseAmount = (2 x £20) and (1 x £10);
- 10NotesToDispense = 1
- 20NotesToDispense = 2
- ELSE IF (requiredAmount = 100)
- dispenceAmount = (5 x £20);
- 20NotesToDispense =5
- ELSE IF (requiredAmount = 200)
- dispenseAmount = (10 x £20);
- 20NotesToDispense =10
- ENDIF
- Eject card;
- Dispense cash using the number of notes number defined in 20NotesToDispense and 10NotesToDispense.
- ENDIF
END
Note: In this task, I used avery simple command for dispensing the cash. I decided to use this simple method after an unsuccessful attempt with a different command.
c)
PROGRAM<AutomatedTellerMachine>
- DECLARE boolean insertCard;
- DECLARE integer pinEntered = 0;
- DECLARE integer requiredAmount = 10 to 200;
- Declare 10NotesToDispense = 0
- Declare 20NotesToDispense = 0
- CONSTANT pinRequired = 1234;
- Display message “Enter pin”;
- IF insertCard
// entry pin number
- Enter pinEntered;
- WHILE (pinEntered != pinNumber)
- Display message “Wrong pin”;
- Re-enter pin;
- ENDWHILE
// withdrawal
- Select cash amount;
- IF (requiredAmount = 10)
- dispenseAmount = (1 x £10);
- 10NotesToDispense = 1
- ELSE IF (requiredAmount = 20)
- dispenseAmount = (1 x £20);
- 20NotesToDispense = 1
- ELSE IF (requiredAmount = 50)
- dispenseAmount = (2 x £20) and (1 x £10);
- 10NotesToDispense = 1
- 20NotesToDispense = 2
- ELSE IF (requiredAmount = 100)
- dispenceAmount = (5 x £20);
- 20NotesToDispense =5
- ELSE IF (requiredAmount = 200)
- dispenseAmount = (10 x £20);
- 20NotesToDispense =10
- ENDIF
- WHILE (10NotesToDispense > 0)
- Dispense £10 note
- 10NotesTiDispense = 10NotesToDispense - 1
- END WHILE
- WHILE (20NotesToDispense > 0)
- Dispense £20 note
- 20NotesTiDispense = 20NotesToDispense - 1
- END WHILE
- IF (dispenseAmount = requiredAmount)
- Dispense £10;
- ENDIF
- ENDWHILE
- ELSE IF (requiredAmount = 100)
- requiredAmount = 5;
- dispenseAmount = 0; // allows multiply dispenses
- WHILE (dispenseAmount != requiredAmount)
- Dispense £20;
- requiredAmount = dispenseAmount + 1
- ENDWHILE
- ELSE IF (requiredAmount = 200)
- requiredAmount = 10;
- dispenseAmount = 0; // allows multiply dispenses
- WHILE (dispenseAmount != requiredAmount)
- Dispense £20;
- requiredAmount = dispenseAmount + 1
- ENDWHILE
- ENDIF
- Ejectcard
- Dispense cash;
- ENDIF
END
Note:The most difficult task. I have tried a different approach of dispensing the cash but at the end, I decided to use this simple way. Set dispenseAmount to zero -allows multiple dispenses
Task 6. Limiting PIN Attempts
a)
Variable / Description / ValuepinLimits / limiting times to enter correct pin / 3
b)
PROGRAM<AutomatedTellerMachine>
- DECLARE boolean insertCard;
- DECLARE integer pinEntered = 0;
- DECLARE integer dispenseAmount = 10 to 200;
- DECLARE integer requiredAmount = 10 to 200;
- DECLARE integer pinLimits = 3
- CONSTANT pinRequired = 1234;
- Display message “Enter pin”;
- IF insertCard
// entry pin number
- pinLimits <=3 [IJ18]
- Enter pinEntered;
- WHILE (pinEntered != pinNumber[IJ19]pinLimits <=3)
- Enter pinEntered;
- IF (pinEntered != pinNumber)
- Display message “Wrong pin”;
- pinLimits = pinLimits - 1;
- IF (pinLimits = 0)
- Retain card;
- End transaction;
- ENDIF
- END IF
- ENDWHILE
// withdrawal
- Select cash amount;
- IF (requiredAmount = 10)
- Dispense £10;
- ELSE IF (requiredAmount = 20)
- Dispense £20;
- ELSE IF (requiredAmount = 50)
- requiredAmount = 2;
- dispenseAmount = 0; // Allows multiple dispenses
- WHILE (dispenseAmount != requaredAmount)
- Dispense £20;
- dispenseAmount=dispenseAmount + 1
- IF (dispenseAmount = requiredAmount)
- Dispense £10;
- ENDIF
- ENDWHILE
- ELSE IF (requiredAmount = 100)
- requiredAmount= 5;
- dispenseAmount= 0; // allows multiply dispenses
- WHILE (dispenseAmount != requiredAmount)
- Dispense £20;
- requiredAmount= dispenseAmount + 1
- ENDWHILE
- ELSE IF (requiredAmount = 200)
- requiredAmount=10;
- dispenseAmount= 0; // allows multiply dispenses
- WHILE (dispenseAmount != requiredAmount)
- Dispense £20;
- requiredAmount=dispenseAmount + 1
- ENDWHILE
- ENDIF
- Ejectcard;
- Dispense cash;
- ENDIF
END
Note: I used simple countdown command to limit PIN entry attempts.
Page 1
[IJ1]This is one sub-problem eg chip and pin, proximity or mag strip reader.
[IJ2]I would think the problem would be more around how you capture user input eg touch screen, keyboard, keypad etc.
[IJ3]I would use the term “Authenticate PIN entered by user”.
[IJ4]You missed the requirement (sub-problem) for showing balance on screen
[IJ5]Not sure what you mean show the new balance?
Secondly you should make reference to calculate which notes need to be issued eg withdrawing £50, should a 50 note be used or 2 x £20 and a 1x £10
[IJ6]I would make the assumption the users are able to read English, and there for only English needs to be displayed by the system.
[IJ7]Display instruction asking user to insert card.
[IJ8]Prompt user for cash amount
[IJ9]Need to declare a value and set a value.
[IJ10] to give a result so if X = X then run if X = Y don’t.
[IJ11]You need to define the data type, eg are you wanting to use an integer or a string.
Since PIN’s can start as a zero do you think a string might be better?
[IJ12]Why do you want to set a constant, you need to query the pin for the user’s account eg Declare String pinRequired = “”
[IJ13]Set variable with PIN provided by user eg pinEntered = Pin Entered
[IJ14]Does your course material say you can run a method\process from a press of a button, or do you need a variable to take the input from the button (in which case you need a variable)
Secondly you should also state the data type eg string or integer.
[IJ15]Is this meant to symbol a constraint, why not just set it to 0?
[IJ16]As referenced above are you able to run a method based on a press of a button or do you need a change this to If (menuOption=1), and put something in line above saying menuOption = get button number selected.
[IJ17]Surely this would be 0
[IJ18]This isn’t required its defined in line 5
[IJ19]This will not work, as you get an continuous loop for invalid PIN’s as you haven’t created an END WHILE.
Better to use condition
“pinLimits <= 3”