I know it is sloppy or most likely not done correct, i’m not very good at this but i’m still trying. I have been able to assign each numbered button to display its corresponding number but when it comes to creating the functions for the (balance, deposit, withdraw, clear, and enter) buttons I can not seem to find the right way to form it. Any help would be much appreciated. I’ve asked my professor for help on this and I haven’t gotten a response back, so you guys are my last hope of finally understanding this.
// Global variables
boolean enterClicked, balanceClicked, depositClicked, withdrawClicked, clearClicked;
String[] bLabel = {"0","1","2","3","4","5","6","7","8","9","Balance","Deposit","Withdraw","Clear","Enter"};
int[] bX = {145,50,145,240,50,145,240,50,145,240,365,365,365,365,125},
bY = {275,25,25,25,95,95,95,165,165,165,25,95,165,275,375},
bW = {75,75,75,75,75,75,75,75,75,75,100,100,100,100,115},
bH = {50,50,50,50,50,50,50,50,50,50,50,50,50,50,50};
int bID,
prevOp;
float acc, num, total, balance, withdraw;
// setp()
void setup(){
size(500,500);
total = 0;
num = bID;
withdraw = 0;
balance = bID + bID;
enterClicked = false;
balanceClicked = false;
depositClicked = false;
withdrawClicked = false;
clearClicked = false;
}
// draw()
void draw(){
for (int i=0; i<15; 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<15; 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:
println(bID);
break;
case 10:
balanceClicked = true;
total = num;
println("Balance",total);
break;
// Balance Button
case 11:
depositClicked = true;
num = total + bID;
println(num,"has been deposited");
break;
// Deposit Button
case 12:
withdrawClicked = true;
withdraw = total - bID;
println(withdraw,"has been withdrawn");
break;
// Withdraw Button
case 13:
if(!clearClicked)
clearClicked = true;
println("");
break;
// Clear Button
case 14: // Enter Button
println(num);
}}
}