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>

  1. Insert card;[IJ7]
  2. Request pin from user
  3. Enter pin;
  4. Query database and very PIN is correct
  5. Select cash amount;[IJ8]
  6. Verify cash amount (are you sure you want X amount)
  7. Eject card;
  8. Dispense cash;

END

Task 2. Start-up

PROGRAM<AutomatedTellerMachine>

  1. DECLARE boolean insertCard = false;[IJ9]
  2. Display message “Enter pin”;
  3. IF[IJ10]insertCard = true
  4. Enter pin;
  5. Select cash amount;
  6. Eject card;
  7. Dispense cash;
  8. 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 / Value
pinRequired / Pin stored in the card / 1234
pinEntered[IJ11] / Does pin entered matches pin on card / 0

b)

PROGRAM<AutomatedTellerMachine>

  1. DECLARE boolean insertCard;
  2. DECLARE integer pinEntered=0;
  3. CONSTANT pinRequired = 1234; [IJ12]
  4. pinRequired = Get user PIN from database
  5. Display message “Enter pin”;
  6. IF insertCard

// entry pin number

  1. Enter pinEntered;[IJ13]
  2. WHILE (pinEntered != pinRequired)
  3. Display message “Wrong pin”;
  4. Re-enter pin;
  5. pinEntered = New PIN entered by user
  6. ENDWHILE
  7. Select cash amount;
  8. Eject card;
  9. Dispense cash;
  10. 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 / Value
dispenseAmount / Amount of cash to be dispense / £10-£200
menuOption / Withdraw or View Balance / 1 OR 2[IJ14]

b)

PROGRAM<AutomatedTellerMachine>

  1. DECLARE boolean insertCard;
  2. DECLARE integer pinEntered=0;
  3. DECLARE integer dispenseAmount = 10 to 200;[IJ15]
  4. CONSTANT pinRequired = 1234; //
  5. Display message “Enter pin”;
  6. IF insertCard

// entry pin number

  1. Enter pinEntered;
  2. WHILE (pinEntered != pinNumber)
  3. Display message “Wrong pin”;
  4. Re-enter pin;
  5. ENDWHILE
  6. IF (buttonOne is pressed[IJ16])
  7. Check balance;
  8. ENDIF
  9. IF (buttonTwo is pressed)
  10. Withdraw cash;

// withdrawal

  1. Select cash amount;
  2. IF (buttonThree is pressed)
  3. dispenseAmount = £10;
  4. ENDIF
  5. IF (buttonFour is pressed)
  6. dispenseAmount = £20;
  7. ENDIF
  8. IF (buttonFive is pressed)
  9. dispenseAmount = £50;
  10. ENDIF
  11. IF (buttonSix is pressed)
  12. dispenceAmount = £100;
  13. ENDIF
  14. IF (buttonSeven is pressed)
  15. dispenseAmount = £200;
  16. ENDIF
  17. Ejectcard;
  18. Dispense cash;
  19. ENDIF

END

Note: Simple command that shows Menu choices and amount of cash to be dispense.

Task 5. Dispencing Cash

a)

Variable / Description / Value
requiredAmount / 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>

  1. DECLARE boolean insertCard;
  2. DECLARE integer pinEntered=0;
  3. DECLARE integer dispenseAmount = 10 to 200;[IJ17]
  4. DECLARE integer requiredAmount = 10 to 200;
  5. Declare 10NotesToDispense = 0
  6. Declare 20NotesToDispense = 0
  7. CONSTANT pinRequired = 1234;
  8. Display message “Enter pin”;
  9. IF insertCard

// entry pin number

  1. Enter pinEntered;
  2. WHILE (pinEntered != pinRequired)
  3. Display message “Wrong pin”;
  4. Re-enter pin;
  5. ENDWHILE

// withdrawal

  1. Select cash amount;
  2. IF (requiredAmount = 10)
  3. dispenseAmount = (1 x £10);
  4. 10NotesToDispense = 1
  5. ELSE IF (requiredAmount = 20)
  6. dispenseAmount = (1 x £20);
  7. 20NotesToDispense = 1
  8. ELSE IF (requiredAmount = 50)
  9. dispenseAmount = (2 x £20) and (1 x £10);
  10. 10NotesToDispense = 1
  11. 20NotesToDispense = 2
  12. ELSE IF (requiredAmount = 100)
  13. dispenceAmount = (5 x £20);
  14. 20NotesToDispense =5
  15. ELSE IF (requiredAmount = 200)
  16. dispenseAmount = (10 x £20);
  17. 20NotesToDispense =10
  18. ENDIF
  19. Eject card;
  20. Dispense cash using the number of notes number defined in 20NotesToDispense and 10NotesToDispense.
  21. 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>

  1. DECLARE boolean insertCard;
  2. DECLARE integer pinEntered = 0;
  3. DECLARE integer requiredAmount = 10 to 200;
  4. Declare 10NotesToDispense = 0
  5. Declare 20NotesToDispense = 0
  6. CONSTANT pinRequired = 1234;
  7. Display message “Enter pin”;
  8. IF insertCard

