0

I need a little logic help as well as some code help.

I'm writing a program that is suppose to be a simple ATM program. It will do deposits Withdrawals And a balance check.

I also have to have my program record the date of every deposit, and use that date when calculating 5% interest over a year for when the user checks their balance. The part im having problems with is the part where I need to store the deposit amount as well as the date that corresponds to that deposit. I'm supposed to use the GregorianCalender methods. Im just taking a shot in the dark but I think I would use an array for this. But im clueless as to how to implement it. Because I'm new to arrays.

Just to give u an idea. I have my Main class. A menu class, and a transaction class.

1 Answers1

2

A deposit class that has an amount and a date.

import java.util.Date;

public class Deposit {
    Double amount;
    Date depositDate;
}
Rylander
  • 19,449
  • 25
  • 93
  • 144
  • @user2733862, As a side note, why do you calculate interest for each deposit? Interest is usual calculated periodically using the account balance. – Rylander Sep 23 '13 at 22:26
  • I thought that but if one amount is deposited in june and the other in july wouldnt both those amounts have accrued different interest? – user2733862 Sep 23 '13 at 22:28
  • a) a `double` instead of a `Double` b) not a `double` since money does not like floating point http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency :) – zapl Sep 23 '13 at 22:48
  • @zapl I agree, floating point is not good for currency, I prefer a "Money" class that is built on top of BigInteger however this *example* was built to work with the types mentioned in question. I usually default to using the object Double over the primitive double, why would you suggest using the primitive? – Rylander Sep 24 '13 at 16:41
  • @user2733862 possibly, it depends on how often the interest is calculated. See http://en.wikipedia.org/wiki/Compound_interest – Rylander Sep 24 '13 at 16:51
  • @MikeRylander because of a) the Object creation overhead of `Double`, `double` needs no garbage collection, less memory, is quicker overall b) `Double` can be `null`, simpler / safer code if that's not possible c) error prone in case you do things like `new Double(5) == new Double(5)`. And as long as it's not a real world ATM software I'd use `double` as well. – zapl Sep 24 '13 at 17:13