Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8274969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:54:27+00:00 2026-06-08T07:54:27+00:00

This is my code, and i have a simple question import java.util.*; import java.io.*;

  • 0

This is my code, and i have a simple question

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

    Calendar c = Calendar.getInstance();
    c.setTime(cc.getExpiryDate());
    c.add(Calendar.YEAR, range);
    Date newDate = c.getTime();

        if (cc.getExpiryDate().compareTo(newDate) < range)
        {
            if(cc.getExpiryDate().compareTo(newDate) > range)
            {
                out.print("*");
            }
            out.print(cc.getNumber());
            out.println("\t" + sf.format(cc.getExpiryDate()));

        }
    }



}
}

output of what it should look like:

Enter report range in years ... 3
Cards expiring before 3 years from now:

561561-8 20/11/2015
045645-7 22/02/2017
456462-3 16/04/2013 *
546548-5 19/08/2016

The current year is 2012
The person enters ‘3’ as range.
so any year that is from 2012-2015 should have a ” * “. Like the output above, 2013 has a ” * “.
Can you tell what i am doing wrong in my IF statement?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:54:29+00:00Added an answer on June 8, 2026 at 7:54 am

    If you are comparing cc.getExpiryDate() with the current date + the range, you want the newDate to be:

    Calendar c = Calendar.getInstance();
    // commenting this line out because getInstance() gives us the current date already
    //    c.setTime(cc.getExpiryDate());
    c.add(Calendar.YEAR, range);
    Date newDate = c.getTime();
    

    This newDate is “range” years ahead of the current date. Now you can start comparing your cc.getExpiryDate() values:

        // expiry date is BEFORE the date + "range" years ahead
        if (cc.getExpiryDate().compareTo(newDate) < 0)
        {
            // the expiry date is AFTER or ON the current date
            if(cc.getExpiryDate().compareTo(new Date()) >= 0)
            {
                out.print("*");
            }
        }
        out.print(cc.getNumber());
        out.println("\t" + sf.format(cc.getExpiryDate()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie question, but I have this code: import java.util.*; import java.io.*; public class Welcome1
i have this simple question please. I have this part of code which sets
I have this simple code public String toString() { **Iterator it = list.iterator();** String
I'm looking at some code with this form: 1 package com.stackoverflow.java.questions; 2 import java.util.ArrayList;
A newbie question. I have the following piece of Java code: import acm.program.*; import
I have a very simple Java JTable question. I am creating this class to
I have a very simple Java code like this. I don't have any idea
Newbie Scala Question: Say I want to do this [Java code] in Scala: public
I have this simple code (for making things shorted, the important bits are probably
I have this simple code, using Joda-time. Works fine, but I have a problem.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.