java - Code not executing after true "if" statement -


i working on making bank account holds account information.

each account gets 3 free withdrawals each month, $1 being charged every transaction after first 3 free. have conditional deals charging customers $3 every transaction after 3 free ones, isn't working right.

public static double gettfee(int accountnumber) {     if (transactioncount[accountnumber] >= 4) {         return 1;     } else {         return 0;     } 

the function returns 1 every account has 4 or more transactions, doesn't provide right balance in "tester" class. i.e. if account made 5 deposits of $1 each, should have $3 since last 2 being charged. tester class doesn't deduct $1 after 4th transaction, returning balance of $4 previous scenario. here tester class:

system.out.println("please enter account number.");             checkingaccount.setaccountnumber(scanner.nextint());             (int j = 0; j < size; j++) {             if (bankaccount[j] == checkingaccount.getaccountnumber()) {                     system.out.println("please enter amount desire deposit.: ");                     checkingaccount.setamount(double.parsedouble(scanner.next()));                     amount[j] = amount[j] + checkingaccount.getamount();                     checkingaccount.transaction(checkingaccount.getaccountnumber());                     value = checkingaccount.checktfee(checkingaccount.getaccountnumber());                     system.out.println("your balance is: $" + (amount[j] - checkingaccount.gettfee(value)));                 } else if (bankaccount[j] != checkingaccount.getaccountnumber()) {              } 

the test class runs, problem not conditional in tester class. must gettfee function. please me. thank you

you shouldn't returning 1 every time call gettfee, code work you:

public static double gettfee(int accountnumber) {     if (transactioncount[accountnumber] >= 4) {         return transactioncount[accountnumber] - 3;     } else {         return 0;     } 

to explain things, gettfee should return 0 if account has done 3 transactions or less, when account done 4 or more, subtract 3 free transactions total transactions , return fee (every transaction costs 1$ there's no need multiply result 1)


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -