@@ -26,7 +26,7 @@ public void display() {
26
26
}
27
27
28
28
public class Donations {
29
- public static int getMonths (Date start , Date end ){
29
+ public static int getMonths (Date start , Date end ) {
30
30
Calendar startCal = new GregorianCalendar ();
31
31
startCal .setTime (start );
32
32
Calendar endCal = new GregorianCalendar ();
@@ -42,52 +42,50 @@ public static void main(String[] args) {
42
42
Scanner sc = new Scanner (System .in );
43
43
Donor donors [] = new Donor [3 ];
44
44
45
- try {
45
+ try {
46
46
SimpleDateFormat sdf = new SimpleDateFormat ("dd/MM/yyyy" );
47
47
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 );
49
49
donors [2 ] = new Donor ("Kaviya" , "0888" , "A+ve" , sdf .parse ("12/04/2018" ), 21 );
50
- }catch (ParseException e ){
50
+ } catch (ParseException e ) {
51
51
System .out .println (e );
52
52
}
53
53
54
54
String filename = "donations.txt" ;
55
- try {
55
+ try {
56
56
FileOutputStream fos = new FileOutputStream (filename );
57
57
ObjectOutputStream oos = new ObjectOutputStream (fos );
58
58
59
59
oos .writeObject (donors );
60
60
oos .close ();
61
61
fos .close ();
62
- }catch (FileNotFoundException e ){
62
+ } catch (FileNotFoundException e ) {
63
63
System .out .println (e );
64
- }catch (IOException e ){
64
+ } catch (IOException e ) {
65
65
System .out .println (e );
66
66
}
67
67
68
- try {
68
+ try {
69
69
FileInputStream fis = new FileInputStream (filename );
70
70
ObjectInputStream ois = new ObjectInputStream (fis );
71
71
72
- Donor [] savedDonors = (Donor [])ois .readObject ();
72
+ Donor [] savedDonors = (Donor []) ois .readObject ();
73
73
74
74
fis .close ();
75
75
ois .close ();
76
76
77
77
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" ))
80
80
d .display ();
81
81
}
82
- }catch (FileNotFoundException e ){
82
+ } catch (FileNotFoundException e ) {
83
83
System .out .println (e );
84
- }catch (IOException e ){
84
+ } catch (IOException e ) {
85
85
System .out .println (e );
86
86
} catch (ClassNotFoundException e ) {
87
87
e .printStackTrace ();
88
88
}
89
89
90
-
91
-
92
90
}
93
91
}
0 commit comments