Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Mridul Gupta
2,144 PointsCalendar Class in java?
I was unable to implement the calendar class in my code.
This is my Main method
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.set(2015, 9, 8);
cal2.set(2016, 9, 7);
FixedDeposit account = new FixedDeposit("SBI", "12345", cal1, cal2, 100000, 120000);
System.out.println(account.toString());
This is some part of my FixedDeposit Class
public class FixedDeposit implements Bank {
private String mBankName;
private String mAccountNumber;
private Calendar mDateOfCreation;
private Calendar mDateOfMaturity;
private Integer mDepositAmount;
private Integer mMaturityAmount;
public FixedDeposit(String bankName, String accountNumber, Calendar dateOfCreation, Calendar dateOfMaturity, int depositAmount, int maturityAmount) {
mBankName = bankName;
mAccountNumber = accountNumber;
mDateOfCreation = dateOfCreation;
mDateOfMaturity = dateOfMaturity;
mDepositAmount = depositAmount;
mMaturityAmount = maturityAmount;
}
@Override
public String getDateOfCreation() {
return mDateOfCreation.YEAR + "/" + mDateOfCreation.MONTH + "/" + mDateOfCreation.DATE;
}
@Override
public String getDateOfMaturity() {
return mDateOfMaturity.YEAR + "/" + mDateOfMaturity.MONTH + "/" + mDateOfMaturity.DATE;
}
@Override
public String toString() {
return "Your Fixed Deposit in \"" + mBankName + "\" was created on " + getDateOfCreation() + " of Rs. " + mDepositAmount + " and you will get Rs. " +
mMaturityAmount + " on " + getDateOfMaturity();
}
}
I am getting this Output -
Your Fixed Deposit in "SBI" was created on 1/2/5 of Rs. 100000 and you will get Rs. 120000 on 1/2/5
As you see i am not getting the right date as i gave in input. Please Help out. Or give any other ideas to improve the code.
1 Answer
Christopher Augg
21,223 PointsMridul,
You can read this website for a good example (the second example down the page) of how you can use the Calendar class. It should be enough for you to fix your code.
Regards,
Chris