Skip to main content
added 6 characters in body
Source Link
bowmore
  • 5.4k
  • 1
  • 20
  • 23
  • First and most important remark : do not use double or float to represent money. Use BigDecimal instead. And make a Money class that combines the amount with the currency. edit : it's also possible to use long or int, if you always calculate in cents, this would make a Money class even more useful, to hide away that implementation detail.
  • Think about rounding and precision. How many fractional digits can an annual rate have, how many can a monthly rate have...? How will you round if needed?
  • Don't hard code the values of the rates. If there's anything banks like to change it is their rates. :)
  • I would find it very odd if the date of the withdrawals and deposits did not matter in calculating the interests.
  • I'm not sure how NewWithdrawl and NewDeposit are supposed to get their values, from the posted code. As is these fields don't seem to make much sense, it feels like they want to be parameters of methods yet to be defined.
  • getWithdrawl() (sic)(sic) seems to do the same sort of operation as depositdeposit(), yet the former is named as a getter method (while it isn't one) and the latter is not. Preferably they'd be named consistently.
  • First and most important remark : do not use double or float to represent money. Use BigDecimal instead. And make a Money class that combines the amount with the currency. edit : it's also possible to use long or int, if you always calculate in cents, this would make a Money class even more useful, to hide away that implementation detail.
  • Think about rounding and precision. How many fractional digits can an annual rate have, how many can a monthly rate have...? How will you round if needed?
  • Don't hard code the values of the rates. If there's anything banks like to change it is their rates. :)
  • I would find it very odd if the date of the withdrawals and deposits did not matter in calculating the interests.
  • I'm not sure how NewWithdrawl and NewDeposit are supposed to get their values, from the posted code. As is these fields don't seem to make much sense, it feels like they want to be parameters of methods yet to be defined.
  • getWithdrawl() (sic) seems to do the same sort of operation as deposit, yet the former is named as a getter method (while it isn't one) and the latter is not. Preferably they'd be named consistently.
  • First and most important remark : do not use double or float to represent money. Use BigDecimal instead. And make a Money class that combines the amount with the currency. edit : it's also possible to use long or int, if you always calculate in cents, this would make a Money class even more useful, to hide away that implementation detail.
  • Think about rounding and precision. How many fractional digits can an annual rate have, how many can a monthly rate have...? How will you round if needed?
  • Don't hard code the values of the rates. If there's anything banks like to change it is their rates. :)
  • I would find it very odd if the date of the withdrawals and deposits did not matter in calculating the interests.
  • I'm not sure how NewWithdrawl and NewDeposit are supposed to get their values, from the posted code. As is these fields don't seem to make much sense, it feels like they want to be parameters of methods yet to be defined.
  • getWithdrawl() (sic) seems to do the same sort of operation as deposit(), yet the former is named as a getter method (while it isn't one) and the latter is not. Preferably they'd be named consistently.
Source Link
bowmore
  • 5.4k
  • 1
  • 20
  • 23

  • First and most important remark : do not use double or float to represent money. Use BigDecimal instead. And make a Money class that combines the amount with the currency. edit : it's also possible to use long or int, if you always calculate in cents, this would make a Money class even more useful, to hide away that implementation detail.
  • Think about rounding and precision. How many fractional digits can an annual rate have, how many can a monthly rate have...? How will you round if needed?
  • Don't hard code the values of the rates. If there's anything banks like to change it is their rates. :)
  • I would find it very odd if the date of the withdrawals and deposits did not matter in calculating the interests.
  • I'm not sure how NewWithdrawl and NewDeposit are supposed to get their values, from the posted code. As is these fields don't seem to make much sense, it feels like they want to be parameters of methods yet to be defined.
  • getWithdrawl() (sic) seems to do the same sort of operation as deposit, yet the former is named as a getter method (while it isn't one) and the latter is not. Preferably they'd be named consistently.