// entry pin number

  1. Enter pinEntered;
  2. WHILE (pinEntered != pinNumber)
  3. Display message “Wrong pin”;
  4. Re-enter pin;
  5. ENDWHILE

// withdrawal

  1. Select cash amount;
  2. IF (requiredAmount = 10)
  3. dispenseAmount = (1 x £10);
  4. 10NotesToDispense = 1
  5. ELSE IF (requiredAmount = 20)
  6. dispenseAmount = (1 x £20);
  7. 20NotesToDispense = 1
  8. ELSE IF (requiredAmount = 50)
  9. dispenseAmount = (2 x £20) and (1 x £10);
  10. 10NotesToDispense = 1
  11. 20NotesToDispense = 2
  12. ELSE IF (requiredAmount = 100)
  13. dispenceAmount = (5 x £20);
  14. 20NotesToDispense =5
  15. ELSE IF (requiredAmount = 200)
  16. dispenseAmount = (10 x £20);
  17. 20NotesToDispense =10
  18. ENDIF
  19. WHILE (10NotesToDispense > 0)
  20. Dispense £10 note
  21. 10NotesTiDispense = 10NotesToDispense - 1
  22. END WHILE
  23. WHILE (20NotesToDispense > 0)
  24. Dispense £20 note
  25. 20NotesTiDispense = 20NotesToDispense - 1
  26. END WHILE
  27. IF (dispenseAmount = requiredAmount)
  28. Dispense £10;
  29. ENDIF
  30. ENDWHILE
  31. ELSE IF (requiredAmount = 100)
  32. requiredAmount = 5;
  33. dispenseAmount = 0; // allows multiply dispenses
  34. WHILE (dispenseAmount != requiredAmount)
  35. Dispense £20;
  36. requiredAmount = dispenseAmount + 1
  37. ENDWHILE
  38. ELSE IF (requiredAmount = 200)
  39. requiredAmount = 10;
  40. dispenseAmount = 0; // allows multiply dispenses
  41. WHILE (dispenseAmount != requiredAmount)
  42. Dispense £20;
  43. requiredAmount = dispenseAmount + 1
  44. ENDWHILE
  45. ENDIF
  46. Ejectcard
  47. Dispense cash;
  48. 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 / Value
pinLimits / limiting times to enter correct pin / 3

b)

PROGRAM<AutomatedTellerMachine>

  1. DECLARE boolean insertCard;
  2. DECLARE integer pinEntered = 0;
  3. DECLARE integer dispenseAmount = 10 to 200;
  4. DECLARE integer requiredAmount = 10 to 200;
  5. DECLARE integer pinLimits = 3
  6. CONSTANT pinRequired = 1234;
  7. Display message “Enter pin”;
  8. IF insertCard

// entry pin number

  1. pinLimits <=3 [IJ18]
  2. Enter pinEntered;
  3. WHILE (pinEntered != pinNumber[IJ19]pinLimits <=3)
  4. Enter pinEntered;
  5. IF (pinEntered != pinNumber)
  6. Display message “Wrong pin”;
  7. pinLimits = pinLimits - 1;
  8. IF (pinLimits = 0)
  9. Retain card;
  10. End transaction;
  11. ENDIF
  12. END IF
  13. ENDWHILE

// withdrawal

  1. Select cash amount;
  2. IF (requiredAmount = 10)
  3. Dispense £10;
  4. ELSE IF (requiredAmount = 20)
  5. Dispense £20;
  6. ELSE IF (requiredAmount = 50)
  7. requiredAmount = 2;
  8. dispenseAmount = 0; // Allows multiple dispenses
  9. WHILE (dispenseAmount != requaredAmount)
  10. Dispense £20;
  11. dispenseAmount=dispenseAmount + 1
  12. IF (dispenseAmount = requiredAmount)
  13. Dispense £10;
  14. ENDIF
  15. ENDWHILE
  16. ELSE IF (requiredAmount = 100)
  17. requiredAmount= 5;
  18. dispenseAmount= 0; // allows multiply dispenses
  19. WHILE (dispenseAmount != requiredAmount)
  20. Dispense £20;
  21. requiredAmount= dispenseAmount + 1
  22. ENDWHILE
  23. ELSE IF (requiredAmount = 200)
  24. requiredAmount=10;
  25. dispenseAmount= 0; // allows multiply dispenses
  26. WHILE (dispenseAmount != requiredAmount)
  27. Dispense £20;
  28. requiredAmount=dispenseAmount + 1
  29. ENDWHILE
  30. ENDIF
  31. Ejectcard;
  32. Dispense cash;
  33. 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”