Double check on Java code.
Alright - I downloaded a *.class file that was being used as an applet and decompiled it into this. I need to make a flow chart of what every line in this program does and why, so that I can figure out how to solve the same problem this program does, but in C++, and in my own style. This is a pretty easy question, but I just want to double check. Can anyone find a place in this code where fill() might be called? Even if it's in an IF statement, I just need to find it, because my with my understanding of this code so far, fill() is just a useless function!
Code:
import java.applet.Applet;
import java.awt.*;
public class lsq extends Applet
{
public void init()
{
setBackground(Color.lightGray);
setLayout(null);
resize(475, 375);
label = new Label(" Data");
label.reshape(0, 0, 150, 20);
add(label);
label = new Label(" Plot");
label.reshape(155, 0, 270, 20);
add(label);
data.reshape(0, 20, 150, 150);
data.setFont(new Font("COURIER", 0, 12));
add(data);
plot1.reshape(155, 20, 320, 230);
add(plot1);
plot1.repaint();
label = new Label(" Equation");
label.reshape(0, 250, 470, 20);
add(label);
result.reshape(0, 270, 475, 75);
result.setFont(new Font("COURIER", 0, 12));
add(result);
cpanel.reshape(0, 350, 475, 75);
cpanel.add(compute);
cpanel.add(plotData);
model.addItem("Linear");
model.addItem("Quadratic");
model.addItem("Cubic");
cpanel.add(model);
add(cpanel);
show();
}
public boolean action(Event event, Object obj)
{
if(event.target == compute)
{
result.setText("Calculating...");
Matrix matrix = new Matrix(data.getText());
plot1.P = matrix;
plot1.repaint();
result.setText(compute(matrix));
} else
if(event.target == plotData)
{
plot1.M = new Matrix("0;0");
plot1.P = new Matrix(data.getText());
plot1.repaint();
}
return super.action(event, obj);
}
String compute(Matrix matrix)
{
int k = model.getSelectedIndex() + 2;
Matrix matrix1 = new Matrix(matrix.rows, k, 1.0D);
for(int j1 = 1; j1 < matrix1.columns; j1++)
{
for(int i = 0; i < matrix1.rows; i++)
matrix1.element[i][j1] = Math.pow(matrix.element[i][0], j1);
}
Matrix matrix2 = matrix1.Q();
Matrix matrix3 = new Matrix(matrix2.transpose(), matrix1, '*');
Matrix matrix4 = new Matrix(matrix2.transpose(), matrix.sub(0, matrix.rows - 1, 1, 1), '*');
matrix4 = new Matrix(matrix4.sub(0, matrix3.columns - 1, 0, 0));
matrix3 = new Matrix(matrix3.sub(0, matrix3.columns - 1, 0, matrix3.columns - 1));
Matrix matrix5 = new Matrix(matrix3, matrix4, '\\');
plot1.P = new Matrix(data.getText());
plot1.repaint();
plot1.M = matrix5;
matrix4 = matrix.sub(0, matrix.rows - 1, 1, 1);
double d = matrix4.average();
double d1 = 0.0D;
double d3 = 0.0D;
double d4 = 0.0D;
for(int j = 0; j < matrix.rows; j++)
{
double d2 = 0.0D;
for(int l = 0; l < matrix5.rows; l++)
d2 += matrix5.element[l][0] * Math.pow(matrix.element[j][0], l);
d3 += Math.pow(d2 - d, 2D);
d4 += Math.pow(matrix4.element[j][0] - d, 2D);
}
Matrix matrix6 = new Matrix(matrix1, matrix5, '*');
Matrix matrix7 = new Matrix(matrix6, matrix4, '-');
double d5 = Math.pow(matrix7.norm(), 2D);
String s = "\ny = " + matrix5.element[0][0];
if(matrix5.element[1][0] >= 0.0D)
s = s + " +";
s = s + " " + matrix5.element[1][0] + "x";
for(int i1 = 2; i1 < matrix5.rows; i1++)
{
if(matrix5.element[i1][0] >= 0.0D)
s = s + " +";
s = s + " " + matrix5.element[i1][0] + "x^" + i1;
}
return s;
}
String fill(double d, int i)
{
String s = " " + d + " ";
return s.substring(0, i);
}
public lsq()
{
data = new TextArea(30, 20);
result = new TextArea(50, 20);
plot1 = new Plot();
cpanel = new Panel();
compute = new Button("Compute");
plotData = new Button("Plot data");
model = new Choice();
}
TextArea data;
TextArea result;
Plot plot1;
Panel cpanel;
Button compute;
Button plotData;
Choice model;
Label label;
}