这是我的代码:
import java.util.*;
import java.io.*;
import type.lib.GlobalCredit;
import type.lib.CreditCard;
import java.text.SimpleDateFormat;
public class eCheck08A
{
public static void main(String[] args)
{
PrintStream out = System.out;
Scanner in = new Scanner(System.in);
GlobalCredit credit1 = new GlobalCredit().getRandom();
out.print("Enter report range in years ... ");
int range = in.nextInt();
out.println("Cards expiring before " + range + " year(s) from now: ");
SimpleDateFormat sf = new SimpleDateFormat("dd/MM/yyyy");
for (CreditCard cc : credit1)
{
out.print(cc.getNumber());
out.println("\t" + sf.format(cc.getExpiryDate()));
}
}
}
起初,我的应用程序要求输入 Range 年份,假设我们输入“3”。我想在低于范围号的任何年份的日期旁边放一个“*”。我假设 Java 假设日期是今天,所以是 2012 年 7 月 23 日。例如,如果我们得到 16/04/2013,我想要一个“*”旁边。但如果我们得到 23/05/2016,则不会出现“*”。
编辑:
Date endDate = new Date(2015, 12, 31);
for (CreditCard cc : credit1)
{
if (cc.getExpiryDate().compareTo(endDate) < 0)
{
if(cc.getExpiryDate().compareTo(endDate) > 0)
{
out.print("*");
}
out.print(cc.getNumber());
out.println("\t" + sf.format(cc.getExpiryDate()));
}
}
范围是