Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Ok Im stuck where has my code went wrong

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ok Im stuck where has my code went wrong

    Im stuck I am trying to write a program that takes a chi squared test, however I get this error


    mixing_up.java:130: array required, but double found
    A2_CAL[I] = ALPHA2[I] / (1 + DELTA[J]*DELTA[J])*(B2F21 + 2*DELTA[J]*B2F22 + B2F23*Math.pow(DELTA[J],2));


    I dont know why, as I have declared delta as an array. Anyhelp would be appreciated.

    import javax.swing.JOptionPane; 
    import java.io.*;
    import java.util.*;
    import java.text.DecimalFormat;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.*;
    import java.io.File;
    import static java.lang.Math.*;
     
     
    public class mixing_up
    {
    public static void main(String[] args)
    {
    DecimalFormat fmt = new DecimalFormat("0.###E0"); //number of decimal places 3 and in scientific format
     
     
    JOptionPane.showMessageDialog (null, "<html> This program calculates the mixing ratio using the chi squared test");
    JOptionPane.showMessageDialog (null, "Written by me");
     
     
     StringBuilder results = new StringBuilder();
    String s,t,u,v,w,x,y,z,m,j,l,o,ap,bb,lo,q;
    s = JOptionPane.showInputDialog("Enter the value of alpha2: "); 
    double ALPHA2 = Double.parseDouble(s);
     
    t = JOptionPane.showInputDialog("Enter the value of alpha2 error: ");
    double DALPHA2 = Double.parseDouble(t);
     
    u= JOptionPane.showInputDialog(null,"Enter the value of alpha4: ");
    double ALPHA4 = Double.parseDouble(u);
     
    v= JOptionPane.showInputDialog("Enter the value of alpha4 error: ");
    double DALPHA4 = Double.parseDouble(v);
     
    w = JOptionPane.showInputDialog("Enter the value of A2/A0:");
    double A2_EXP = Double.parseDouble(w);
     
    x = JOptionPane.showInputDialog("Enter the value of A2/A0 error: ");
    double DA2 = Double.parseDouble(x);
     
    y = JOptionPane.showInputDialog("Enter the value of A4/A0: ");
    double A4_EXP = Double.parseDouble(y);
     
     
    z= JOptionPane.showInputDialog("Enter the value of A4/A0 error: ");
    double DA4 = Double.parseDouble(z);
     
     
    m =JOptionPane.showInputDialog("Enter the value of B2F2 (DD, 11): ");
    double B2F21 = Double.parseDouble(m);
     
    j =JOptionPane.showInputDialog("Enter the value of B2F2 (DQ, 12): ");
    double B2F22 = Double.parseDouble(j);
     
    l =JOptionPane.showInputDialog("Enter the value of B2F2 (QQ, 22): ");
    double B2F23 = Double.parseDouble(l);
     
    o =JOptionPane.showInputDialog("Enter the value of B4F4 (QQ): ");
    double B4F4 = Double.parseDouble(o);
     
    ap =JOptionPane.showInputDialog("Enter the lower limit for arctan(delta) (-90.lt.delta): ");
    double DL = Double.parseDouble(ap);
     
    bb =JOptionPane.showInputDialog("Enter the upper limit for arctan(delta) (delta.lt+90): ");
    double DU = Double.parseDouble(bb);
     
    lo =JOptionPane.showInputDialog("Enter the number of steps for arctan(delta) max 1000: ");
    double N = Double.parseDouble(lo);
     
    q =JOptionPane.showInputDialog("Please select from the following: To fit A2/A0 press 1. To fit A4/A0 press 2. To fit A2/A0 and A4/A0 press 3. ");
    double r = Double.parseDouble(q);
     
    double  CHI_UP = 1000000000;
    double  CHI_LOW = 1000000000;
    double  CHI_CENTER = 1000000000;
    double  Lun = 6;
    double ALPHA2_1 = ALPHA2-DALPHA2;
    double ALPHA2_3 = ALPHA2+DALPHA2;
    double ALPHA4_1 = ALPHA4-DALPHA4;
    double ALPHA4_3 = ALPHA4+DALPHA4;
    double [] A2_CAL;
    A2_CAL = new double[3];
    double [] DELTA;
    DELTA = new double[1001];
    double [] ANGLE;
    ANGLE = new double[1001];
    double [] ANGLE2;
    ANGLE2 = new double[1001];
    double []A4_CAL;
    A4_CAL = new double[3];
    double [] X2;
    X2 = new double[3];
    double[] LOGX2;
    LOGX2 = new double[1001];
    double[] CHI_2;
    CHI_2 = new double[1001]; 
    double DELTA_LOW; 
    double DELTA_UP; 
    double ANGLE_LOW; 
    double ANGLE_UP; 
    double DELTA_E_LOW; 
    double DELTA_E_UP; 
    double ANGLE_E_LOW; 
    double ANGLE_E_UP; 
    double CHI_E_LOW; 
    double CHI_E_UP; 
    double CHI_ERROR; 
    double DELTA_CENTER; 
    double ANGLE_CENTER; 
    double J_LOW; 
    double J_UP; 
    double J_CENTER;
     
     
     
    if (r == 1) {
    // put A2 only code here
    for(int J=1; J< N; J++)
    {
     
    ANGLE[J]= DL + (J-1)*((DU - DL)/N);
    ANGLE2[J] = ANGLE[J]/57.297;
    DELTA[J] =  Math.tan(ANGLE2[J]); 
     
     
    for(int I=1;  I < 4; I++)
    {
    A2_CAL[I] = ALPHA2[I] / (1 + DELTA[J]*DELTA[J])*(B2F21 + 2*DELTA[J]*B2F22 + B2F23*Math.pow(DELTA[J],2));
     
    X2[I] = Math.pow(A2_CAL[I] - A2_EXP,2) / Math.pow(DA2,2);
     
    }
     
    CHI_2[J] = X2[2];       
    LOGX2[J] = Math.log10(X2[2]);
     
    if (CHI_2[J] < CHI_CENTER)
    {
    CHI_CENTER = CHI_2[J];
    ANGLE_CENTER = ANGLE[J];
    DELTA_CENTER = DELTA[J];
    }
     
     
    if (X2[1] < CHI_LOW) 
    { 
    CHI_LOW = X2[1];
    ANGLE_UP = ANGLE[J];
    DELTA_UP = DELTA[J];
    }
     
    if (X2[3] < CHI_UP) 
    { 
    CHI_UP = X2[3];
    ANGLE_LOW = ANGLE[J];
    DELTA_LOW = DELTA[J];
    }
    }
     
    results.append("The values of X2(2) chi central i.e chi squared minimum " + fmt.format(CHI_CENTER) +  "");
    results.append('\n');
    results.append("The value of X2(1) chi squared lower limit is " + fmt.format(CHI_LOW) +  "");
    results.append('\n');
    results.append("The value of X2(3) chi squared upper limit is" + fmt.format(CHI_UP) +  "");
    results.append('\n');
    results.append("The value of Delta for chi central is " + fmt.format(DELTA_CENTER) +  "");
    results.append('\n');
    results.append("The value of Angle for chi central is " + fmt.format(ANGLE_CENTER) +  "");
     
     
    FileWriter resultFile = null;
     try {
                resultFile = new FileWriter("mixing_ratio.dat");
                resultFile.write(results.toString());
     
     
    	    resultFile.close();
            } catch (IOException ex) {
                Logger.getLogger(mixing_up.class.getName()).log(Level.SEVERE, null, ex);
            }
    	JOptionPane.showMessageDialog (null, "The values of X2(2) chi central i.e chi squared minimum " + fmt.format(CHI_CENTER) +  ""); 
    	JOptionPane.showMessageDialog (null, "The value of X2(1) chi squared lower limit is " + fmt.format(CHI_LOW) +  "");         
    	JOptionPane.showMessageDialog (null, "The value of X2(3) chi squared upper limit is " + fmt.format(CHI_UP) +  "");
    	JOptionPane.showMessageDialog (null, "The value of Delta for chi central is " + fmt.format(DELTA_CENTER) +  "" );
    	JOptionPane.showMessageDialog (null, "The value of Angle for chi central is " + fmt.format(ANGLE_CENTER) +  "" );
    	JOptionPane.showMessageDialog (null, "The value of chi squared central for a given value of delta is" + fmt.format(DELTA) +  "" );
     
     
     
     
    	JOptionPane.showMessageDialog (null, "Thank you for using the program the results are saved in mixing_ratio.dat" ); 
    	JOptionPane.showMessageDialog (null, "Have a Nice Day" ); 
     
     
    }
    }
     }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Ok Im stuck where has my code went wrong

    double ALPHA2 
    A2_CAL[I] = ALPHA2[I]
    Can you spot the problem?
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Ok Im stuck where has my code went wrong

    Ahh, Ok i got it, thanks buddy

Similar Threads

  1. completely stuck on a simple code
    By disp in forum Loops & Control Statements
    Replies: 6
    Last Post: June 30th, 2011, 12:02 PM
  2. Help!, newbie, interested in Java, Very simple code, completely stuck!
    By munkybunky in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 30th, 2011, 07:25 AM
  3. What is wrong with my code?
    By phantom06 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 3rd, 2011, 05:21 AM
  4. what's wrong in this code
    By Aravind in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 4th, 2011, 03:38 AM
  5. Help I'm stuck on code.
    By GreenM in forum Loops & Control Statements
    Replies: 3
    Last Post: January 29th, 2010, 09:27 PM