-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment7-part2
More file actions
156 lines (129 loc) · 3.93 KB
/
assignment7-part2
File metadata and controls
156 lines (129 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// assignment 7 cont'd
import java.io.*;
public class Program7contd
{
// declare variables
double famIncome[], temp2; // need temp with this variable for bubble search loops
double adjInc[];
double taxRate[];
double famTax[];
int count = 11; // needs to be 1 less than size of arrays (12)
int flag = 0; // for while loop
int deductions[] = {1,1,1,1}; // another way to say size of deductions is 4
String lname[], temp1; // need temp with this variable for bubble search loops
PrintWriter outfile;
// declare index variables
int i;
int j;
// declare temporary variables for array compare
String lnametemp[] = new String[4];
double famIncometemp[] = {0,0,0,0}; // another way to say size of famIncometemp is 4
// call constructor method
public Program7contd(String lname[], double famIncome[], PrintWriter outfile, double adjInc[],
double taxRate[], double famTax[])
{
this.lname = lname;
this.famIncome = famIncome;
this.outfile = outfile;
this.adjInc = adjInc;
this.taxRate = taxRate;
this.famTax = famTax;
}
// calculate deductions: dont print
public void deductions()
{
// set the first index of temp array equal to first index of original array
famIncometemp[0] = famIncome[0];
for(int i=0; i<11; i++)
{
// if the first element in lname = next element of lname...
if(lname[i].equals(lname[i+1]))
{
// then the first index in lnametemp (temp array) is filled (=) to that name
// then also add the incomes of each member
// then also increment the counter (deductions)
lnametemp[j] = lname[i+1];
famIncometemp[j] += famIncome[i+1];
deductions[j]++;
}
// if that is not the case
else
{
// then the next index in lname temp (temp array) is filled with the name not equal to lname[i]
// then also add the incomes of each member
// then also go to the next index of j
lnametemp[j+1] = lname[i+1];
famIncometemp[j+1] = famIncome[i+1];
j++;
}
}
outfile.println();
outfile.println("Tax Data for Each Family: ");
outfile.println();
}
// calculate adjusted income tax: print to outfile
public void adjustedInc()
{
for(j=0; j<4; j++)
{
adjInc[j] = famIncometemp[j] - (500 * deductions[j]);
outfile.println("Adjusted Income for " + lnametemp[j] + " : " + adjInc[j]);
}
}
// calculate tax rate: dont print
public void taxRate()
{
for(j=0; j<4; j++)
{
if(famIncometemp[j] < 60000.00)
{
taxRate[j] = adjInc[j]/100000.00;
}
else if(famIncometemp[j] >= 60000.00)
{
taxRate[j] = .50;
}
}
}
// calculate family tax: print to outfile
public void famTax()
{
outfile.println();
for(j=0; j<4; j++)
{
famTax[j] = (taxRate[j]*adjInc[j]);
outfile.println("Taxes for " +lnametemp[j] + " : " + famTax[j]);
}
}
// sort the last names in alphabetical order: print the sorted list after the original list
public void sort()
{
// basically copied from bsort2 - still unsure of what flag means but i get the idea
while(flag==0)
{
flag=1;
for(i=0; i<count;i++)
{
if(lname[i].compareTo(lname[i+1]) >0)
{
// run loop for last names
temp1 = lname[i];
lname[i] = lname[i+1];
lname[i+1] = temp1;
// run loop for incomes
temp2 = famIncome[i];
famIncome[i]= famIncome[i+1];
famIncome[i+1] = temp2;
flag=0;
}
}
count--;
}
outfile.println();
outfile.println("Sorted List of Families:");
outfile.println();
for(i=0; i<12; i++)
{
outfile.println(lname[i]+ " " + famIncome[i]);
}
}