idk ive done too much

This commit is contained in:
2022-12-11 21:40:09 -06:00
parent 9a1bc9cfb5
commit 4ee4e7551a
59 changed files with 3553 additions and 13 deletions

15
LAB-7/.classpath Normal file
View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

17
LAB-7/.project Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>LAB-7</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

6
LAB-7/input1.txt Normal file
View File

@@ -0,0 +1,6 @@
6bw61YK7Bb [debits] 16 18 5 11 17 11 14 3 18 [debits] [uses] 13 19 14 16 2 [uses] [uses] 45.45 6.26 44.69 2.14 99.95 92.35 1.19 57.93 15.15 [uses] [returns] 17 16 0 14 8 3 [returns] [uses] 19 13 18 8 5 0 13 [uses]
H04GP8Y7DC returns 54.27 17.42 returns [debits] 7 10 14 [debits] income 60.29 96.40 7.21 16.78 37.25 income [debits] 59.23 32.09 [debits]
i51ZGQQ6g1 debits 16 17 3 12 0 6 9 debits debits 52.39 76.86 60.14 debits returns 13 12 15 17 0 returns income 64.74 11.76 41.06 income
dF6aW1--51 [debits] 19.19 5.33 91.10 [debits] [uses] 19 12 14 [uses] [returns] 82.80 17.24 [returns] interactions 17 18 3 7 19 interactions interactions 0 19 3 interactions [debits] 58.49 39.84 19.72 28.69 1.23 [debits]
XmqY743pr3

16
LAB-7/input2.txt Normal file
View File

@@ -0,0 +1,16 @@
20#Tg0=OI6 [returns] 17 12 10 [returns] [uses] 1 8 [uses] [returns] 28.09 78.25 95.84 28.33 71.12 [returns] returns 2 3 14 0 4 16 15 1 returns
68WTt10AZ5 [uses] 19 17 [uses] interactions 14 16 20 16 6 11 interactions income 45.90 71.70 98.27 80.55 31.32 income debits 16 8 17 2 8 5 3 4 debits
bm3D679n+m [returns] 39.60 96.77 64.52 64.80 70.38 46.81 84.05 67.88 6.05 [returns] uses 12 9 3 14 19 18 9 0 uses [interactions] 2 12 20 19 18 15 [interactions]
9Yns4a9i5N returns 29.72 43.74 33.53 90.60 97.37 68.43 20.10 16.12 returns debits 3 6 15 16 11 7 debits returns 10 12 13 2 9 5 12 20 9 returns [income] 23.31 63.03 [income] interactions 7 7 11 20 14 1 interactions [uses] 18 0 11 0 15 5 2 [uses]
B407e5PDY0 returns 19 7 returns [returns] 24.21 85.33 44.85 45.20 43.83 40.31 10.30 98.19 [returns]
+9fA2h3U2l
aI8Ci9%18Z [debits] 21.23 59.68 19.85 49.44 14.94 45.33 10.34 22.56 [debits] income 13.09 83.16 75.74 51.15 22.35 91.03 28.40 income [returns] 4 20 14 3 6 15 [returns] [debits] 11.90 45.59 3.79 [debits] [debits] 42.29 15.47 84.80 88.71 41.90 [debits]
lvex52d110 [debits] 9 2 15 [debits] uses 74.82 82.98 96.95 81.61 14.77 82.69 24.71 35.64 uses [debits] 17.24 26.26 69.61 [debits] uses 48.97 0.95 uses
*xNr77h034 [debits] 4 5 0 [debits] [uses] 35.31 74.41 2.07 25.82 71.44 59.72 [uses] [uses] 11 20 19 10 12 12 0 3 17 [uses] [debits] 14.95 43.99 45.81 5.83 23.06 38.07 74.73 67.58 [debits] [uses] 66.46 16.19 69.98 57.36 4.92 [uses] returns 2 15 3 6 0 11 10 8 returns
63Yl72Adc4 [uses] 16 1 6 18 6 7 3 0 [uses] debits 5 13 2 3 19 18 debits [debits] 59.62 95.24 26.35 52.61 34.09 0.62 9.89 6.27 16.72 [debits]
1RHq52U783 returns 13.84 38.47 45.59 returns [uses] 11 13 18 6 18 [uses] returns 14 5 9 20 3 6 15 returns [income] 94.34 29.13 81.69 11.17 5.08 [income] [interactions] 7 14 5 0 [interactions] income 7.61 65.28 90.56 93.72 30.26 97.32 income interactions 10 0 17 17 interactions income 49.38 54.20 16.61 55.75 15.72 5.13 income
&m5876nKD( [debits] 19 4 9 2 3 6 8 0 [debits] [interactions] 7 2 5 [interactions] [uses] 38.14 39.76 [uses]
q5Uj)2U65@ income 57.93 41.45 income [interactions] 10 3 14 2 20 [interactions] [uses] 20 10 [uses] [returns] 60.25 69.45 40.95 60.48 34.32 15.74 59.19 55.31 [returns] [returns] 19 13 17 4 [returns]
p4C@NX9422 uses 65.43 4.42 92.60 12.60 9.53 uses [debits] 20 3 7 15 20 10 5 14 18 [debits] [returns] 83.67 44.87 99.39 15.32 48.07 99.70 11.94 [returns] interactions 0 16 14 interactions [income] 25.97 84.72 [income] returns 7.40 30.59 16.74 88.92 35.97 82.14 8.95 28.36 22.55 returns
87W&66tt3q [interactions] 17 2 7 13 14 0 9 17 16 [interactions] uses 81.77 5.85 23.60 34.94 15.47 98.74 36.53 uses uses 19 4 9 16 4 13 uses

