I am having an issue with my code not displaying the correct or desired output. Here is my code that I wrote up.
import java.time.LocalDateTime;
public class DriversLicense
{
private String name;
private int id;
private int expYear;
private int expMonth;
private int expDay;
public DriversLicense(String name, int id, int expYear, int expMonth, int expDay)
{
this.name = name;
this.id = id;
this.expYear = expYear;
this.expMonth = expMonth;
this.expDay = expDay;
}
public boolean isExpired()
{
LocalDateTime date = LocalDateTime.now();
boolean tORf = false;
int year = date.getYear();
int month = date.getMonthValue();
int day = date.getDayOfMonth();
if(year > this.expYear && month > this.expMonth && day > this.expDay)
{
return true;
}
return tORf;
}
public void displayInfo()
{
System.out.println("Name: " + this.name);
System.out.println("ID: " + this.id);
System.out.println("Expiration: " + this.expYear + "/" + this.expMonth + "/" + this.expDay);
}
}
In my isExpired() method it is supposed to check weather the current date is later than the expiration date of an ID. And if the ID is expired it should print out true, else it should print out false. For some reason I am getting all false when it should be false true false for the three ids my program checks. Here is my test file below.
public class TestDL
{
public static void main(String[] args)
{
DriversLicense dr1 = new DriversLicense("John Smith", 192891, 6, 21, 2018);
dr1.displayInfo();
System.out.println("Expired? " + dr1.isExpired());
System.out.println();
DriversLicense dr2 = new DriversLicense("Jennifer Brown", 728828, 5, 31, 2017);
dr2.displayInfo();
System.out.println("Expired? " + dr2.isExpired());
System.out.println();
DriversLicense dr3 = new DriversLicense("Britney Wilson", 592031, 7, 15, 2019);
dr3.displayInfo();
System.out.println("Expired? " + dr3.isExpired());
System.out.println();
}
}
Also here is the output I am currently getting.
Name: John Smith
ID: 192891
Expiration: 6/21/2018
Expired? false
Name: Jennifer Brown
ID: 728828
Expiration: 5/31/2017
Expired? false
Name: Britney Wilson
ID: 592031
Expiration: 7/15/2019
Expired? false