sriramv
February 28th, 2000, 04:46 AM
Hi,
I am trying to generate the market dates(Using Calendar class) and computing the next market date and store each of these in an array.I dont understand why but it always stores the latest value.
Example java Test 02/03/2000
The output should be
array[0]=02/04/2000
array[1]=02/05/2000
array[2]=02/06/2000
But i get
array[0]=02/06/2000
array[1]=02/07/2000
array[2]=02/08/2000
I am not sure if i have overlooked something.
Here is the code.
import java.util.*;
class sprint{
private Calendar qt;
sprint(Calendar qt1){
qt=qt1;
}
String tString(){
String temp=qt.get(Calendar.YEAR) + "/"
+ (qt.get(Calendar.MONTH)) + "/"
+ qt.get(Calendar.DAY_OF_MONTH);
return(temp);
}
}
public class Test{
public static Calendar getnextdate(Calendar _quote_date){
int day_of_week=_quote_date.get((Calendar.DAY_OF_WEEK));
int month = _quote_date.get((Calendar.MONTH));
int day_of_month= _quote_date.get(Calendar.DAY_OF_MONTH);
int year=_quote_date.get((Calendar.YEAR));
_quote_date.roll(Calendar.DAY_OF_MONTH,1);
return(_quote_date);
}
public static void main(String args[]){
Calendar next_market_date= Calendar.getInstance();
/**
* Accepts month,day and year in one String and converts into integer.
*/
int first=args[0].indexOf("/");
int last= args[0].lastIndexOf("/");
int month=new Integer(args[0].substring(0,first)).intValue();
int day_of_month = new Integer(args[0].substring(first+1,last)).intValue();
int year=new Integer(args[0].substring(last+1,args[0].length())).intValue();
next_market_date.set(year,month,day_of_month);
sprint sp[]= new sprint[3];
for(int i=0;i<3;i++){
next_market_date= Test.getnextdate( next_market_date);
sp[i]= new sprint(next_market_date);
}
for(int i=0;i<3;i++)
System.out.println(sp[i].tString());
}
}
I am trying to generate the market dates(Using Calendar class) and computing the next market date and store each of these in an array.I dont understand why but it always stores the latest value.
Example java Test 02/03/2000
The output should be
array[0]=02/04/2000
array[1]=02/05/2000
array[2]=02/06/2000
But i get
array[0]=02/06/2000
array[1]=02/07/2000
array[2]=02/08/2000
I am not sure if i have overlooked something.
Here is the code.
import java.util.*;
class sprint{
private Calendar qt;
sprint(Calendar qt1){
qt=qt1;
}
String tString(){
String temp=qt.get(Calendar.YEAR) + "/"
+ (qt.get(Calendar.MONTH)) + "/"
+ qt.get(Calendar.DAY_OF_MONTH);
return(temp);
}
}
public class Test{
public static Calendar getnextdate(Calendar _quote_date){
int day_of_week=_quote_date.get((Calendar.DAY_OF_WEEK));
int month = _quote_date.get((Calendar.MONTH));
int day_of_month= _quote_date.get(Calendar.DAY_OF_MONTH);
int year=_quote_date.get((Calendar.YEAR));
_quote_date.roll(Calendar.DAY_OF_MONTH,1);
return(_quote_date);
}
public static void main(String args[]){
Calendar next_market_date= Calendar.getInstance();
/**
* Accepts month,day and year in one String and converts into integer.
*/
int first=args[0].indexOf("/");
int last= args[0].lastIndexOf("/");
int month=new Integer(args[0].substring(0,first)).intValue();
int day_of_month = new Integer(args[0].substring(first+1,last)).intValue();
int year=new Integer(args[0].substring(last+1,args[0].length())).intValue();
next_market_date.set(year,month,day_of_month);
sprint sp[]= new sprint[3];
for(int i=0;i<3;i++){
next_market_date= Test.getnextdate( next_market_date);
sp[i]= new sprint(next_market_date);
}
for(int i=0;i<3;i++)
System.out.println(sp[i].tString());
}
}