ATM machine project help

I was wondering if anyone could help me remove the features of this code for a calculator I made and make it into an ATM. I’m having difficulty adjusting the code so it doesn’t display in such an odd way on the bottom of the window. I cant seem to remove or adjust anything without the whole thing crashing on me or not working. Any help would be useful. Thanks.

// Global variables

String[] bLabel = {"0","1","2","3","4","5","6","7","8","9",".","+","-","*","/","=","C"};
int[]  bX       = { 70, 20, 70,120, 20, 70,120, 20, 70,120,170,170,205,170,205,205,170},
       bY       = {150, 30, 30, 30, 70, 70, 70,110,110,110,140, 70, 70,105,105,140, 30},
       bW       = { 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 30, 30, 30, 30, 30, 30, 65},
       bH       = { 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, 30, 30, 30, 30, 30, 30, 35};
int bID,
    prevOp;
float acc, num, div;
boolean decimalClicked;

// setp()
void setup(){
  size(260,200);
  acc = 0;
  num = 0;
  decimalClicked = false;
  div = 1;
  prevOp = -1;
}

// draw()
void draw(){
  for (int i=0; i<17; i++){
    fill(255);
    rect(bX[i],bY[i],bW[i],bH[i]);
    fill(0);
    textAlign(CENTER,CENTER);
    textSize(20);
    text(bLabel[i],bX[i]+bW[i]/2,bY[i]+bH[i]/2);
  }
}

// Functions

void mousePressed(){
  bID = -1;
  for(int i=0; i<17; i++){
    if((mouseX >= bX[i])&(mouseX <= bX[i]+bW[i])&
       (mouseY >= bY[i])&(mouseY <= bY[i]+bH[i]))
       bID = i;
  }
  if(bID != -1){
    //println(bLabel[bID]);
    switch(bID){
      case 0:
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
      case 7:
      case 8:
      case 9:
        if(!decimalClicked) 
          num = num*10 + bID;
        else {
          div = 10 * div;
          num = num + bID / div;
        }
        break;
      case 10: // Decimal point
        decimalClicked = true;
        println("Decimal");
        break;
      case 11: // +
      case 12: // -
      case 13: // *
      case 14: // /
         prevOp = bID;
         acc = num;
         num = 0;
        break;
      case 15: // =
        switch(prevOp){
          case -1:
            acc = num;
            break;
          case 11: // +
            acc = acc + num;
            break;
          case 12: // -
            acc = acc - num;
            break;
          case 13: // *
            acc = acc * num;
            break;
          case 14: // /
            acc = acc / num;
            break;
          }
        num = 0;
        break;
      case 16: // Clear
        break;
      default:
    }
    println(acc, num);
  }
}

An ATM has different functionality that a calculator. Usually there is a screen that helps you conduct transactions, such as inquiries, withdrawal, or deposits. The number pad to enter your PIN number is just one aspect of it.

You really need to provide us with some more details about what your end goal is.

1 Like
// Global variables

String[] bLabel = {"0","1","2","3","4","5","6","7","8","9","Balance","Deposit","Withdraw","Clear"};
int[]  bX       = {145,50,145,240,50,145,240,50,145,240,365,365,365,365},
       bY       = {275,25,25,25,95,95,95,165,165,165,25,95,165,275},
       bW       = {75,75,75,75,75,75,75,75,75,75,100,100,100,100},
       bH       = {50,50,50,50,50,50,50,50,50,50,50,50,50,50};
int bID,
    prevOp;

// setp()
void setup(){
  size(500,500);
}

// draw()
void draw(){
  for (int i=0; i<14; i++){
    fill(255);
    rect(bX[i],bY[i],bW[i],bH[i]);
    fill(0);
    textAlign(CENTER,CENTER);
    textSize(20);
    text(bLabel[i],bX[i]+bW[i]/2,bY[i]+bH[i]/2);
  }
}

// Functions

void mousePressed(){
  bID = -1;
  for(int i=0; i<14; i++){
    if((mouseX >= bX[i])&(mouseX <= bX[i]+bW[i])&
       (mouseY >= bY[i])&(mouseY <= bY[i]+bH[i]))
       bID = i;
  }
}

So I have this so far which is the key pad and the other buttons. Im trying to make it so each button is able to display the corresponding number when pressed. Also I am trying to be able to create a kind of memory bank just like a real ATM where it knows how much money you have so every time i hit deposit or withdraw it gets stored somewhere. My apologizes if this doesn’t make any sense im not very good at this stuff.

This is a fine UI. What your sketch is lacking now is some sort of logic that handles doing transactions.

For example, let’s say I want to withdraw some money. So I hit the withdraw button, right? So the ATM needs to go into some sort of withdrawal mode. What happens next? Do I need to put in my PIN? Account number? Amount I want withdrawn? How do I know this?

You need another box that displays a message to the user, telling them what to do next. You might also consider adding an “Enter” button, to submit a value via the numpad.

1 Like

ATM Machine…
Automatic Teller Machine Machine…
Redundant? Maybe…