質問編集履歴
1
進展させました
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,14 +11,16 @@
|
|
11
11
|
import java.util.Scanner;
|
12
12
|
import java.io.*;
|
13
13
|
import java.io.FileNotFoundException;
|
14
|
+
import java.io.PrintWriter;
|
14
15
|
|
15
16
|
class Account {
|
16
17
|
private float balance;
|
18
|
+
|
17
19
|
private int countDp;
|
18
20
|
private int countWd;
|
19
21
|
|
20
|
-
float[] deposit = new float[
|
22
|
+
float[] deposit = new float[10];
|
21
|
-
float[] withdrawal = new float[
|
23
|
+
float[] withdrawal = new float[10];
|
22
24
|
|
23
25
|
Scanner input = new Scanner(System.in);
|
24
26
|
|
@@ -28,11 +30,24 @@
|
|
28
30
|
countWd = 0;
|
29
31
|
}
|
30
32
|
|
33
|
+
private float[] enhanceArray(float[] array) {
|
34
|
+
float[] newArray = new float[array.length + 10];
|
35
|
+
for (int i = 0; i < array.length; i++) {
|
36
|
+
newArray[i] = array[i];
|
37
|
+
}
|
38
|
+
return newArray;
|
39
|
+
}
|
40
|
+
|
41
|
+
|
31
42
|
public float depositing() {
|
32
43
|
System.out.println("Enter the amount you would like to deposit: ");
|
33
44
|
|
34
45
|
float depositAmount = input.nextFloat();
|
35
46
|
|
47
|
+
if (countDp == deposit.length) {
|
48
|
+
deposit = enhanceArray(deposit);
|
49
|
+
}
|
50
|
+
deposit[countDp] = depositAmount;
|
36
51
|
balance += depositAmount;
|
37
52
|
|
38
53
|
countDp += 1;
|
@@ -44,34 +59,33 @@
|
|
44
59
|
|
45
60
|
float withdrawalAmount = input.nextFloat();
|
46
61
|
|
47
|
-
if (balance >= withdrawalAmount)
|
62
|
+
if (balance >= withdrawalAmount) {
|
63
|
+
if (countWd == deposit.length) {
|
64
|
+
withdrawal = enhanceArray(withdrawal);
|
65
|
+
}
|
66
|
+
withdrawal[countDp] = withdrawalAmount;
|
48
67
|
balance -= withdrawalAmount;
|
68
|
+
countWd += 1;
|
49
|
-
else {
|
69
|
+
} else {
|
50
70
|
System.out.println("Less balance, transaction failed.");
|
51
71
|
}
|
52
|
-
|
72
|
+
|
53
73
|
return balance;
|
54
74
|
}
|
55
75
|
|
56
76
|
public float balanceOfAccount() {
|
57
77
|
return balance;
|
58
78
|
}
|
59
|
-
|
79
|
+
|
60
80
|
public void outputAllDeposits() {
|
61
|
-
// while(input.hasNextFloat()) {
|
62
|
-
// deposit[countDp] = input.nextFloat();
|
63
|
-
// float line = deposit[countDp];
|
64
|
-
// countDp += 1;
|
65
|
-
// System.out.println(line);
|
66
|
-
// }
|
67
81
|
|
68
82
|
System.out.println("Outputting all your deposits:");
|
69
83
|
|
70
|
-
for (int i = 0; i <
|
84
|
+
for (int i = 0; i < countDp; i++) {
|
71
85
|
deposit[i] = input.nextFloat();
|
72
86
|
|
73
87
|
if(deposit[i] >= 0.0f) {
|
74
|
-
System.out.println(deposit[i]);
|
88
|
+
System.out.println("$" + deposit[i]);
|
75
89
|
}
|
76
90
|
}
|
77
91
|
}
|
@@ -79,11 +93,11 @@
|
|
79
93
|
public void outputAllWithdraws() {
|
80
94
|
System.out.println("Outputting all your withdrawals:");
|
81
95
|
|
82
|
-
for (int i = 0; i <
|
96
|
+
for (int i = 0; i < countWd; i++) {
|
83
97
|
withdrawal[i] = input.nextFloat();
|
84
98
|
|
85
99
|
if(withdrawal[i] >= 0.0f) {
|
86
|
-
System.out.println(withdrawal[i]);
|
100
|
+
System.out.println("$" + withdrawal[i]);
|
87
101
|
}
|
88
102
|
}
|
89
103
|
}
|
@@ -126,8 +140,10 @@
|
|
126
140
|
public static void main(String[] args) throws Exception{
|
127
141
|
int choice = 0;
|
128
142
|
Account account = new Account();
|
143
|
+
|
129
144
|
Scanner in = new Scanner(System.in);
|
130
145
|
|
146
|
+
|
131
147
|
do {
|
132
148
|
System.out.println("**************************************\n" +
|
133
149
|
"* Bank Account Program: *\n" +
|
@@ -173,5 +189,4 @@
|
|
173
189
|
account.outputToTextFile();
|
174
190
|
}
|
175
191
|
}
|
176
|
-
|
177
192
|
```
|