Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BankomatModelImpletation
- package at.fhb.iti.algodat.ue2.bankomat.model;
- import at.fhb.iti.algodat.ue2.bankomat.grafics.BankomatView;
- import java.nio.channels.CancelledKeyException;
- import static at.fhb.iti.algodat.ue2.bankomat.model.BankomatState.*;
- public class BankomatModelImplementation implements BankomatModel {
- private BankomatView theView;
- private BankomatState theState;
- private BankomatState from;
- private BankomatState to;
- private int CorrectCode = 1234;
- private int IntDigit = 0;
- private int Money = 0;
- public void setView(BankomatView view) {
- theView = view;
- theState = START;
- }
- public void pressButtonDigit(int digit) {
- from = theState;
- switch (theState) {
- case ONEDIGIT:
- to = TWODIGIT;
- IntDigit = digit;
- theView.setText(" * ");
- System.out.println("Edge 5 from " + from + " to " + to + " via DIGIT");
- theState = to;
- break;
- case TWODIGIT:
- to = THREEDIGIT;
- IntDigit = IntDigit * 10 + digit;
- theView.setText(" * * ");
- System.out.println("Edge 8 from " + from + " to " + to + " via DIGIT");
- theState = to;
- break;
- case THREEDIGIT:
- to = FOURDIGIT;
- IntDigit = IntDigit * 10 + digit;
- theView.setText(" * * * ");
- System.out.println("Edge 11 from " + from + " to " + to + " via DIGIT");
- theState = to;
- break;
- case FOURDIGIT:
- to = CONTROLDIGIT;
- IntDigit = IntDigit * 10 + digit;
- theView.setText(" * * * * Please press Enter");
- System.out.println("Edge 14 from " + from + " to " + to + " via DIGIT");
- theState = to;
- break;
- case CHOOSEMONEY:
- Money = Money * 10 + digit;
- theState = to;
- System.out.println("Edge 18 from " + from + " to " + to + " via DIGIT");
- theView.setText("" + Money);
- default:
- break;
- }
- }
- public void pressButtonCancel() {
- from = theState;
- switch (theState) {
- case ONEDIGIT:
- cancelMethode();
- System.out.println("Edge 3 from " + from + " to " + to + " via CANCEL");
- break;
- case TWODIGIT:
- cancelMethode();
- System.out.println("Edge 6 from " + from + " to " + to + " via CANCEL");
- break;
- case THREEDIGIT:
- cancelMethode();
- System.out.println("Edge 9 from " + from + " to " + to + " via CANCEL");
- break;
- case FOURDIGIT:
- cancelMethode();
- System.out.println("Edge 12 from " + from + " to " + to + " via CANCEL");
- break;
- case CONTROLDIGIT:
- cancelMethode();
- System.out.println("Edge 15 from " + from + " to " + to + " via CANCEL");
- break;
- case CHOOSEMONEY:
- cancelMethode();
- System.out.println("Edge 21 from " + from + " to " + to + " via CANCEL");
- break;
- default:
- break;
- }
- }
- private void cancelMethode() {
- to = CANCELCARD;
- theView.setText("Cancel pressed.");
- theView.setKartenButtonLabel("Take out card.");
- theState = to;
- }
- public void pressButtonDelete() {
- from = theState;
- switch (theState) {
- case TWODIGIT:
- to = ONEDIGIT;
- IntDigit = IntDigit / 10;
- theView.setText(" Please enter your code: ");
- System.out.println("Edge 4 from " + from + " to " + to + " via DELETE");
- theState = to;
- break;
- case THREEDIGIT:
- to = TWODIGIT;
- IntDigit = IntDigit / 10;
- theView.setText(" * ");
- System.out.println("Edge 7 from " + from + " to " + to + " via DELETE");
- theState = to;
- break;
- case FOURDIGIT:
- to = THREEDIGIT;
- IntDigit = IntDigit / 10;
- theView.setText(" * * ");
- System.out.println("Edge 10 from " + from + " to " + to + " via DELETE");
- theState = to;
- break;
- case CONTROLDIGIT:
- to = FOURDIGIT;
- IntDigit = IntDigit / 10;
- theView.setText(" * * * ");
- System.out.println("Edge 13 from " + from + " to " + to + " via DELETE");
- theState = to;
- break;
- case CHOOSEMONEY:
- //to = CHOOSEMONEY;
- Money = Money / 10;
- System.out.println("Edge 19 from " + from + " to " + to + " via DELETE");
- //theState = to;
- theView.setText("" + Money);
- break;
- default:
- break;
- }
- }
- public void pressButtonEnter() {
- from = theState;
- switch (theState) {
- case CONTROLDIGIT:
- if (IntDigit == CorrectCode)
- {
- to = CHOOSEMONEY;
- theView.setText("Choose your money amount");
- System.out.println("Edge 17 from " + from + " to " + to + " via ENTER");
- }
- else
- {
- to = CANCELCARD;
- theView.setText("Wrong Code");
- theView.setKartenButtonLabel(" Take out card ");
- theView.setKartenText(" Please remove card ");
- System.out.println("Edge 16 from " + from + " to " + to + " via ENTER");
- }
- theState = to;
- break;
- case CHOOSEMONEY:
- if (Money > 0)
- {
- to = SUCCESSCARD;
- System.out.println("Edge 20 from " + from + " to " + to + " via ENTER");
- //theView.setText("Valid entry. Please wait ... ");
- theView.setText("Process was successful");
- theView.setKartenButtonLabel("Take out card");
- theView.setKartenText("Please remove card");
- theState = to;
- }
- else
- {
- theView.setText("Invalid Input! Please try again.");
- }
- break;
- default:
- break;
- }
- }
- public void pressButtonMoney() {
- from = theState;
- switch (theState) {
- case GETMONEY:
- to = START;
- theView.setText("Welcome to the ATM!");
- //theView.setText("You have receive "+ Money + "€ . Please take your Money");
- theView.setGeldladeText(" ");
- System.out.println("Edge 23 from " + from + " to " + to + " via MONEY");
- theState = to;
- break;
- default:
- break;
- }
- }
- public void pressButtonCard() {
- from = theState;
- switch (theState) {
- case START:
- to = ONEDIGIT;
- theView.setText("Please enter code");
- theView.setKartenButtonLabel("Card in progress");
- theView.setKartenText("Your Card is entered");
- System.out.println("Edge 1 from " + from + " to " + to + " via CARD");
- theState = to;
- break;
- case CANCELCARD:
- to = START;
- theView.setText("Welcome to ATM!");
- theView.setKartenButtonLabel(" Insert card ");
- theView.setKartenText("Please insert card.");
- System.out.println("Edge 2 from " + from + " to " + to + " via CARD");
- theState = to;
- break;
- case SUCCESSCARD:
- to = GETMONEY;
- theView.setText("Money amount: " + Money + ". ");
- theView.setKartenButtonLabel(" Insert Card ");
- theView.setGeldladeText("€" + Money );
- theView.setKartenText("Card slot is empty");
- System.out.println("Edge 22 from " + from + " to " + to + " via CARD");
- theState = to;
- default:
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement