import java.text.;
import java.util.;
public class Joy {
public static void main(String args[]) {
print();
}
static void print() {
Variables a = new Variables();
while (true) {
Scanner date1 = new Scanner(System.in);
System.out.println("请输入起息日格式为:yyyy-MM-DD");
String vd1 = date1.next();
a.setvd(vd1);
// judgementDate(vd1);
// a.setvd(vd1);
if (judgementDate(vd1) == 1) {
continue;
}
Scanner date2 = new Scanner(System.in);
System.out.println("请输入到息日格式为:yyyy-MM-DD");
String id1 = date2.next();
a.setid(id1);
// judgementDate(id1);
if (judgementDate(id1) == 1) {
continue;
}else if (a.getvd().compareTo(id1) > 0) {
System.out.println("到息日不能小于起息日,请重新输入");
continue;
}
Scanner date3 = new Scanner(System.in);
System.out.println("开放天数");
int od1 = date3.nextInt();
a.setod(od1);
if (od1 <= 0) {
System.out.println("开放天数要大于0");
}
Scanner date4 = new Scanner(System.in);
System.out.println("开放周期");
int op1 = date4.nextInt();// final
a.setop(op1);
if (op1 <= 0) {
System.out.println("开放周期要大于0");
}
Scanner date5 = new Scanner(System.in);
System.out.println("首次开放日格式为:yyyy-MM-DD");
String fod1 = date5.next();
a.setfod(fod1);
if (judgementDate(fod1) == 1) {
continue;
}else if (a.getvd().compareTo(fod1) > 0) {
System.out.println("首次开放日必须大于起息日");
continue;
}
String ocd = a.getfod();
int op = a.getop();
String id = a.getid();
int od = a.getod();
makePlan(ocd, op, id, od);
break;
}
}
public static void makePlan(String ocd, int op, String id, int od) {
SimpleDateFormat sj = new SimpleDateFormat("yyyy-MM-dd");// 日期
Date d = null;
try {
d = sj.parse(ocd);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(d);
System.out.println("序号" + " " + "开放起始日" + " " + "开放结束日" + " "
+ "开放确认日" + " " + "净值日");
int i = 0;
while (ocd.compareTo(id) <= 0) {// 比较用的string类型
i++;// 序号
if (i > 1) {// 第一次不用加op
calendar.add(Calendar.DATE, op);
ocd = sj.format(calendar.getTime());// 格式化日期
}
if (ocd.compareTo(id) > 0) {// ocd的值改变了
break;
}
calendar.add(Calendar.DATE, -1);
String nvd = sj.format(calendar.getTime());// 淨值日
String oed = sj.format(calendar.getTime());// 开放结束日
calendar.add(Calendar.DATE, -od + 1);// 开放起始日等于开放结束日-开放天数+1
String osd = sj.format(calendar.getTime());// 开放起始日
calendar.add(Calendar.DATE, od);
System.out.println(i + " " + osd + " " + oed + " " + ocd
+ " " + nvd);
}
}
static int judgementDate(String str) {// 判断日期输入的是否合法
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");// 指定格式
int i = 0;
try {
format.setLenient(false);
format.parse(str);
// return;
} catch (ParseException e) {
i++;
System.out.println("您输入的日期格式有误!请重新输入");
}
return i;
}
}
class Variables {
private String vd;
private String id;
private int od;
private int op;
private String fod;
// private String ocd=fod;
public void setvd(String vd) {
this.vd = vd;
}
public String getvd() {
return vd;
}
public void setid(String id) {
this.id = id;
}
public String getid() {
return id;
}
public void setod(int od) {
this.od = od;
}
public int getod() {
return od;
}
public void setop(int op1) {
this.op = op1;
}
public int getop() {
return op;
}
public void setfod(String fod) {
this.fod = fod;
}
public String getfod() {
return fod;
}
}