36
LAB-7/input3.txt Normal file
View File

@@ -0,0 +1,36 @@
0XlfA2Y21E [uses] 57.36 34.06 11.94 14.16 44.70 [uses] [debits] 71.66 12.84 14.25 57.75 56.44 71.61 33.24 15.48 [debits] [debits] 24.57 69.94 7.41 20.79 37.59 15.42 89.77 [debits] income 7.96 80.78 40.30 48.29 53.87 11.06 21.47 income
o80ve2yJ69 returns 6 14 12 7 2 8 3 returns [uses] 29.97 63.24 65.37 48.71 91.12 [uses] [uses] 2 4 20 4 4 0 6 16 11 [uses] [uses] 15 14 11 [uses] [debits] 52.68 78.95 63.40 16.51 72.03 97.23 60.62 14.71 16.55 [debits] uses 8 2 13 19 1 1 16 16 8 uses
1wu5Rn5NF2 returns 23.24 48.99 12.59 returns uses 4 18 6 7 17 20 uses income 49.85 71.12 78.30 38.38 89.51 38.23 56.34 income returns 44.81 11.03 9.34 26.97 95.95 27.14 returns debits 92.86 95.33 68.83 82.44 93.17 37.82 debits
23G1A210OF [debits] 15 15 15 13 12 2 [debits] income 97.30 0.59 94.92 35.63 16.31 income [interactions] 17 19 [interactions] debits 1 9 11 14 0 debits
xaj321J1BZ [debits] 8 14 [debits] [interactions] 6 18 18 7 8 [interactions]
Cr731Iii7I uses 87.86 63.43 70.21 87.20 88.97 60.50 76.81 18.42 uses uses 63.46 2.73 28.35 69.03 79.83 77.51 94.53 90.63 uses income 66.90 46.29 75.62 73.55 51.54 70.89 80.18 22.05 income [interactions] 13 2 20 9 0 19 [interactions] income 92.67 35.00 38.26 income income 20.75 22.31 38.63 66.89 74.26 10.71 income income 22.71 80.35 35.42 30.18 50.24 13.31 53.84 income
6E3Fxj85yL returns 13 0 18 19 14 13 1 8 5 returns income 24.32 87.86 97.25 22.70 7.06 4.57 19.79 23.68 income interactions 9 15 19 16 interactions
wYs18i9m5k returns 3 11 6 2 returns [uses] 13 19 3 [uses] [interactions] 16 13 5 18 [interactions]
W8ANj6np26 [debits] 7 10 1 13 2 [debits] uses 72.59 17.42 81.22 17.96 93.96 95.85 63.51 75.19 98.87 uses [interactions] 7 12 17 20 2 10 [interactions] [income] 60.40 58.78 [income] interactions 1 14 15 14 20 1 interactions
b8W01cT5n8 interactions 0 16 4 3 interactions [income] 83.50 41.60 23.05 24.06 25.83 92.62 71.87 [income]
338bJ687YD debits 10 12 8 5 2 4 17 9 2 debits
8ft4ChT823 returns 15 14 returns [income] 7.81 95.19 16.07 91.16 89.42 24.06 [income] [income] 48.93 94.64 27.08 [income] [interactions] 8 0 5 8 19 13 12 15 [interactions]
i01&50ftN2 [uses] 1.20 2.67 [uses] [uses] 39.26 69.03 3.11 69.90 68.50 40.17 [uses] [interactions] 14 3 7 1 20 4 [interactions] [returns] 80.99 5.63 42.85 38.10 2.76 65.67 37.36 [returns] [uses] 83.26 69.03 [uses]
ocn2E9U02m [debits] 22.62 90.71 19.97 51.49 13.68 86.25 [debits] [uses] 26.53 78.68 46.65 [uses] [returns] 99.72 86.32 5.30 58.42 5.05 12.69 62.03 7.23 [returns] debits 20 11 18 1 0 8 10 9 11 debits
At90OL089h [returns] 19 19 8 4 8 0 2 7 16 [returns] [uses] 59.72 97.33 8.67 [uses] [uses] 19 10 16 11 9 [uses] income 22.74 97.53 income returns 1 12 7 17 1 2 15 3 returns returns 18 5 6 9 18 3 15 10 4 returns returns 5 10 4 8 7 returns
eo0n0Z62wq [uses] 3 5 11 1 14 1 11 19 13 [uses] [uses] 14 10 [uses] income 25.97 25.06 58.94 18.99 69.62 4.73 26.77 income [income] 26.69 92.09 12.96 27.95 72.97 [income] returns 11 11 3 20 5 12 13 3 3 returns
6sVk7528rZ [returns] 16 20 13 8 7 15 [returns] [interactions] 3 13 10 17 15 [interactions] [income] 20.17 48.83 97.01 [income] [debits] 55.54 57.08 [debits] [income] 1.45 69.59 60.61 41.25 74.95 65.20 77.76 64.14 86.07 [income]
O@2C3Y5Oe6 [debits] 80.98 74.85 83.88 25.76 33.65 31.69 93.79 91.78 38.96 [debits] [debits] 15 14 9 0 [debits] uses 13.61 51.04 29.17 6.43 uses
99L0MmmK60 [returns] 36.56 98.19 72.40 47.40 16.82 58.52 7.37 33.99 11.17 [returns] returns 91.67 76.87 67.45 26.60 91.27 94.31 60.00 3.24 58.90 returns [returns] 94.99 2.55 79.16 [returns]
M5N$p8C823 income 30.79 33.35 88.69 income [interactions] 12 15 [interactions]
8r80725tqY debits 4 11 14 0 debits returns 4 2 19 returns [uses] 8 6 2 6 9 0 20 20 [uses] [interactions] 20 2 11 [interactions] income 11.96 51.60 12.41 31.54 46.24 52.49 96.30 3.58 income
Qb7gA5M10H [uses] 5 0 3 20 16 0 7 2 6 [uses] debits 52.74 39.02 67.73 95.93 debits
0Y-o506P%b [uses] 6.01 89.11 76.96 88.11 74.98 27.75 2.27 [uses] [interactions] 1 3 16 6 3 [interactions]
9Lc160L30C uses 1 10 12 12 6 10 2 14 uses [interactions] 17 13 11 18 12 8 20 16 [interactions] income 62.32 89.46 62.95 49.40 42.38 78.53 income [uses] 1 4 10 6 7 4 18 [uses]
E%q847=v2d [returns] 47.88 76.44 50.37 45.13 [returns]
23L9Jgx7yt returns 92.18 68.29 18.09 returns uses 14 17 11 18 14 15 8 0 uses returns 0 11 returns
BH51tz93s5 [uses] 7 7 9 7 [uses] returns 15.34 63.27 71.81 3.52 23.05 12.82 52.33 returns [interactions] 7 6 2 3 7 [interactions] income 4.03 67.32 87.56 65.24 22.91 income [uses] 10 18 20 17 8 1 13 8 [uses]
f71O-^D5k9 interactions 13 18 2 interactions income 42.37 89.94 75.14 12.04 income [returns] 6.50 80.41 69.37 35.66 [returns] [debits] 61.39 47.20 28.31 15.98 30.56 81.34 89.15 9.94 [debits]
o4bbw3q524 uses 10 13 11 4 15 11 1 uses returns 19 18 15 0 20 14 8 11 16 returns interactions 16 10 17 14 5 4 17 interactions interactions 10 11 9 4 2 interactions
x60iC7015a [uses] 16 0 [uses] returns 31.19 2.89 44.83 20.84 44.40 65.63 returns debits 10 15 18 debits [interactions] 4 17 18 18 15 19 [interactions] income 98.69 68.25 17.93 28.21 53.36 8.78 75.31 34.99 income [income] 39.25 12.78 64.77 14.10 74.76 27.78 [income] debits 12 7 11 3 17 debits
578q3cOi4L uses 9 9 15 16 uses debits 99.02 5.76 14.89 69.11 80.06 2.97 19.95 91.74 debits [debits] 17 7 [debits] income 43.22 81.33 94.52 88.67 32.87 63.32 income [interactions] 3 6 5 15 0 6 20 18 [interactions] income 85.06 66.61 22.98 77.44 income
t8W7R&45s3 [debits] 11 17 [debits] income 6.35 30.91 22.44 29.06 53.71 49.69 87.38 23.27 35.04 income interactions 0 12 11 17 17 18 interactions [uses] 40.87 87.47 47.98 28.70 32.46 65.56 41.49 96.47 68.70 [uses]
53h2xKa8P1 [debits] 9 13 0 0 [debits] returns 52.56 50.71 94.78 32.58 returns returns 67.72 37.34 44.23 33.35 returns [uses] 15 8 12 15 2 9 [uses]
9=4(L4kF8b uses 10 5 18 15 1 6 15 9 16 uses returns 8.39 15.71 99.57 returns [returns] 18 10 20 12 [returns] [debits] 9 0 9 2 17 4 9 4 [debits] debits 18 12 4 3 7 debits
12TGf5$u)3 [uses] 19.01 21.42 7.07 33.85 2.58 86.49 68.91 [uses] debits 18 2 debits [income] 74.02 8.65 [income]

