////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //PIMS: Personal Invstment Management System //Class : Alerts //This class defines two methods:- // 1. checkForAlerts: Returns an array of pending alerts. // 2. setNewAlert: Registers a new alert in its database set by the user. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import java.lang.*; import java.io.*; import java.util.*; import java.text.*; public class Alerts{ //attributes. private dataRepository DR; private int numAlerts;//Total number of alerts specified by the user. private String alertList[][];//list of alerts. Contains alert date and alert details. private boolean debug = false;//boolean variable used for debugging this class. public Alerts(dataRepository DR){ try{ this.DR = DR; //Read the alert file and initialize the alert list. alertList = DR.readAlerts(); //Count the number of alerts. while(alertList[numAlerts][0] != null){ numAlerts++; } }catch(Exception e){} } //This method compares two dates. returns true if the first date is less than equal to //the second date and false otherwise. private boolean lessThanEqual(String date1, String date2){ int day1, day2; int month1, month2; int year1, year2; StringTokenizer ST1 = new StringTokenizer(date1, "/"); StringTokenizer ST2 = new StringTokenizer(date2, "/"); //extract the day month and year for both the dates. day1 = Integer.parseInt(ST1.nextToken()); day2 = Integer.parseInt(ST2.nextToken()); month1 = Integer.parseInt(ST1.nextToken()); month2 = Integer.parseInt(ST2.nextToken()); year1 = Integer.parseInt(ST1.nextToken()); year2 = Integer.parseInt(ST2.nextToken()); //compare the dates. if(year1 < year2)return(true); if(year1 > year2)return(false); if(month1 < month2)return(true); if(month1 > month2)return(false); if(day1 < day2)return(true); if(day1 > day2)return(false); return(true);//the dates are equal. } //debugging method for printing. public void printArray(String array[][], int n){ for(int i=0;i