There is a field for entering numbers, as well as the mWithdrawButton button, which minus the values from 0 and the mDepositButton button, which adds values. All this is displayed in mAmountDisplay .
I would like to add the ability to display a finite number in the number of bills, for example, we made 475, in mAmountDisplay shows that our balance is 475, and then: 4 x 100; 1 X 50; 1 X 20; 1 x 5. Tell me how best to register.
public class MainActivity extends Activity { private static final String TAG = "MainActivity"; EditText mAmountInput; Button mWithdrawButton; Button mDepositButton; TextView mAmountDisplay; BankAccount mCurrentAccount; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mCurrentAccount = new SavingsAccount(); mAmountInput = (EditText)findViewById(R.id.amount_input); mWithdrawButton = (Button)findViewById(R.id.withdraw_button); mDepositButton = (Button)findViewById(R.id.deposit_button); mAmountDisplay = (TextView)findViewById(R.id.balance_display); mWithdrawButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String amount = mAmountInput.getText().toString(); mCurrentAccount.withdraw(Double.parseDouble(amount)); mAmountDisplay.setText("Balance is " + mCurrentAccount.getBalance()); } }); mDepositButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String amount = mAmountInput.getText().toString(); mCurrentAccount.deposit(Double.parseDouble(amount)); mAmountDisplay.setText("Balance is " + mCurrentAccount.getBalance()); } }); } public abstract class BankAccount { private ArrayList<Double> mTransactions; public static final double OVERDRAFT_FEE = 30; BankAccount(){ mTransactions = new ArrayList<Double>(); } public void withdraw(double amount){ mTransactions.add(-amount); if (getBalance() < 0) { mTransactions.add(-OVERDRAFT_FEE); } } protected int numberOfWithdrawals(){ int count = 0; for (int i = 0; i < mTransactions.size(); i++) { if(mTransactions.get(i) < 0) { count++; } } return count; } public void deposit(double amount){ mTransactions.add(amount); } public double getBalance(){ double total = 0; for(int i = 0; i < mTransactions.size(); i++){ total += mTransactions.get(i); } return total; } } public class SavingsAccount extends BankAccount { private static final String TAG = "SavingsAccount"; @Override public void withdraw(double amount) { if(numberOfWithdrawals() >= 3){ return; } super.withdraw(amount); } }
Doubletype - are you also using kopecks? - pavlofff