5
LAB-7/output1.txt Normal file
View File

@@ -0,0 +1,5 @@
6bw61YK7Bb .00
H04GP8Y7DC 217.93
i51ZGQQ6g1 117.56
dF6aW1--51 .00
XmqY743pr3 .00

5
LAB-7/output1Cost.txt Normal file
View File

@@ -0,0 +1,5 @@
6bw61YK7Bb 0
H04GP8Y7DC 217.93
i51ZGQQ6g1 117.56
dF6aW1--51 0
XmqY743pr3 0

View File

@@ -0,0 +1,5 @@
6bw61YK7Bb 0
H04GP8Y7DC 0
i51ZGQQ6g1 0
dF6aW1--51 12
XmqY743pr3 0

5
LAB-7/output1Valid.txt Normal file
View File

@@ -0,0 +1,5 @@
6bw61YK7Bb true
H04GP8Y7DC true
i51ZGQQ6g1 true
dF6aW1--51 false
XmqY743pr3 true

15
LAB-7/output2.txt Normal file
View File

@@ -0,0 +1,15 @@
20#Tg0=OI6 .00
68WTt10AZ5 327.74
bm3D679n+m .00
9Yns4a9i5N 86.34
B407e5PDY0 .00
+9fA2h3U2l .00
aI8Ci9%18Z 364.92
lvex52d110 .00
*xNr77h034 .00
63Yl72Adc4 .00
1RHq52U783 221.41
&m5876nKD( .00
q5Uj)2U65@ 99.38
p4C@NX9422 110.69
87W&66tt3q .00

