-1

need some help here with the Date type.

I'm managing a CreditCard class with the following parameters

public class CreditCard extends Card{
Date monthlyFee;
double amount2pay;
public CreditCard(StandardAccount yourAssociatedBankAccount,Date monthlyFeeDay) {
    super(yourAssociatedBankAccount);
    monthlyFee=monthlyFeeDay;
    cardType="Credit Card";
}

when the CreditCard is created, I have to set the MonthlyFeeDay (which is for instance "today + 30 days").

The following function has to create the CreditCard

   public void createCreditCard(StandardAccount anAccount){
    Date today= new Date();
    Card newCard= new CreditCard(anAccount,today);
    anAccount.addCard(newCard);
    cardsList.add(newCard);
}

The fact is, I don't know how to increment the variable "today" by 30 days. I don't know how to set the day of the next month. Any hint?

someCoder
  • 185
  • 3
  • 15

1 Answers1

1

You can use Calendar for this.

Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_MONTH, 30);
Date date =  c.getTime();
m4tt
  • 102
  • 4