-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZTable.java
261 lines (213 loc) · 10.5 KB
/
ZTable.java
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package statsmodel;
import static com.sun.xml.internal.fastinfoset.alphabet.BuiltInRestrictedAlphabets.table;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.table.TableColumn;
/**
*
* @author Milu
*/
public class ZTable {
NumericalMethods numMethods = new NumericalMethods();
//frmGreaterThan greaterThan = new frmGreaterThan();
temp temp = new temp();
//static double start, end; //get user inputs from text boxes
double[] column = new double[10];
//JTable table;
public ZTable() {
}
public static void main(String args[]) {
//data as object;
//table
//DISPLAY
/*for (int k = 0; k < rows.length; k++) { //print each row
System.out.println(rows[k]);
}*/
}
public void check_is_Input_Negative(double start, double end) {
if (start < 0 && end < 0) {
}
}
public JTable getZTable(boolean s, double start, double end) {
//double start = 2;//.97;//0.97;
// double end = 4;
//3.9;
//finding the no. of rows:
//check_is_Input_Negative(start, end);//check whether the start or end z value is negative
double startOnedp = (Math.floor(start * 10.0) / 10.0);//get the first 2 significant figures of the input start value
double endOnedp = (Math.floor(end * 10.0) / 10.0);// 2sf of end value
double difference = endOnedp - startOnedp; //find difference
double tenths = difference * 10; //gets a Double to 1 place value after decimal
int noOfRows = (int) tenths; //only whole number is relevnat
//checks whether there is a number in the 2dp of start 0.0*<-. If so, the no. of columns needs to be incremented by 1
int start_hundreth_present = getColumnHeading(start);
double x = Math.floor(start);
//if (start_hundreth_present != 0&&x==0) {
/// noOfRows++;
// }
//if (start_hundreth_present != 0) {
// noOfRows++;
//}
noOfRows++; //increment by 1 to get the no of rows between start and end
//get the first LHS row header value
double rowFirstHeader = (Math.floor(start * 10) / 10);//get the first 2 significant figures of the input start value
double rowLastHeader = (Math.floor(end * 10) / 10);// 2sf of end value
double[] rows = new double[noOfRows];
//row,MINUS 1 AS O IS INCLUDED FOR BOTH VALUES R,C
///"+1" because og table headers
JTable table = new JTable(noOfRows + 1, 10 + 1) {
//Implement table cell tool tips.
public String getToolTipText(MouseEvent e) {
String tip = null;
java.awt.Point p = e.getPoint();
int rowIndex = rowAtPoint(p);
int colIndex = columnAtPoint(p);
try {
tip = getValueAt(rowIndex, colIndex).toString();
} catch (RuntimeException e1) {
//catch null pointer exception if mouse is over an empty line
}
return tip;
}
};
TableColumn column = null;
for (int i = 0; i < table.getColumnCount(); i++) {
column = table.getColumnModel().getColumn(i);
column.setPreferredWidth(60);
}
table.setRowHeight(30);
//table.setShowGrid(false);
table.setShowHorizontalLines(true);
table.setShowVerticalLines(false);
table.setGridColor(Color.BLACK);
table.setFont(new Font("Ariel", Font.PLAIN, 14));
//Z TABLE HEADERS
table.setValueAt("Z", 0, 0);//r,c/i,j//only applicatble for the FIRST ROW and possibly the LAST ROW
//Z=0.1 to 4.0
double z_rowHeaders = rowFirstHeader;//row headers are to 1dp
DecimalFormat fRow = new DecimalFormat("0.0");
//ROW HEADERs
for (int r = 1; r < (noOfRows) + 1; r++) {
table.setValueAt(fRow.format(z_rowHeaders), r, 0);//r,c/i,j//only applicatble for the FIRST ROW and possibly the LAST ROW
z_rowHeaders += 0.1;
}
//COLUMN HEADERs
//Z = 0.00 to 0.09
double z_ColumnHeaders = 0.00;//column headers are to 2 dp
DecimalFormat fCol = new DecimalFormat("0.00");
for (int h = 1; h < 11; h++) {
// z_rowHeaders = (Math.floor(z_rowHeaders * 100) / 100);// 2dp format
table.setValueAt(fCol.format(z_ColumnHeaders), 0, h);//r,c/i,j//only applicatble for the FIRST ROW and possibly the LAST ROW
z_ColumnHeaders += 0.01;
}
int intFirstColumnHeaderI = getColumnHeading(start);
//LOCATE FIRST j (ROW place in table)
double doubleRowHeader = Math.floor(start * 10) / 10;//gets Z value to 1 dp
// double intFirstRowHeaderD = (doubleRowHeader * 10);//get the nth row postion of the double row magnitude
int intFirstRowHeaderI = (int) doubleRowHeader;//typecasts to populate in table
//error check to fill in leading empty cells incase VALUE DOESTN START @ (0,0) i.e. somewhere middway
//empty cells before start
if (intFirstColumnHeaderI != 0) {//0th is the first column
for (int f = 1; f <= intFirstColumnHeaderI; f++) {//fill in the leading empty cells
table.setValueAt(null, 1, f);//r,c/i,j//only applicatble for the FIRST ROW and possibly the LAST ROW
}
}
//ENDING POINT OF TABLE
//ENDING ROW
double doubleLastRowHeader = Math.floor(end * 10) / 10;//gets Z value to 1 dp
double integerLastRowHeadersD = (doubleLastRowHeader * 10) + 1;//get the nth row postion of the double row magnitude
int integerLastRowHeadersI = (int) integerLastRowHeadersD;//typecasts to populate in table
//ENDING COLUMN
double truncate_ZEnd = Math.floor(end * 10) / 10;//gets Z value to 1 dp
double hundreths_ZEnd = end - truncate_ZEnd;//gets the the 2nd dp (hunthreths) number for column headings
double intLastColumnHeadersDR = Math.round(hundreths_ZEnd * 100.0) / 100.0; //gets the interger part of the column, igoring the leading 0.0s
int intLastColumnHeadersI = (int) (intLastColumnHeadersDR * 100);//as first heading is inclusive of 0(.00)
//POPULATE
int cPointer, counter = 0;
int tempR;// = (intFirstRowHeaderI+1);
if (intFirstRowHeaderI == 0) {//only exception when value of row cant be used as a count
tempR = 1;
} else {
tempR = intFirstRowHeaderI;
}
for (int rPointer = 1; rPointer < noOfRows + 1; rPointer++) {//row pointer
//ensures that the row after the first stare from the first cell in the next row
//FIRST VALUE MAY NOT BE IN THE FIRST COLUMN OF THE FIRST ROW
counter++;//redunant after first iteration
if (counter == 1) {
cPointer = intFirstColumnHeaderI + 1;//WHAT I DID HERE IS CRUCIAL EXPLAIN PERFECTLY; DOUBLT TO MAG CONVERSION SO THAT DISPLAY PARALLELS WITH MAG COUNT
} else {
cPointer = 1;
}//if else
for (cPointer = cPointer; cPointer < 11; cPointer++) {//9999
/*if (rB == greaterThan.radBtnZSimp) {
table.setValueAt(zScoreUsingSimpsons(start), rPointer, cPointer);//value, row, col
}
else if (rB == greaterThan.radBtnZTrap) {
table.setValueAt(zScoreUsingTrapezium(start), rPointer, cPointer);//value, row, col
}*/
table.setValueAt(getAreaLeftOfZScore(start, s), rPointer, cPointer);//value, row, col
start += 0.01;
}//for loop column
int t = 0;
}//for loop row
//empty @ end
int columnIndex = intLastColumnHeadersI + 1;//column index is n+1
int temp = columnIndex + 1;//column after should be next
if (columnIndex != 10) {//9th column is the last
for (int f = temp; f < 11; f++) {//fill in the ending/trailing empty cells
table.setValueAt(null, noOfRows, f);//r,c/i,j//only applicatble for the FIRST ROW and possibly the LAST ROW
}
}
return table;
}
public int getColumnHeading(double start) {
//STARTING POINTS OF TABLE
//LOCATE FIRST i (COLUMN place in table)
double truncate_ZStart = Math.floor(start * 10) / 10;//gets Z value to 1 dp
double hundreths_ZStart = start - truncate_ZStart;//gets the the 2nd dp (hunthreths) number for column headings
double hundreths_ZStartR = Math.round(hundreths_ZStart * 100.0) / 100.0;//gets the the 2nd dp (hunthreths) number for column headings
double intFirstColumnHeaderD = hundreths_ZStartR * 100; //gets the interger part of the column, igoring the leading 0.0s
int intFirstColumnHeaderI = (int) intFirstColumnHeaderD;//+1;//as first heading is inclusive of 0(.00)
return intFirstColumnHeaderI;
}
public BigDecimal getAreaLeftOfZScore(double b, boolean s) {
double a = -4;//-4;//cos -10 //upper limit
BigDecimal zArea;
if (s) {
//System.out.println("Simpson");
zArea = numMethods.simpsonsRule(a, b, 0, 1);
//return zArea;
} else {
//System.out.println("Trapezium");
zArea = numMethods.trapeziumRule(a, b, 0, 1);
//return zArea;
}
// BigDecimal zArea = numMethods.simpsonsRule(a, b, 0, 1);
//zArea = numMethods.trapeziumRule(a, b, 0, 1);
//zArea = numMethods.simpsonsRule(a, b, 0, 1);
return zArea;
}
public Object zScoreUsingSimpsons(double b) {
double a = -4;//-4;//cos -10 //upper limit
BigDecimal zArea = numMethods.simpsonsRule(a, b, 0, 1);
return zArea;
}
public Object zScoreUsingTrapezium(double b) {
double a = -4;//-4;//cos -10 //upper limit
BigDecimal zArea = numMethods.trapeziumRule(a, b, 0, 1);
return zArea;
}
}