Birthday Reminder
Birthday Reminder
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.InputMismatchException;
import java.util.Scanner;
try{
option = input.nextInt();
}catch(InputMismatchException e){
System.out.println("Invalid option selected,
Please try again\n");
mainMenu();
}
if(option == 1){
addFriend();
mainMenu();
}else if(option == 2){
checkReminders();
mainMenu();
}else if(option ==3){
brReader = new BRReader("BirthdayReminders");
brReader.readFile();
mainMenu();
}else if(option ==4){
input.close();
System.exit(0);
}else{
System.out.println("Invalid option, Please select
again");
mainMenu();
}
br = new BRWriter();
br.pushData(name,strBday,age,gender);
br.writeCsvFile("BirthdayReminders");
//current calender
//
int today = calTday.get(Calendar.DAY_OF_YEAR);
int i;
BRWriter Class:
//BRWriter writes the data into the file when you add a new friends birthday.
import java.io.FileWriter;
import java.io.IOException;
//setter function class mai bhejni hai value to ye setter use karenge
public void pushData(String _name,String _dob, String _age, String _gender){
name = _name;
dob = _dob;
age = _age;
gender = _gender;
}
//flush() writes the content of the buffer to the destination and makes the buffer empty for
further data to store but it does not closes the stream permanently.
//That means you can still write some more data to the stream.
//But close() closes the stream permanently. If you want to write some data further, then you
have to reopen the stream again and append the data with the existing ones.
} finally {
try {
fw.flush();
fw.close();
} catch (IOException e) {
System.out.println("Error while flushing/closing fileWriter
!!!");
e.printStackTrace();
}
}
}
}
BRReader Class:
//reader class
//read line while kee loop mai lagaya hai ta ke next line mai jai peche nahi
jata
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
//set method
public BRReader(String _fileName){
fileName = _fileName;
}
} finally {
if(reader != null)
reader.close();
}
}
//while loop jab tk chalta rahe ga jab line ki value null nahi hojata
try {
String line = "";
fileReader = new BufferedReader(new FileReader(fileName));
read kar raha hai par line chahye jo pheli line read tokens mai
divide kia to 0 index mai
naam betha hoga kisi ka bhi q ke line pe phela index name hai or
ye token divide com ma del se ho raha hai to
tokens mai array mai 0 pos mai naam hai then dob then gender to
mujhe srif naam chhaye token ke 0
index se naam uthaaya or name ke array mai rukh dia and then line
number increment */
lineNumber++;
}
}
}
catch (Exception e) {
System.out.println("Error in CsvFileReader !!!");
e.printStackTrace();
} finally {
try {
fileReader.close();
} catch (IOException e) {
System.out.println("Error while closing fileReader !!!");
e.printStackTrace();
}
}
return names;
}
try {
String line = "";
fileReader = new BufferedReader(new FileReader(fileName));
catch (Exception e) {
System.out.println("Error in CsvFileReader !!!");
e.printStackTrace();
} finally {
try {
fileReader.close();
} catch (IOException e) {
System.out.println("Error while closing fileReader !!!");
e.printStackTrace();
}
}
return dates;
}
//
public int[] returnDaysOfTheYear(){
BufferedReader fileReader = null;
int lineNumber = 0;
int[] daysOfTheYear = null;
try{
daysOfTheYear = new int[countLines()];
}catch(IOException e){
e.printStackTrace();
}
try {
//chahye to jo cal obj string read nahi karta to usko parse use kia jo
uske cal ke formate mai convert kardega
daysOfTheYear[lineNumber] =
cal.get(Calendar.DAY_OF_YEAR); //cal mai se jo string bethai hain mm/dd/yyyy
jo /dd value return kardega
lineNumber++;
} catch (ParseException e) {
e.printStackTrace();
}
}
}
catch (Exception e) {
System.out.println("Error in CsvFileReader !!!");
e.printStackTrace();
} finally {
try {
fileReader.close();
} catch (IOException e) {
System.out.println("Error while closing fileReader !!!");
e.printStackTrace();
}
}
return daysOfTheYear;
}
FRIEND Classes:
//use this class for readfile method
public class Friend {