15
LAB-7/output2Cost.txt Normal file
View File

@@ -0,0 +1,15 @@
20#Tg0=OI6 0
68WTt10AZ5 327.74
bm3D679n+m 0
9Yns4a9i5N 86.34
B407e5PDY0 0
+9fA2h3U2l 0
aI8Ci9%18Z 364.92
lvex52d110 0
*xNr77h034 0
63Yl72Adc4 0
1RHq52U783 221.41
&m5876nKD( 0
q5Uj)2U65@ 99.38
p4C@NX9422 110.69
87W&66tt3q 0

View File

@@ -0,0 +1,15 @@
20#Tg0=OI6 0
68WTt10AZ5 13
bm3D679n+m 14
9Yns4a9i5N 10
B407e5PDY0 0
+9fA2h3U2l 0
aI8Ci9%18Z 0
lvex52d110 0
*xNr77h034 0
63Yl72Adc4 0
1RHq52U783 6
&m5876nKD( 4
q5Uj)2U65@ 9
p4C@NX9422 10
87W&66tt3q 10

15
LAB-7/output2Valid.txt Normal file
View File

@@ -0,0 +1,15 @@
20#Tg0=OI6 false
68WTt10AZ5 false
bm3D679n+m false
9Yns4a9i5N true
B407e5PDY0 false
+9fA2h3U2l false
aI8Ci9%18Z false
lvex52d110 false
*xNr77h034 false
63Yl72Adc4 false
1RHq52U783 false
&m5876nKD( false
q5Uj)2U65@ false
p4C@NX9422 false
87W&66tt3q false

