I am trying to do a sort of and expiry date so that when an account is created about 3 months later I'll be informed so that the account can be renewed. I don't know how I can do this and to tell you the truth I never used the calander. I tried to do something but certainly I need help. After entering the dates I am parsing them in a calander format but I don't know if it is useless.Then I tried to do an expiry method but to tell you the truth I don't have an idea how to do it correctly. The following is my code till now. Can someone pls help me? Thanks a lot.
import java.io.*; // required for handling the IOExceptions
import java.util.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.text.*;
class Transactions
{
// create an empty list to hold Cars
ArrayList<GymUser> UserListIn = new ArrayList<GymUser>();
public Transactions (ArrayList<GymUser> Tran)
{
UserListIn = Tran;
}
static void addTransaction(ArrayList<User> UserListIn)
{
String tempMemberShipID;
String tempName;
String tempSurname;
String tempAge;
String tempAddress;
String tempPhone;
String tempDuration;
String tempFrom;
String tempTo;
String tempTypeOfMembership;
String longDate;
int date;
int month;
int year;
int hour;
int minute;
Scanner keyboard = new Scanner(System.in);
keyboard.useDelimiter("\n");
System.out.println("Please enter the member's Personal Details to process Transaction");
System.out.println("----------------------------------------------------------------- ");
System.out.println("Enter the membership number");
tempMemberShipID = keyboard.next();
System.out.print("Enter Name: ");
tempName = keyboard.next();
System.out.print("Enter Surname:");
tempSurname = keyboard.next();
System.out.print("Enter Address:");
tempAddress = keyboard.next();
System.out.print("Enter Age:");
tempAge = keyboard.next();
System.out.print("Enter Phone:");
tempPhone = keyboard.next();
System.out.print("Type of membership:");
tempTypeOfMembership = keyboard.next();
System.out.print("Membership Duration:");
tempDuration = keyboard.next();
System.out.print("From(YYYY-MM-dd): ");
tempFrom = keyboard.next();
//parsing date
Date newDate;
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
System.out.print(" " + tempFrom + " parses as ");
try {
newDate = formatter.parse(tempFrom);
System.out.println(newDate + ".");
} catch (ParseException e) {
System.out.println("Unparseable using " + formatter + ".");
}
System.out.print("To(DD/MM/YYYY): ");
tempTo = keyboard.next();
//parsing date
Date EndDate;
SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd");
System.out.print(" " + tempTo + " parses as ");
try {
EndDate = formatter2.parse(tempTo);
System.out.println(EndDate + ".");
} catch (ParseException e) {
System.out.println("Unparseable using " + formatter + ".");
}
UserListIn.add(new User(tempMemberShipID, tempName, tempSurname, tempAddress, tempPhone, tempAge,tempTypeOfMembership,tempDuration,tempFrom,tempTo));
}
static void Expiry()
{
Calendar calExpired = Calendar.getInstance();
calExpired.add(Calendar.MONTH, -3);
Date EndDate = null; //get it from your db or log file...
Calendar cal_lastlogin = Calendar.getInstance();
if(cal_lastlogin.before(calExpired))
{
System.out.println("Account to be Renewed!");
// System.out.println(item.getM_ID()+" "+item.getName()+" "+item.getSurname()+" "+item.getAddress()+" "+item.getPhone()+" "+item.getAge()+" "+item.getType()+" "+item.getDuration()+" "+item.getFrom()+" "+item.getTo());
}
}
}