Skip to content

Commit a060bac

Browse files
committed
Merge branch 'neha-practice' of https://github.com/code4tomorrow/java into neha-practice
2 parents deea919 + 434ea82 commit a060bac

File tree

14 files changed

+603
-0
lines changed

14 files changed

+603
-0
lines changed
Binary file not shown.
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
35
2+
94
3+
16
4+
38
5+
82
6+
87
7+
52
8+
60
9+
86
10+
59
11+
72
12+
7
13+
60
14+
56
15+
63
16+
11
17+
67
18+
77
19+
67
20+
82
21+
28
22+
13
23+
100
24+
92
25+
85
26+
69
27+
75
28+
6
29+
83
30+
100
31+
76
32+
51
33+
13
34+
84
35+
59
36+
30
37+
21
38+
72
39+
15
40+
28
41+
15
42+
95
43+
87
44+
61
45+
80
46+
22
47+
45
48+
9
49+
73
50+
85
51+
85
52+
2
53+
90
54+
75
55+
60
56+
80
57+
91
58+
21
59+
80
60+
41
61+
82
62+
27
63+
48
64+
43
65+
37
66+
52
67+
78
68+
21
69+
54
70+
20
71+
15
72+
49
73+
42
74+
89
75+
63
76+
24
77+
10
78+
62
79+
44
80+
63
81+
51
82+
34
83+
36
84+
21
85+
2
86+
49
87+
64
88+
77
89+
34
90+
80
91+
7
92+
83
93+
51
94+
46
95+
11
96+
25
97+
59
98+
96
99+
21
100+
65
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
35
2+
94
3+
16
4+
38
5+
82
6+
87
7+
52
8+
60
9+
86
10+
59
11+
72
12+
7
13+
60
14+
56
15+
63
16+
11
17+
67
18+
77
19+
67
20+
82
21+
28
22+
13
23+
100
24+
92
25+
85
26+
69
27+
75
28+
6
29+
83
30+
100
31+
76
32+
51
33+
13
34+
84
35+
59
36+
30
37+
21
38+
72
39+
15
40+
28
41+
15
42+
95
43+
87
44+
61
45+
80
46+
22
47+
45
48+
9
49+
73
50+
85
51+
85
52+
2
53+
90
54+
75
55+
60
56+
80
57+
91
58+
21
59+
80
60+
41
61+
82
62+
27
63+
48
64+
43
65+
37
66+
52
67+
78
68+
21
69+
54
70+
20
71+
15
72+
49
73+
42
74+
89
75+
63
76+
24
77+
10
78+
62
79+
44
80+
63
81+
51
82+
34
83+
36
84+
21
85+
2
86+
49
87+
64
88+
77
89+
34
90+
80
91+
7
92+
83
93+
51
94+
46
95+
11
96+
25
97+
59
98+
96
99+
21
100+
65
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.codefortomorrow.advanced.chapter14.practice;
2+
3+
import java.io.*;
4+
5+
/*
6+
The file “numbers.txt” has 100 random numbers
7+
(one on each line). Use file i/o to find the
8+
average of these numbers. Write “Average: ”
9+
and display the average on the next (101st)
10+
line of the file.
11+
12+
Hint: Just like BufferedReader and FileReader,
13+
there are BufferedWriter and FileWriter classes
14+
that allow you to add full words to files,
15+
instead of just bytes. You should do a quick
16+
Google search to explore these classes first,
17+
but just to get you started:
18+
19+
new FileWriter(“fileName.txt”, true)
20+
21+
will create an instance of FileWriter, and
22+
the “true” puts it in append mode, so you
23+
start writing to the end of the file instead
24+
of writing over the existing content from the beginning.
25+
*/
26+
27+
public class Average {
28+
29+
public static void main(String[] args) {
30+
// Add code here.
31+
}
32+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.codefortomorrow.advanced.chapter14.practice;
2+
3+
/*
4+
Create a class called BankAccount (a separate
5+
class from your main program) that contains a
6+
private “balance” attribute for the amount of
7+
money in the account.
8+
9+
The user should be able to set the original
10+
balance upon initialization (through the constructor).
11+
The class should have deposit and withdraw methods
12+
that add and subtract money from the account.
13+
There should also be a getter method to access
14+
the balance, since the attribute is private.
15+
16+
Create at least 2 instances of BankAccount.
17+
Deposit, withdraw, and display the final balance of each.
18+
19+
Create a NotEnoughMoneyException class that is a
20+
checked exception. The withdraw method should throw
21+
this exception if the user tries to withdraw an
22+
amount that is greater than their current balance.
23+
Handle this exception by displaying the difference
24+
between the balance and the amount to be withdrawn,
25+
and do this exception handling in the main program
26+
where you have created instances of BankAccount.
27+
*/
28+
29+
public class Bank {
30+
31+
public static void main(String[] args) {
32+
// Your code here.
33+
}
34+
}
35+
// Add other classes here.

0 commit comments

Comments
 (0)