@@ -26,7 +26,7 @@ public void display() {
2626}
2727
2828public class Donations {
29- public static int getMonths (Date start , Date end ){
29+ public static int getMonths (Date start , Date end ) {
3030 Calendar startCal = new GregorianCalendar ();
3131 startCal .setTime (start );
3232 Calendar endCal = new GregorianCalendar ();
@@ -42,52 +42,50 @@ public static void main(String[] args) {
4242 Scanner sc = new Scanner (System .in );
4343 Donor donors [] = new Donor [3 ];
4444
45- try {
45+ try {
4646 SimpleDateFormat sdf = new SimpleDateFormat ("dd/MM/yyyy" );
4747 donors [0 ] = new Donor ("Anuradha" , "2172" , "O+ve" , sdf .parse ("13/09/2018" ), 21 );
48- donors [1 ] = new Donor ("Uday" , "2012" , "AB+ve" ,sdf .parse ("12/05/2018" ), 21 );
48+ donors [1 ] = new Donor ("Uday" , "2012" , "AB+ve" , sdf .parse ("12/05/2018" ), 21 );
4949 donors [2 ] = new Donor ("Kaviya" , "0888" , "A+ve" , sdf .parse ("12/04/2018" ), 21 );
50- }catch (ParseException e ){
50+ } catch (ParseException e ) {
5151 System .out .println (e );
5252 }
5353
5454 String filename = "donations.txt" ;
55- try {
55+ try {
5656 FileOutputStream fos = new FileOutputStream (filename );
5757 ObjectOutputStream oos = new ObjectOutputStream (fos );
5858
5959 oos .writeObject (donors );
6060 oos .close ();
6161 fos .close ();
62- }catch (FileNotFoundException e ){
62+ } catch (FileNotFoundException e ) {
6363 System .out .println (e );
64- }catch (IOException e ){
64+ } catch (IOException e ) {
6565 System .out .println (e );
6666 }
6767
68- try {
68+ try {
6969 FileInputStream fis = new FileInputStream (filename );
7070 ObjectInputStream ois = new ObjectInputStream (fis );
7171
72- Donor [] savedDonors = (Donor [])ois .readObject ();
72+ Donor [] savedDonors = (Donor []) ois .readObject ();
7373
7474 fis .close ();
7575 ois .close ();
7676
7777 System .out .println ("Donors with A+ve and Last date of Donation > 6mths: " );
78- for (Donor d : savedDonors ) {
79- if (getMonths (d .dold ,new Date ()) > 6 && d .bgroup .equals ("A+ve" ))
78+ for (Donor d : savedDonors ) {
79+ if (getMonths (d .dold , new Date ()) > 6 && d .bgroup .equals ("A+ve" ))
8080 d .display ();
8181 }
82- }catch (FileNotFoundException e ){
82+ } catch (FileNotFoundException e ) {
8383 System .out .println (e );
84- }catch (IOException e ){
84+ } catch (IOException e ) {
8585 System .out .println (e );
8686 } catch (ClassNotFoundException e ) {
8787 e .printStackTrace ();
8888 }
8989
90-
91-
9290 }
9391}
0 commit comments