35
LAB-7/output3.txt Normal file
View File

@@ -0,0 +1,35 @@
0XlfA2Y21E 263.73
o80ve2yJ69 .00
1wu5Rn5NF2 421.73
23G1A210OF 244.75
xaj321J1BZ .00
Cr731Iii7I 487.02
6E3Fxj85yL 287.23
wYs18i9m5k .00
W8ANj6np26 119.18
b8W01cT5n8 362.53
338bJ687YD .00
8ft4ChT823 323.71
i01&50ftN2 .00
ocn2E9U02m .00
At90OL089h 120.27
eo0n0Z62wq 230.08
6sVk7528rZ 166.01
O@2C3Y5Oe6 .00
99L0MmmK60 .00
M5N$p8C823 152.83
8r80725tqY 306.12
Qb7gA5M10H .00
0Y-o506P%b .00
9Lc160L30C 385.04
E%q847=v2d .00
23L9Jgx7yt .00
BH51tz93s5 247.06
f71O-^D5k9 219.49
o4bbw3q524 .00
x60iC7015a 385.52
578q3cOi4L 403.93
t8W7R&45s3 337.85
53h2xKa8P1 .00
9=4(L4kF8b .00
12TGf5$u)3 82.67

35
LAB-7/output3Cost.txt Normal file
View File

@@ -0,0 +1,35 @@
0XlfA2Y21E 263.73
o80ve2yJ69 0
1wu5Rn5NF2 421.73
23G1A210OF 244.75
xaj321J1BZ 0
Cr731Iii7I 487.02
6E3Fxj85yL 287.23
wYs18i9m5k 0
W8ANj6np26 119.18
b8W01cT5n8 362.53
338bJ687YD 0
8ft4ChT823 323.71
i01&50ftN2 0
ocn2E9U02m 0
At90OL089h 120.27
eo0n0Z62wq 230.08
6sVk7528rZ 166.01
O@2C3Y5Oe6 0
99L0MmmK60 0
M5N$p8C823 152.83
8r80725tqY 306.12
Qb7gA5M10H 0
0Y-o506P%b 0
9Lc160L30C 385.04
E%q847=v2d 0
23L9Jgx7yt 0
BH51tz93s5 247.06
f71O-^D5k9 219.49
o4bbw3q524 0
x60iC7015a 385.52
578q3cOi4L 403.93
t8W7R&45s3 337.85
53h2xKa8P1 0
9=4(L4kF8b 0
12TGf5$u)3 82.67

View File

@@ -0,0 +1,35 @@
0XlfA2Y21E 0
o80ve2yJ69 0
1wu5Rn5NF2 0
23G1A210OF 18
xaj321J1BZ 11
Cr731Iii7I 10
6E3Fxj85yL 14
wYs18i9m5k 13
W8ANj6np26 11
b8W01cT5n8 5
338bJ687YD 0
8ft4ChT823 10
i01&50ftN2 8
ocn2E9U02m 0
At90OL089h 0
eo0n0Z62wq 0
6sVk7528rZ 11
O@2C3Y5Oe6 0
99L0MmmK60 0
M5N$p8C823 13
8r80725tqY 11
Qb7gA5M10H 0
0Y-o506P%b 5
9Lc160L30C 14
E%q847=v2d 0
23L9Jgx7yt 0
BH51tz93s5 5
f71O-^D5k9 11
o4bbw3q524 11
x60iC7015a 15
578q3cOi4L 9
t8W7R&45s3 12
53h2xKa8P1 0
9=4(L4kF8b 0
12TGf5$u)3 0

35
LAB-7/output3Valid.txt Normal file
View File

