0

so i am working on a assigment for school, and i need help with the java.util.Calendar , i am trying to increment the year of as today by one each index of an array . This functions needs to be inside a toString(). so i need some help i know i need a for loop to pass the add(calendar.YEAR, index)
here is what i have so far ..ohh yeah this class should not have a main method.

import java.util.Date;
import java.util.Calendar;
import java.text.DateFormat;
import java.text.NumberFormat;

public class RetiermentCalculator
{
    AccountInformation[] years = new AccountInformation[35];
    public RetiermentCalculator(int aYear, double aBeginIncome, double aContribution, double aReturn )
    {
        double answer = 0.0;
        double finance = (aBeginIncome + aContribution);
        double intrestMade = finance * aReturn;
        for (int index = 0; index < years.length; index ++)
        {
            answer += finance + intrestMade;
            System.out.println(answer);
        }  
    }
    @Override
    public String toString()//@override
    {
        String answer = "";
        Calendar greg = Calendar.getInstance();
        Date sometime = greg.getTime();
        DateFormat formatter = DateFormat.getDateInstance();
        for(int index = 0 ; index < years.length; index ++)
        {
            greg.add(greg.YEAR, index);
            answer = formatter.format(sometime);
        }
        return(answer);
    }  
}
2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by fonzi
0

Well, why are overwriting the value each iteration (rather than using +=), why are you formatting the same data every time (rather than using getTime, in that spot, directly), and why haven't you written a main method, yet (we are not going to do it for you)?

0

i know its not your job to do this for me, and ohh did you read the description above, is a class that should not have a main, :) just letting you know in case my description was confusing

Edited by fonzi: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.