Jump to content

Urgent!!!!! Needs to be done by march 24th

- - - - -

  • Please log in to reply
4 replies to this topic

#1
coltonf93

coltonf93

    Newbie

  • Members
  • PipPip
  • 11 posts
I need help setting the variables from main in the frame class. There already properly named.

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
*****************************************************************************************

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]





#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Where do you declare Min?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
coltonf93

coltonf93

    Newbie

  • Members
  • PipPip
  • 11 posts
ya i declared it in main. but the jframe method comes b4 main. and i dont think the methods can comunicate with eachother without an object

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Something like

public void startStuff(int Min){

  new DataOutput(Min);

 }

perhaps.

#5
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP

coltonf93 said:

ya i declared it in main. but the jframe method comes b4 main. and i dont think the methods can comunicate with eachother without an object

It's not because the Jframe method comes before main, but because min is declared outside of the scope of the Jframe method.
Wim has a good solution that you should be able to work with but it'll only solve the problem with Min. You can :

1)add the rest of the variables to startStuff as parameters or
2)declare the variables you need as field variables.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users