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);
}
}