@@ -0,0 +1,35 @@
0XlfA2Y21E true
o80ve2yJ69 false
1wu5Rn5NF2 true
23G1A210OF false
xaj321J1BZ true
Cr731Iii7I true
6E3Fxj85yL true
wYs18i9m5k true
W8ANj6np26 true
b8W01cT5n8 false
338bJ687YD false
8ft4ChT823 false
i01&50ftN2 false
ocn2E9U02m true
At90OL089h false
eo0n0Z62wq true
6sVk7528rZ false
O@2C3Y5Oe6 false
99L0MmmK60 false
M5N$p8C823 false
8r80725tqY false
Qb7gA5M10H true
0Y-o506P%b false
9Lc160L30C false
E%q847=v2d false
23L9Jgx7yt true
BH51tz93s5 false
f71O-^D5k9 false
o4bbw3q524 false
x60iC7015a false
578q3cOi4L false
t8W7R&45s3 false
53h2xKa8P1 false
9=4(L4kF8b false
12TGf5$u)3 false

View File

@@ -0,0 +1,7 @@
/**
* @author brett
*
*/
module uwstout.courses.cs144 {
requires junit;
}

View File

@@ -0,0 +1,184 @@
package uwstout.courses.cs144.labs.lab7;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.Scanner;
/**
* Stores the name of the input file that the data is in and the name of the
* output file where the report will be written. Contains a number of methods to
* find, filter, and process the data.
*
* @author Brett Bender
* @version 2022.11.28
*/
public class DataAnalytic {
private String inputFileName;
private String outputFileName;
/**
* Creates a new DataAnalytic class to analyze and process data. Takes data
* from input (filename), and outputs the report to output (filename).
*
* @param input The name of the input file
* @param output The name of the output file
*/
public DataAnalytic(String input, String output) {
inputFileName = (input == null) ? "" : input;
outputFileName = (output == null) ? "" : output;
}
/**
* Get the input filename
*
* @return The input filename
*/
public String getInputName() {
return inputFileName;
}
/**
* Get the output filename
*
* @return The output filename
*/
public String getOutputName() {
return outputFileName;
}
/**
* Skips to a field definition
*
* @param sc The input scanner
* @param fieldName The field we are searching for
*/
public void skipToField(Scanner sc, String fieldName) {
String readString;
do {
if (sc.hasNext()) {
readString = sc.next();
} else {
break;
}
} while (!readString.matches("(\\[?)" + fieldName + "(\\]?)"));
}
/**
* Gets the sum of an income field
*
* @param sc The input scanner
* @return The total income
*/
public double getIncome(Scanner sc) {
skipToField(sc, "income");
double total = 0;
while (sc.hasNextDouble()) {
total += sc.nextDouble();
}
return total;
}
/**
* Get the average of an interactions field
*
* @param sc The input scanner
* @return The average interactions
*/
public int getFrequency(Scanner sc) {
skipToField(sc, "interactions");
int total = 0;
int num = 0;
while (sc.hasNextDouble()) {
total += sc.nextInt();
num++;
}
try {
return total / num;
} catch (Exception e) {
return 0;
}
}
/**
* Checks if an input ID is valid
*
* @param id The ID to check
* @return If the ID is valid
*/
public boolean isValid(String id) {
int numDigits = 0;
int numLetters = 0;
int numOtherChars = 0;
for (int i = 0; i < id.length(); i++) {
char c = id.charAt(i);
if ('0' <= c && c <= '9') {
numDigits++;
} else if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) {
numLetters++;
} else {
numOtherChars++;
}
}
return numOtherChars == 0 && numDigits < numLetters;
}
/**
* Processes the input file, and outputs the given reportType to the output
* file specified at class creation. Returns true if the file was processed,
* false if one of the files can't be opened.
*
* @param reportType The type of report to be created.
* @return If the processing occurred.
*/
public boolean processFile(ProcessType reportType) {
DecimalFormat df = new DecimalFormat("#,###.00");
try {
File inFile = new File(inputFileName);
Scanner fileScanner = new Scanner(inFile);
PrintWriter outWriter = new PrintWriter(outputFileName);
while (fileScanner.hasNext()) {
String readLine = fileScanner.nextLine();
Scanner lineScanner = new Scanner(readLine);
String id = lineScanner.next();
switch (reportType) {
case COST:
double income = getIncome(lineScanner);
outWriter.println(id + " " + df.format(income));
break;
case FREQUENCY:
int freq = getFrequency(lineScanner);
outWriter.println(id + " " + freq);
break;
default:
boolean valid = isValid(id);
outWriter.println(id + " " + valid);
break;
}
}
fileScanner.close();
outWriter.close();
return true;
} catch (FileNotFoundException e) {
return false;
}
}
}

