I wrote this program and it systems outs the right data but the j frame is coming up correctly. can someone please fix it a repost it. I would be forever grateful.
**************************************************************
//jframe start
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//jframe end
import java.util.Arrays;
public class Coltonssciencefair
{
public static int getMaximum(int[] Random)
{
int max=0;
int[] toReturn = new int[Random.length+1];
for (int i = 0; i < Random.length; i++)
{
if ( Random[i] > toReturn[0])
{
toReturn[0] = Random[i];
max = i;
}
}
return max;
}
//starts here
public class DataOutput extends JFrame
{
JLabel Mean2;
JLabel Median2;
JLabel Mode2;
JLabel Min2;
JLabel max2;
JTextField min1;
JTextField mode1;
JTextField max1;
JTextField median1;
JTextField Mean1;
JLabel OutputData1;
JButton Ok;
JLabel SD;
JTextField SD1;
public DataOutput() {
DataOutputLayout customLayout = new DataOutputLayout();
getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 14));
getContentPane().setLayout(customLayout);
Mean2 = new JLabel("Mean");
getContentPane().add(Mean2);
Median2 = new JLabel("Median");
getContentPane().add(Median2);
Mode2 = new JLabel("Mode");
getContentPane().add(Mode2);
Min2 = new JLabel("Minnimum");
getContentPane().add(Min2);
max2 = new JLabel("Maximum");
getContentPane().add(max2);
min1 = new JTextField("Min");
getContentPane().add(min1);
mode1 = new JTextField("mode");
getContentPane().add(mode1);
max1 = new JTextField("Max");
getContentPane().add(max1);
median1 = new JTextField("median");
getContentPane().add(median1);
Mean1 = new JTextField("average");
getContentPane().add(Mean1);
OutputData1 = new JLabel(" OutputData");
getContentPane().add(OutputData1);
Ok = new JButton("Ok");
getContentPane().add(Ok);
SD = new JLabel("Standard Deviation");
getContentPane().add(SD);
SD1 = new JTextField("dev");
getContentPane().add(SD1);
setSize(getPreferredSize());
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void second(String args[]) {
DataOutput window = new DataOutput();
window.setTitle("DataOutput");
window.pack();
window.show();
}
}
class DataOutputLayout implements LayoutManager {
public DataOutputLayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInsets();
dim.width = 175 + insets.left + insets.right;
dim.height = 350 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+96,72,24);}
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+128,72,24);}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+160,72,24);}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+224,72,24);}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+192,72,24);}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+224,72,24);}
c = parent.getComponent(6);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+160,72,24);}
c = parent.getComponent(7);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+192,72,24);}
c = parent.getComponent(8);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+128,72,24);}
c = parent.getComponent(9);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+96,72,24);}
c = parent.getComponent(10);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+16,152,64);}
c = parent.getComponent(11);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+288,152,48);}
c = parent.getComponent(12);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+256,72,24);}
c = parent.getComponent(13);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+256,72,24);}
}
}
//ends here
public static void main(String[] args)
{
int value = 100000; //amout of tested numbers
int value2 = 10; //range of tested numbers (maximum value possible)
int[]Counter = new int [value+1];
int[] Random;
Random = new int[value+1];
int count = 0;
double average = 0;
int Max = value2;
int Min = 0;
int sum = 0;
int number = 0;
double median = 0;
int mode = 0;
double dev = 0;
double acc = 0;
for (count = 0; count < value; count++)
{
number = (int)(Math.random()*value2+1);
Random[count] = number;
sum = sum + number;
}
average = (double)sum/(double)value;
System.out.println(value+" randomly generated numbers from 0 to "+value2);
System.out.println("In Ascending Order:");
Arrays.sort(Random);
for (count = 0; count < value; count++)
{
//comenmt out
// System.out.println(Random[count]);
while(Random[count]>Max)
Max=Random[count];
while(Random[count]<Min)
Min=Random[count];
median=Random[value/2];
}
for (int k = 0; k < value; k++)
{
Counter[Random[k]] =Counter[Random[k]]+1;
}
for (int k = 0; k < value; k++)
{
acc = acc + (Random[k]-average)*(Random[k]-average);
}
average= average-.5;
dev = Math.sqrt(acc/value);
mode=getMaximum(Counter);
System.out.println("The highest number is " + Max);
System.out.println("The lowest number is " + Min);
System.out.println("The median is "+median+".");
System.out.println("The average is: " +average);
System.out.println("The mode is "+mode);
System.out.println("The standard deviation is "+dev);
}
}
****************************************************************
Please hurry. I am under a lot of pressure here to get this done.
12 replies to this topic
#1
Posted 23 March 2011 - 10:06 AM
|
|
|
#2
Posted 23 March 2011 - 10:54 AM
import java.awt.*;
import javax.swing.*;
import java.util.Arrays;
public class MainAsd
{
public static int getMaximum(int[] Random)
{
int max=0;
int[] toReturn = new int[Random.length+1];
for (int i = 0; i < Random.length; i++)
{
if ( Random[i] > toReturn[0])
{
toReturn[0] = Random[i];
max = i;
}
}
return max;
}
//starts here
public class DataOutput extends JFrame
{
private static final long serialVersionUID = -4480786588092262886L;
JLabel Mean2;
JLabel Median2;
JLabel Mode2;
JLabel Min2;
JLabel max2;
JTextField min1;
JTextField mode1;
JTextField max1;
JTextField median1;
JTextField Mean1;
JLabel OutputData1;
JButton Ok;
JLabel SD;
JTextField SD1;
public DataOutput() {
DataOutputLayout customLayout = new DataOutputLayout();
getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 14));
getContentPane().setLayout(customLayout);
Mean2 = new JLabel("Mean");
getContentPane().add(Mean2);
Median2 = new JLabel("Median");
getContentPane().add(Median2);
Mode2 = new JLabel("Mode");
getContentPane().add(Mode2);
Min2 = new JLabel("Minnimum");
getContentPane().add(Min2);
max2 = new JLabel("Maximum");
getContentPane().add(max2);
min1 = new JTextField("Min");
getContentPane().add(min1);
mode1 = new JTextField("mode");
getContentPane().add(mode1);
max1 = new JTextField("Max");
getContentPane().add(max1);
median1 = new JTextField("median");
getContentPane().add(median1);
Mean1 = new JTextField("average");
getContentPane().add(Mean1);
OutputData1 = new JLabel(" OutputData");
getContentPane().add(OutputData1);
Ok = new JButton("Ok");
getContentPane().add(Ok);
SD = new JLabel("Standard Deviation");
getContentPane().add(SD);
SD1 = new JTextField("dev");
getContentPane().add(SD1);
pack();
setVisible(true);
}
}
class DataOutputLayout implements LayoutManager {
public DataOutputLayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInsets();
dim.width = 175 + insets.left + insets.right;
dim.height = 350 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+96,72,24);}
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+128,72,24);}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+160,72,24);}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+224,72,24);}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+192,72,24);}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+224,72,24); }
c = parent.getComponent(6);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+160,72,24); }
c = parent.getComponent(7);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+192,72,24); }
c = parent.getComponent(8);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+128,72,24); }
c = parent.getComponent(9);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+96,72,24);}
c = parent.getComponent(10);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+16,152,64);}
c = parent.getComponent(11);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+288,152,48); }
c = parent.getComponent(12);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+256,72,24);}
c = parent.getComponent(13);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+256,72,24); }
}
}
//ends here
public static void main(String[] args)
{
int value = 100000; //amout of tested numbers
int value2 = 10; //range of tested numbers (maximum value possible)
int[]Counter = new int [value+1];
int[] Random;
Random = new int[value+1];
int count = 0;
double average = 0;
int Max = value2;
int Min = 0;
int sum = 0;
int number = 0;
double median = 0;
int mode = 0;
double dev = 0;
double acc = 0;
for (count = 0; count < value; count++)
{
number = (int)(Math.random()*value2+1);
Random[count] = number;
sum = sum + number;
}
average = (double)sum/(double)value;
System.out.println(value+" randomly generated numbers from 0 to "+value2);
System.out.println("In Ascending Order:");
Arrays.sort(Random);
for (count = 0; count < value; count++)
{
//comenmt out
// System.out.println(Random[count]);
while(Random[count]>Max)
Max=Random[count];
while(Random[count]<Min)
Min=Random[count];
median=Random[value/2];
}
for (int k = 0; k < value; k++)
{
Counter[Random[k]] =Counter[Random[k]]+1;
}
for (int k = 0; k < value; k++)
{
acc = acc + (Random[k]-average)*(Random[k]-average);
}
average= average-.5;
dev = Math.sqrt(acc/value);
mode=getMaximum(Counter);
System.out.println("The highest number is " + Max);
System.out.println("The lowest number is " + Min);
System.out.println("The median is "+median+".");
System.out.println("The average is: " +average);
System.out.println("The mode is "+mode);
System.out.println("The standard deviation is "+dev);
new MainAsd().startStuff();
}
public void startStuff(){
new DataOutput();
}
}
Try to indendate the code decently the next time please =)
#3
Posted 23 March 2011 - 11:27 AM
Thanks a lot for the help but i still have a problem. I forgot to remove the quotations around the variable names. as of right now the program will not allow me to assign variables to the JTextField. How could I fix this. Or could you possibly paste the code again I would really appreciate it. Heres the code with the removed quotes.
******************************************************************************************************************************************************
import java.awt.*;
import javax.swing.*;
import java.util.Arrays;
public class MainAsd
{
public static int getMaximum(int[] Random)
{
int max=0;
int[] toReturn = new int[Random.length+1];
for (int i = 0; i < Random.length; i++)
{
if ( Random[i] > toReturn[0])
{
toReturn[0] = Random[i];
max = i;
}
}
return max;
}
//starts here
public class DataOutput extends JFrame
{
private static final long serialVersionUID = -4480786588092262886L;
JLabel Mean2;
JLabel Median2;
JLabel Mode2;
JLabel Min2;
JLabel max2;
JTextField min1;
JTextField mode1;
JTextField max1;
JTextField median1;
JTextField Mean1;
JLabel OutputData1;
JButton Ok;
JLabel SD;
JTextField SD1;
public DataOutput() {
DataOutputLayout customLayout = new DataOutputLayout();
getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 14));
getContentPane().setLayout(customLayout);
Mean2 = new JLabel("Mean");
getContentPane().add(Mean2);
Median2 = new JLabel("Median");
getContentPane().add(Median2);
Mode2 = new JLabel("Mode");
getContentPane().add(Mode2);
Min2 = new JLabel("Minnimum");
getContentPane().add(Min2);
max2 = new JLabel("Maximum");
getContentPane().add(max2);
min1 = new JTextField(Min);
getContentPane().add(min1);
mode1 = new JTextField(mode);
getContentPane().add(mode1);
max1 = new JTextField(Max);
getContentPane().add(max1);
median1 = new JTextField(median);
getContentPane().add(median1);
Mean1 = new JTextField(average);
getContentPane().add(Mean1);
OutputData1 = new JLabel(" OutputData");
getContentPane().add(OutputData1);
Ok = new JButton("Ok");
getContentPane().add(Ok);
SD = new JLabel("Standard Deviation");
getContentPane().add(SD);
SD1 = new JTextField(dev);
getContentPane().add(SD1);
pack();
setVisible(true);
}
}
class DataOutputLayout implements LayoutManager {
public DataOutputLayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInsets();
dim.width = 175 + insets.left + insets.right;
dim.height = 350 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+96,72,24);}
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+128,72,24);}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+160,72,24);}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+224,72,24);}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+192,72,24);}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+224,72,24); }
c = parent.getComponent(6);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+160,72,24); }
c = parent.getComponent(7);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+192,72,24); }
c = parent.getComponent(8);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+128,72,24); }
c = parent.getComponent(9);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+96,72,24);}
c = parent.getComponent(10);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+16,152,64);}
c = parent.getComponent(11);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+288,152,48); }
c = parent.getComponent(12);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+256,72,24);}
c = parent.getComponent(13);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+256,72,24); }
}
}
//ends here
public static void main(String[] args)
{
int value = 100000; //amout of tested numbers
int value2 = 10; //range of tested numbers (maximum value possible)
int[]Counter = new int [value+1];
int[] Random;
Random = new int[value+1];
int count = 0;
double average = 0;
int Max = value2;
int Min = 0;
int sum = 0;
int number = 0;
double median = 0;
int mode = 0;
double dev = 0;
double acc = 0;
for (count = 0; count < value; count++)
{
number = (int)(Math.random()*value2+1);
Random[count] = number;
sum = sum + number;
}
average = (double)sum/(double)value;
System.out.println(value+" randomly generated numbers from 0 to "+value2);
System.out.println("In Ascending Order:");
Arrays.sort(Random);
for (count = 0; count < value; count++)
{
//comenmt out
// System.out.println(Random[count]);
while(Random[count]>Max)
Max=Random[count];
while(Random[count]<Min)
Min=Random[count];
median=Random[value/2];
}
for (int k = 0; k < value; k++)
{
Counter[Random[k]] =Counter[Random[k]]+1;
}
for (int k = 0; k < value; k++)
{
acc = acc + (Random[k]-average)*(Random[k]-average);
}
average= average-.5;
dev = Math.sqrt(acc/value);
mode=getMaximum(Counter);
System.out.println("The highest number is " + Max);
System.out.println("The lowest number is " + Min);
System.out.println("The median is "+median+".");
System.out.println("The average is: " +average);
System.out.println("The mode is "+mode);
System.out.println("The standard deviation is "+dev);
new MainAsd().startStuff();
}
public void startStuff(){
new DataOutput();
}
******************************************************************************************************************************************************
import java.awt.*;
import javax.swing.*;
import java.util.Arrays;
public class MainAsd
{
public static int getMaximum(int[] Random)
{
int max=0;
int[] toReturn = new int[Random.length+1];
for (int i = 0; i < Random.length; i++)
{
if ( Random[i] > toReturn[0])
{
toReturn[0] = Random[i];
max = i;
}
}
return max;
}
//starts here
public class DataOutput extends JFrame
{
private static final long serialVersionUID = -4480786588092262886L;
JLabel Mean2;
JLabel Median2;
JLabel Mode2;
JLabel Min2;
JLabel max2;
JTextField min1;
JTextField mode1;
JTextField max1;
JTextField median1;
JTextField Mean1;
JLabel OutputData1;
JButton Ok;
JLabel SD;
JTextField SD1;
public DataOutput() {
DataOutputLayout customLayout = new DataOutputLayout();
getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 14));
getContentPane().setLayout(customLayout);
Mean2 = new JLabel("Mean");
getContentPane().add(Mean2);
Median2 = new JLabel("Median");
getContentPane().add(Median2);
Mode2 = new JLabel("Mode");
getContentPane().add(Mode2);
Min2 = new JLabel("Minnimum");
getContentPane().add(Min2);
max2 = new JLabel("Maximum");
getContentPane().add(max2);
min1 = new JTextField(Min);
getContentPane().add(min1);
mode1 = new JTextField(mode);
getContentPane().add(mode1);
max1 = new JTextField(Max);
getContentPane().add(max1);
median1 = new JTextField(median);
getContentPane().add(median1);
Mean1 = new JTextField(average);
getContentPane().add(Mean1);
OutputData1 = new JLabel(" OutputData");
getContentPane().add(OutputData1);
Ok = new JButton("Ok");
getContentPane().add(Ok);
SD = new JLabel("Standard Deviation");
getContentPane().add(SD);
SD1 = new JTextField(dev);
getContentPane().add(SD1);
pack();
setVisible(true);
}
}
class DataOutputLayout implements LayoutManager {
public DataOutputLayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInsets();
dim.width = 175 + insets.left + insets.right;
dim.height = 350 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+96,72,24);}
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+128,72,24);}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+160,72,24);}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+224,72,24);}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+192,72,24);}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+224,72,24); }
c = parent.getComponent(6);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+160,72,24); }
c = parent.getComponent(7);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+192,72,24); }
c = parent.getComponent(8);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+128,72,24); }
c = parent.getComponent(9);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+96,72,24);}
c = parent.getComponent(10);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+16,152,64);}
c = parent.getComponent(11);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+288,152,48); }
c = parent.getComponent(12);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+256,72,24);}
c = parent.getComponent(13);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+256,72,24); }
}
}
//ends here
public static void main(String[] args)
{
int value = 100000; //amout of tested numbers
int value2 = 10; //range of tested numbers (maximum value possible)
int[]Counter = new int [value+1];
int[] Random;
Random = new int[value+1];
int count = 0;
double average = 0;
int Max = value2;
int Min = 0;
int sum = 0;
int number = 0;
double median = 0;
int mode = 0;
double dev = 0;
double acc = 0;
for (count = 0; count < value; count++)
{
number = (int)(Math.random()*value2+1);
Random[count] = number;
sum = sum + number;
}
average = (double)sum/(double)value;
System.out.println(value+" randomly generated numbers from 0 to "+value2);
System.out.println("In Ascending Order:");
Arrays.sort(Random);
for (count = 0; count < value; count++)
{
//comenmt out
// System.out.println(Random[count]);
while(Random[count]>Max)
Max=Random[count];
while(Random[count]<Min)
Min=Random[count];
median=Random[value/2];
}
for (int k = 0; k < value; k++)
{
Counter[Random[k]] =Counter[Random[k]]+1;
}
for (int k = 0; k < value; k++)
{
acc = acc + (Random[k]-average)*(Random[k]-average);
}
average= average-.5;
dev = Math.sqrt(acc/value);
mode=getMaximum(Counter);
System.out.println("The highest number is " + Max);
System.out.println("The lowest number is " + Min);
System.out.println("The median is "+median+".");
System.out.println("The average is: " +average);
System.out.println("The mode is "+mode);
System.out.println("The standard deviation is "+dev);
new MainAsd().startStuff();
}
public void startStuff(){
new DataOutput();
}
#4
Posted 23 March 2011 - 11:31 AM
Sorry i forgot to indent it. when I Ctrl-C, Ctrl-V it it just puts it in a straight line. How did you get in in the scroll box like you did. did you use the wrap code button?
#5
Posted 23 March 2011 - 11:51 AM
Yeah I used the code button.
Anyway I didn't understand what the problem is now. Could you specify the line that's giving you problems?
Anyway I didn't understand what the problem is now. Could you specify the line that's giving you problems?
#6
Posted 23 March 2011 - 11:55 AM
7 errors found:
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 62]
Error: Min cannot be resolved to a variable
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 65]
Error: mode cannot be resolved to a variable
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 68]
Error: Max cannot be resolved to a variable
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 71]
Error: median cannot be resolved to a variable
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 74]
Error: average cannot be resolved to a variable
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 86]
Error: dev cannot be resolved to a variable
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 222]
Error: Syntax error, insert "}" to complete ClassBody
ill color them in
*****************************************************************************************
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 62]
Error: Min cannot be resolved to a variable
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 65]
Error: mode cannot be resolved to a variable
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 68]
Error: Max cannot be resolved to a variable
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 71]
Error: median cannot be resolved to a variable
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 74]
Error: average cannot be resolved to a variable
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 86]
Error: dev cannot be resolved to a variable
File: C:\Users\parents\Desktop\Colton\Science fair\MainAsd.java [line: 222]
Error: Syntax error, insert "}" to complete ClassBody
ill color them in
*****************************************************************************************
import java.awt.*;
import javax.swing.*;
import java.util.Arrays;
public class MainAsd
{
public static int getMaximum(int[] Random)
{
int max=0;
int[] toReturn = new int[Random.length+1];
for (int i = 0; i < Random.length; i++)
{
if ( Random[i] > toReturn[0])
{
toReturn[0] = Random[i];
max = i;
}
}
return max;
}
//starts here
public class DataOutput extends JFrame
{
private static final long serialVersionUID = -4480786588092262886L;
JLabel Mean2;
JLabel Median2;
JLabel Mode2;
JLabel Min2;
JLabel max2;
JTextField min1;
JTextField mode1;
JTextField max1;
JTextField median1;
JTextField Mean1;
JLabel OutputData1;
JButton Ok;
JLabel SD;
JTextField SD1;
public DataOutput() {
DataOutputLayout customLayout = new DataOutputLayout();
getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 14));
getContentPane().setLayout(customLayout);
Mean2 = new JLabel("Mean");
getContentPane().add(Mean2);
Median2 = new JLabel("Median");
getContentPane().add(Median2);
Mode2 = new JLabel("Mode");
getContentPane().add(Mode2);
Min2 = new JLabel("Minnimum");
getContentPane().add(Min2);
max2 = new JLabel("Maximum");
getContentPane().add(max2);
[COLOR="yellow"] min1 = new JTextField(Min);[/COLOR]
getContentPane().add(min1);
[COLOR="yellow"] mode1 = new JTextField(mode);[/COLOR]
getContentPane().add(mode1);
[COLOR="yellow"]max1 = new JTextField(Max);[/COLOR]
getContentPane().add(max1);
[COLOR="yellow"] median1 = new JTextField(median);[/COLOR]
getContentPane().add(median1);
[COLOR="yellow"]Mean1 = new JTextField(average);[/COLOR]
getContentPane().add(Mean1);
OutputData1 = new JLabel(" OutputData");
getContentPane().add(OutputData1);
Ok = new JButton("Ok");
getContentPane().add(Ok);
SD = new JLabel("Standard Deviation");
getContentPane().add(SD);
[COLOR="yellow"]SD1 = new JTextField(dev);[/COLOR]
getContentPane().add(SD1);
pack();
setVisible(true);
}
}
class DataOutputLayout implements LayoutManager {
public DataOutputLayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInsets();
dim.width = 175 + insets.left + insets.right;
dim.height = 350 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+96,72,24);}
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+128,72,24);}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+160,72,24);}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+224,72,24);}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+192,72,24);}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+224,72,24); }
c = parent.getComponent(6);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+160,72,24); }
c = parent.getComponent(7);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+192,72,24); }
c = parent.getComponent(8);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+128,72,24); }
c = parent.getComponent(9);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+96,72,24);}
c = parent.getComponent(10);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+16,152,64);}
c = parent.getComponent(11);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+288,152,48); }
c = parent.getComponent(12);
if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+256,72,24);}
c = parent.getComponent(13);
if (c.isVisible()) {c.setBounds(insets.left+88,insets.top+256,72,24); }
}
}
//ends here
public static void main(String[] args)
{
int value = 100000; //amout of tested numbers
int value2 = 10; //range of tested numbers (maximum value possible)
int[]Counter = new int [value+1];
int[] Random;
Random = new int[value+1];
int count = 0;
double average = 0;
int Max = value2;
int Min = 0;
int sum = 0;
int number = 0;
double median = 0;
int mode = 0;
double dev = 0;
double acc = 0;
for (count = 0; count < value; count++)
{
number = (int)(Math.random()*value2+1);
Random[count] = number;
sum = sum + number;
}
average = (double)sum/(double)value;
System.out.println(value+" randomly generated numbers from 0 to "+value2);
System.out.println("In Ascending Order:");
Arrays.sort(Random);
for (count = 0; count < value; count++)
{
//comenmt out
// System.out.println(Random[count]);
while(Random[count]>Max)
Max=Random[count];
while(Random[count]<Min)
Min=Random[count];
median=Random[value/2];
}
for (int k = 0; k < value; k++)
{
Counter[Random[k]] =Counter[Random[k]]+1;
}
for (int k = 0; k < value; k++)
{
acc = acc + (Random[k]-average)*(Random[k]-average);
}
average= average-.5;
dev = Math.sqrt(acc/value);
mode=getMaximum(Counter);
System.out.println("The highest number is " + Max);
System.out.println("The lowest number is " + Min);
System.out.println("The median is "+median+".");
System.out.println("The average is: " +average);
System.out.println("The mode is "+mode);
System.out.println("The standard deviation is "+dev);
new MainAsd().startStuff();
}
public void startStuff(){
new DataOutput();
[COLOR="yellow"] }[/COLOR]
#7
Posted 23 March 2011 - 11:56 AM
Fail I should of used a darker color. haha
#8
Posted 23 March 2011 - 11:58 AM
Of course it's giving you problems:
The variable Min doesn't exist!
min1 = new JTextField(Min);
The variable Min doesn't exist!
#9
Posted 23 March 2011 - 11:58 AM
For the last error I fixed it by just adding an extra } bracket. but the other 6 I need help with. Maybe its that the jframe class comes before the main? idk. But i relay need to get this fixed. haha.
#10
Posted 23 March 2011 - 12:00 PM
But all of them are declared in main. I want the variables from main to be put into the jframe.
The problem is main comes after the jframe class so when it looks for the variables they dont exist til later. would this be a hard fix?
The problem is main comes after the jframe class so when it looks for the variables they dont exist til later. would this be a hard fix?
#11
Posted 23 March 2011 - 12:01 PM
Java is looking for a variable called Min (and mode, and Max, and median), but they don't exist! You haven't declared them before their use.
You need to do something like this:
or
got it?
You need to do something like this:
String Min="some ****"; min1 = new JTextField(Min);
or
min1 = new JTextField("some ****");
got it?
#12
Posted 23 March 2011 - 12:03 PM
You can't use in a method variables you've declared in another method
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









