//My Extend Student class
public class ExtendStudent {
//data members
private String name;
private String email;
//constructor
public ExtendStudent(String StudentName, String StudentEmail){
name = StudentName;
email = StudentEmail;
}
//method
public String getName(){
return name;
}
public String getEmail(){
return email;
}
}
//My Extend Library Card class
public class ExtendLibraryCard {
//data members
private ExtendStudent owner;
private int numBorBooks;
private String expDate;
private int expDay;
private int expMonth;
private int expYear;
private boolean active;
private int thisYear;
private int thisMonth;
private int thisDay;
//constructor
public ExtendLibraryCard() {
numBorBooks = 0;
expDate = null;
expMonth = 0;
expYear = 0;
setActive(true);
}
//methods
//set the owner be the student
public void setOwner(ExtendStudent student) {
owner = student;
}
//get the name of the owner (which is the student)
public String getOwnerName() {
return owner.getName();
}
//get the email of the owner
public String getOwnerEmail(){
return owner.getEmail();
}
//number of books borrowed
public void totalBooksBorrowed(int totalBooks) {
numBorBooks = numBorBooks + totalBooks;
}
//get number of books borrowed
public int getNumBorBooks() {
return numBorBooks;
}
//print out
public String toStringExpDate() {
return "Expiration Date: " + expDay + "/" + expMonth + "/" + expYear;
}
//expiration date
public void setExpDate(int expDay, int expMonth, int expYear) {
this.expDay = expDay;
this.expMonth = expMonth;
this.expYear = expYear;
}
public int getExpMonth() {
return expMonth;
}
public void setExpMonth(int expMonth) {
this.expMonth = expMonth;
}
public int getExpYear() {
return expYear;
}
public void setExpYear(int expYear) {
this.expYear = expYear;
}
public int getExpDay() {
return expDay;
}
public void setExpDay(int expDay) {
this.expDay = expDay;
}
//set active
public void setActive(boolean state) {
active = state;
}
//getter and setter of the current time
public int getThisYear() {
return thisYear;
}
public void setThisYear(int thisYear) {
this.thisYear = thisYear;
}
public int getThisMonth() {
return thisMonth;
}
public void setThisMonth(int thisMonth) {
this.thisMonth = thisMonth;
}
public int getThisDay() {
return thisDay;
}
public void setThisDay(int thisDay) {
this.thisDay = thisDay;
}
public void testing(){
if(active = false)
System.out.println("Your card is out of date. Please buy a new one or you will not be allowed to enter the library!");
else
System.out.println(toString());
}
//print out every single info to the card
public String toString(){
return "Owner Name: " + getOwnerName() + "\n" +
"Owner Email: " +getOwnerEmail() + "\n" +
"Number of books borrowed: " + getNumBorBooks() + "\n" +
"Today: " + getThisDay() + "/" + getThisMonth() + "/" + getThisYear() + "\n" +
toStringExpDate();
}
}
//My Extend Librarian
public class ExtendLibrarian {
public static void main(String[] args) {
ExtendStudent student = new ExtendStudent("SKT Faker", "fakerskt@yahoo.com");
ExtendLibraryCard card = new ExtendLibraryCard();
card.setOwner(student);
card.getOwnerName();
card.totalBooksBorrowed(20);
card.setExpDate(20, 11, 2019);
card.setThisDay(10);
card.setThisMonth(11);
card.setThisYear(2019);
if (card.getThisYear() > card.getExpYear()) {
card.setActive(false);
} else if (card.getThisYear() == card.getExpYear()) {
if (card.getThisMonth() > card.getExpMonth()) {
card.setActive(false);
}
} else if (card.getThisYear() == card.getExpYear()) {
if (card.getThisMonth() == card.getExpMonth()) {
if (card.getThisDay() > card.getExpDay()) {
card.setActive(false);
}
}
}
else {
card.setActive(true);
}
card.testing();
}
}
So the thing is let just say my expiration day is Nov 20th 2019, and if today is Nov 21st 2019, the code will print out "Your card is out of date", but then it's not. Can somebody help me please, thank you.
P/s: Sorry if my English is terrible