View File

@@ -0,0 +1,251 @@
package uwstout.courses.cs144.labs.lab7;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.util.Scanner;
import org.junit.Before;
import org.junit.Test;
/**
* Tests the DataAnalytic Class
*
* @author Brett Bender
* @version 2022.11.28
*/
public class DataAnalyticTest {
private static final double DELTA = 0.01;
private DataAnalytic da1;
private DataAnalytic da2;
private DataAnalytic da3;
/**
* Set up the shared DataAnalytic Classes
*
* @throws Exception
*/
@Before
public void setUp() throws Exception {
da1 = new DataAnalytic("input1.txt", "output1.txt");
da2 = new DataAnalytic("input2.txt", "output2.txt");
da3 = new DataAnalytic("input3.txt", "output3.txt");
}
/**
* Tests the default constructor
*/
@Test
public void testDataAnalytic() {
DataAnalytic t1 = new DataAnalytic(null, null);
assertEquals("", t1.getInputName());
assertEquals("", t1.getOutputName());
DataAnalytic t2 = new DataAnalytic("testin1.txt", "testout1.txt");
assertEquals("testin1.txt", t2.getInputName());
assertEquals("testout1.txt", t2.getOutputName());
}
/**
* Tests the getIncome method
*/
@Test
public void testGetIncome() {
// create a line of input (taken from one of the data files)
// this should find the interactions field and average the numbers.
Scanner input = new Scanner("[uses] 10 5 8 [uses] "
+ "[uses] 86.26 10.48 98.26 55.51 28.41 61.26 [uses] "
+ "income 32.35 51.31 70.99 98.72 40.78 65.53 income "
+ "[interactions] 8 20 1 1 6 3 17 3 18 [interactions] ");
assertEquals(359.68, da1.getIncome(input), DELTA);
input = new Scanner("[income] [income]");
assertEquals(0, da1.getIncome(input), DELTA);
input = new Scanner("");
assertEquals(0, da1.getIncome(input), DELTA);
input = new Scanner("income 10 10 10 income");
assertEquals(30, da1.getIncome(input), DELTA);
}
/**
* Tests the getFrequency method
*/
@Test
public void testGetFrequency() {
// create a line of input (taken from one of the data files)
// this should find the interactions field and average the numbers.
Scanner input = new Scanner("[uses] 10 5 8 [uses] "
+ "[uses] 86.26 10.48 98.26 55.51 28.41 61.26 [uses] "
+ "income 32.35 51.31 70.99 98.72 40.78 65.53 income "
+ "[interactions] 8 20 1 1 6 3 17 3 18 [interactions] ");
assertEquals(8, da1.getFrequency(input));
input = new Scanner("[interactions] [interactions]");
assertEquals(0, da1.getFrequency(input));
input = new Scanner("");
assertEquals(0, da1.getFrequency(input));
input = new Scanner("interactions 10 10 interactions");
assertEquals(10, da1.getFrequency(input));
}
/**
* Tests the isValid method
*/
@Test
public void testIsValid() {
// create object - file names don't matter
// since they are not being used
assertTrue(da1.isValid("9Yns4a9i5N"));
assertTrue(da1.isValid("H04GP8Y7DC"));
assertFalse(da1.isValid("dF6aW1--51"));
assertFalse(da1.isValid("20#Tg0=OI6"));
assertFalse(da1.isValid("23G1A210OF"));
assertFalse(da1.isValid("23G1a?]Z`z"));
}
/**
* Test processFile with the VALIDATE value
*/
@Test
public void testProcessFileValidate() {
// create the report
assertTrue(da1.processFile(ProcessType.VALIDATE));
// this will only return true if everything else worked.
assertTrue(testFile("output1.txt", "output1Valid.txt"));
// create the report
assertTrue(da2.processFile(ProcessType.VALIDATE));
// this will only return true if everything else worked.
assertTrue(testFile("output2.txt", "output2Valid.txt"));
// create the report
assertTrue(da3.processFile(ProcessType.VALIDATE));
// this will only return true if everything else worked.
assertTrue(testFile("output3.txt", "output3Valid.txt"));
}
/**
* Test processFile with the FREQUENCY value
*/
@Test
public void testProcessFileFrequency() {
// create the report
assertTrue(da1.processFile(ProcessType.FREQUENCY));
// this will only return true if everything else worked.
assertTrue(testFile("output1.txt", "output1Frequency.txt"));
// create the report
assertTrue(da2.processFile(ProcessType.FREQUENCY));
// this will only return true if everything else worked.
assertTrue(testFile("output2.txt", "output2Frequency.txt"));
// create the report
assertTrue(da3.processFile(ProcessType.FREQUENCY));
// this will only return true if everything else worked.
assertTrue(testFile("output3.txt", "output3Frequency.txt"));
}
/**
* Test processFile with the COST value
*/
@Test
public void testProcessFileCost() {
// create the report
assertTrue(da1.processFile(ProcessType.COST));
// this will only return true if everything else worked.
assertTrue(testFile("output1.txt", "output1Cost.txt"));
// create the report
assertTrue(da2.processFile(ProcessType.COST));
// this will only return true if everything else worked.
assertTrue(testFile("output2.txt", "output2Cost.txt"));
// create the report
assertTrue(da3.processFile(ProcessType.COST));
// this will only return true if everything else worked.
assertTrue(testFile("output3.txt", "output3Cost.txt"));
}
/**
* Test processFile with an invalid file
*/
@Test
public void testProcessFileInvalid() {
DataAnalytic data = new DataAnalytic(null, null);
// create the report
assertFalse(data.processFile(ProcessType.COST));
}
private boolean testFile(String fileName, String expectedFileName) {
String id;
String value;
String line;
int lineCount = 0;
// Test if the output file exists
File inputFile = new File(fileName);
File expectedFile = new File(expectedFileName);
assertTrue("Could not find file " + fileName, inputFile.exists());
try {
// create scanners for the file and the string
// of expected results
Scanner inputScan = new Scanner(inputFile);
Scanner expScan = new Scanner(expectedFile);
// read until one of the two ends (hopefully both)
while (inputScan.hasNext() && expScan.hasNext()) {
// read in a line from the file
line = inputScan.nextLine();
// assuming that the expected data has two values
// per line: the id and the value - should work
// for all three types of reports
id = expScan.next();
value = expScan.next();
// check if line has id and value
assertTrue(
"Could not find the id on line " + lineCount
+ ". The id was supposed to be " + id + ".",
line.indexOf(id) >= 0);
assertTrue("Could not find the value on line " + lineCount
+ ". The id was supposed to be " + id + " and the "
+ "value should be " + value + ".",
line.indexOf(value) >= 0);
lineCount++;
}
// check if there is more data in either scanner
assertFalse("The output file had more lines than it should.",
inputScan.hasNext());
assertFalse("There was not as much data in the output "
+ "file as expected.", expScan.hasNext());
inputScan.close();
expScan.close();
} catch (Exception e) {
fail("processFile crashed trying to read from " + inputFile);
}
return true;
}
}

View File

@@ -0,0 +1,39 @@
package uwstout.courses.cs144.labs.lab7;
/**
* Represents the kind of analysis being ran on the input file.
*
* @author Brett Bender
* @version 2022.11.28
*/
public enum ProcessType {
/**
* Calculate total income
*/
COST,
/**
* Calculate average interactions
*/
FREQUENCY,
/**
* Validate IDs
*/
VALIDATE;
@Override
public String toString() {
String retString;
switch (this) {
case COST:
retString = "Total Income";
break;
case FREQUENCY:
retString = "Average Interactions";
break;
default:
retString = "Validation";
break;
}
return retString;
}
}

View File

@@ -0,0 +1,25 @@
package uwstout.courses.cs144.labs.lab7;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
/**
* Tests the ProcessType enum
*
* @author Brett Bender
* @version 2022.11.28
*/
public class ProcessTypeTest {
/**
* Tests the toString method on ProcessType
*/
@Test
public void testToString() {
assertEquals("Total Income", ProcessType.COST.toString());
assertEquals("Average Interactions", ProcessType.FREQUENCY.toString());
assertEquals("Validation", ProcessType.VALIDATE.toString());
}
}