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);
    }  
}

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)?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.