Results 1 to 10 of 10
  1. #1
    kaizen is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default [SOLVED] Java Class won't compile

    Hi,

    I have a java class that I am trying to compile but it keeps coming up with an error.

    The code is below and the errors I receive are:
    cannot find symbol class Probability line # 60
    cannot find symbol class Probability line # 325

    Both error lines are highlighted below in red.

    I have not written any java before so I am at a bit of a loss as to why it will not compile.

    It is saved as a class file called Probcalc.java



    Java Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    public class Probcalc extends Applet
        implements ActionListener
    {
    
        public void paint(Graphics g)
        {
            Color color = new Color(0, 0, 128);
            g.setColor(color);
            g.fill3DRect(5, 0, 660, 24, true);
            g.setColor(Color.blue);
            g.fill3DRect(5, 25, 280, 159, true);
            g.setColor(Color.gray);
            g.fill3DRect(5, 185, 280, 65, true);
            prompt1.setLocation(10, 30);
            input1.setLocation(185, 30);
            prompt2.setLocation(10, 55);
            input2.setLocation(185, 55);
            prompt3.setLocation(10, 80);
            input3.setLocation(185, 80);
            prompt4.setLocation(10, 105);
            input4.setLocation(185, 105);
            prompt5.setLocation(10, 130);
            input5.setLocation(185, 130);
            submit.setLocation(10, 160);
            g.setColor(Color.white);
            if(probability.lfTarget2 > 0.0D)
            {
                g.drawString("Probability of reaching above 1st target:", 10, 200);
                g.drawString(Double.toString(probability.lfUp) + "%", 240, 200);
                g.drawString("Probability of staying between targets:", 10, 220);
                g.drawString(Double.toString(probability.lfRange) + "%", 240, 220);
                g.drawString("Probability of reaching below 2nd target:", 10, 240);
                g.drawString(Double.toString(probability.lfLow) + "%", 240, 240);
            } else
            {
                g.drawString("Probability of reaching above target:", 10, 200);
                g.drawString(Double.toString(probability.lfUp) + "%", 240, 200);
                g.drawString("Probability of staying between targets:", 10, 220);
                g.drawString(Double.toString(probability.lfRange) + "%", 240, 220);
                g.drawString("Probability of reaching below target:", 10, 240);
                g.drawString(Double.toString(probability.lfLow) + "%", 240, 240);
            }
            g.setColor(Color.white);
            g.drawString("Online Probability Calculator", 10, 16);
            g.setColor(Color.black);
            g.drawString("(c) 2000", 10, 265);
            g.drawString("All rights reserved.", 10, 285);
            drawBellShapedCurve(g);
        }
    
        public Probcalc()
       	{
            [COLOR="Red"][B]probability = new Probability();[/B][/COLOR]
        }
    
        public void actionPerformed(ActionEvent actionevent)
        {
            Double double1 = new Double(0.0D);
            String s = new String();
            double1 = Double.valueOf(input1.getText());
            probability.lfPrice = double1.doubleValue();
            double1 = Double.valueOf(input2.getText());
            probability.lfDays = double1.doubleValue();
            double1 = Double.valueOf(input3.getText());
            probability.lfVolatility = double1.doubleValue();
            probability.lfVolatility /= 100D;
            double1 = Double.valueOf(input4.getText());
            probability.lfTarget1 = double1.doubleValue();
            s = input5.getText();
            if(s.length() <= 0)
            {
                probability.lfTarget2 = 0.0D;
            } else
            {
                Double double2 = Double.valueOf(input5.getText());
                probability.lfTarget2 = double2.doubleValue();
            }
            if(probability.Calculate() == 1)
                repaint();
        }
    
        public void init()
        {
            setBackground(Color.white);
            prompt1 = new Label("Underlying price:");
            prompt1.setBackground(Color.blue);
            prompt1.setForeground(Color.white);
            add(prompt1);
            input1 = new TextField(10);
            input1.setText("100");
            add(input1);
            prompt2 = new Label("Target days:");
            prompt2.setBackground(Color.blue);
            prompt2.setForeground(Color.white);
            add(prompt2);
            input2 = new TextField(10);
            input2.setText("125");
            add(input2);
            prompt3 = new Label("Volatility estimate:");
            prompt3.setBackground(Color.blue);
            prompt3.setForeground(Color.white);
            add(prompt3);
            input3 = new TextField(10);
            input3.setText("25.00");
            add(input3);
            prompt4 = new Label("Target Price 1 (Upper):");
            prompt4.setBackground(Color.blue);
            prompt4.setForeground(Color.white);
            add(prompt4);
            input4 = new TextField(10);
            input4.setText("115");
            add(input4);
            prompt5 = new Label("Target Price 2 (Lower):");
            prompt5.setBackground(Color.blue);
            prompt5.setForeground(Color.white);
            add(prompt5);
            input5 = new TextField(10);
            input5.setText("85");
            add(input5);
            submit = new Button("Calculate");
            submit.addActionListener(this);
            add(submit);
        }
    
        private void drawBellShapedCurve(Graphics g)
        {
            Rectangle rectangle = new Rectangle();
            Rectangle rectangle1 = new Rectangle();
            int ai[] = new int[24];
            int ai1[] = new int[24];
            int ai2[] = new int[24];
            int ai3[] = new int[24];
            double d3 = 0.0D;
            double d8 = 0.0D;
            int i = 0;
            int l = 0;
            rectangle.x = 340;
            rectangle.y = 35;
            rectangle.width = 320;
            rectangle.height = 200;
            double d = rectangle.width / 2 + rectangle.x;
            double d1 = 0.025000000000000001D * (double)rectangle.width;
            double d2 = ((double)rectangle.height / (1.0D / Math.sqrt(6.2831853071795862D))) * Math.exp((-1D * Math.pow(0.0D, 2D)) / 11D);
            rectangle1.x = rectangle.x;
            d8 = (1.0D / Math.sqrt(6.2831853071795862D)) * Math.exp((-1D * Math.pow(0.0D, 2D)) / 11D) * d2;
            rectangle1.y = (rectangle.y + rectangle.height) - (int)d8;
            rectangle1.width = rectangle.width;
            rectangle1.height = rectangle.height;
            g.setColor(Color.white);
            g.fillRect(rectangle1.x, rectangle1.y, rectangle1.width, rectangle1.height);
            g.setColor(Color.black);
            g.drawLine(rectangle.x, rectangle.y + rectangle.height, rectangle.x + rectangle.width, rectangle.y + rectangle.height);
            d8 = (1.0D / Math.sqrt(6.2831853071795862D)) * Math.exp(-Math.pow(0.0D, 2D) / 11D) * d2;
            g.drawLine(rectangle.x + rectangle.width, rectangle.y + rectangle.height, rectangle.x + rectangle.width, (int)((double)(rectangle.y + rectangle.height) - d8));
            g.drawLine(rectangle.x + rectangle.width, (int)((double)(rectangle.y + rectangle.height) - d8), rectangle.x, (int)((double)(rectangle.y + rectangle.height) - d8));
            g.drawLine(rectangle.x, (int)((double)(rectangle.y + rectangle.height) - d8), rectangle.x, rectangle.y + rectangle.height);
            d3 = ((double)rectangle.y + (double)rectangle.height) / 8D - (((double)rectangle.y + (double)rectangle.height) - d8) / 8D;
            i = 1;
            do
            {
                g.setColor(Color.gray);
                g.drawLine(rectangle.x + 1, (int)((double)(rectangle.y + rectangle.height) - d3 * (double)i), (rectangle.x + rectangle.width) - 1, (int)((double)(rectangle.y + rectangle.height) - d3 * (double)i));
                g.setColor(Color.black);
                g.drawLine(rectangle.x - 1, (int)((double)(rectangle.y + rectangle.height) - d3 * (double)i), rectangle.x - 5, (int)((double)(rectangle.y + rectangle.height) - d3 * (double)i));
            } while(++i < 8);
            d3 = (rectangle.x + rectangle.width) / 8 - rectangle.x / 8;
            i = 1;
            do
            {
                g.setColor(Color.gray);
                g.drawLine((int)((double)rectangle.x + d3 * (double)i), (int)(((double)(rectangle.y + rectangle.height) - d8) + 1.0D), (int)((double)rectangle.x + d3 * (double)i), (rectangle.y + rectangle.height) - 1);
                g.setColor(Color.black);
                g.drawLine((int)((double)rectangle.x + d3 * (double)i), rectangle.y + rectangle.height, (int)((double)rectangle.x + d3 * (double)i), rectangle.y + rectangle.height + 4);
            } while(++i < 8);
            ai1[0] = (int)(-1D * ((1.0D / Math.sqrt(6.2831853071795862D)) * Math.exp((-1D * Math.pow(0.0D, 2D)) / 11D) * d2)) + rectangle.y + rectangle.height;
            ai[0] = (int)d;
            ai1[1] = rectangle.y;
            ai[1] = (int)(d - d1);
            i = 1;
            do
            {
                d8 = (1.0D / Math.sqrt(6.2831853071795862D)) * Math.exp((-1D * Math.pow(i, 2D)) / 11D) * d2;
                ai[i + 1] = (int)((double)(-i * (rectangle.width / 21)) + d);
                ai1[i + 1] = (int)(-d8 + (double)rectangle.y + (double)rectangle.height);
            } while(++i < 10);
            ai1[11] = rectangle.y + rectangle.height;
            ai[11] = (int)d;
            d8 = (1.0D / Math.sqrt(6.2831853071795862D)) * Math.exp((-1D * Math.pow(0.0D, 2D)) / 11D) * d2;
            ai1[12] = rectangle.y;
            ai[12] = (int)d;
            ai1[13] = rectangle.y;
            ai[13] = (int)(d + d1);
            i = 1;
            do
            {
                double d9 = (1.0D / Math.sqrt(6.2831853071795862D)) * Math.exp((-1D * Math.pow(i, 2D)) / 11D) * d2;
                ai[i + 13] = (int)((double)(i * (rectangle.width / 21)) + d);
                ai1[i + 13] = (int)(-d9 + (double)rectangle.y + (double)rectangle.height);
            } while(++i < 10);
            ai[23] = (int)d;
            ai1[23] = rectangle.y + rectangle.height;
            g.setColor(Color.blue);
            l = 0;
            i = 10;
            do
            {
                ai2[l] = ai[i];
                ai3[l] = ai1[i];
                l++;
            } while(--i > 0);
            i = 12;
            do
            {
                ai2[l] = ai[i];
                ai3[l] = ai1[i];
                l++;
            } while(++i < 23);
            ai2[l] = ai2[0];
            ai3[l] = ai3[0];
            g.drawPolygon(ai2, ai3, 22);
            g.fillPolygon(ai2, ai3, 22);
            g.setColor(Color.black);
            i = 0;
            do
            {
                double d4 = (double)i * 0.050000000000000003D;
                d4 *= 100D;
                d4 = Math.round(d4);
                d4 /= 100D;
                g.drawString(Double.toString(d4), rectangle.x - 30, (rectangle.y + rectangle.height + 5) - i * (rectangle.height / 8));
            } while(++i < 9);
            i = -4;
            do
            {
                double d5 = i;
                double d10 = Math.exp(probability.lfVolatility * Math.sqrt(probability.lfDays / 365D) * d5) * probability.lfPrice;
                d10 *= 100D;
                d10 = Math.round(d10);
                d10 /= 100D;
                g.drawString(Double.toString(d10), (rectangle.x - 16) + ((i + 4) * rectangle.width) / 8, rectangle.y + rectangle.height + 20);
            } while(++i <= 4);
            if(probability.lfTarget1 > 0.0D)
            {
                int ai4[] = new int[24];
                int ai6[] = new int[24];
                Color color = new Color(192, 192, 192);
                double d13 = Math.log(probability.lfTarget1 / probability.lfPrice) / (probability.lfVolatility * Math.sqrt(probability.lfDays / 365D));
                double d6 = d13;
                d6 = d6 * (double)(rectangle.width / 8) + d;
                int j = 0;
                boolean flag = false;
                do
                    if(ai2[j] >= (int)d6)
                    {
                        double d11 = -1D * ((1.0D / Math.sqrt(6.2831853071795862D)) * Math.exp(-Math.pow(2.6499999999999999D * d13, 2D) / 11D) * d2) + (double)rectangle.y + (double)rectangle.height;
                        ai6[j] = (int)d11;
                        ai4[j] = (int)d6;
                        ai4[j + 1] = (int)d6;
                        ai6[j + 1] = rectangle.y + rectangle.height;
                        ai4[j + 2] = rectangle.x;
                        ai6[j + 2] = rectangle.y + rectangle.height;
                        flag = true;
                    } else
                    {
                        ai4[j] = ai2[j];
                        ai6[j] = ai3[j];
                        j++;
                    }
                while(!flag && j < 22);
                g.setColor(color);
                g.drawPolygon(ai4, ai6, j + 3);
                g.fillPolygon(ai4, ai6, j + 3);
            }
            if(probability.lfTarget2 > 0.0D)
            {
                int ai5[] = new int[24];
                int ai7[] = new int[24];
                Color color1 = new Color(0, 0, 255);
                double d14 = Math.log(probability.lfTarget2 / probability.lfPrice) / (probability.lfVolatility * Math.sqrt(probability.lfDays / 365D));
                double d7 = d14;
                d7 = d7 * (double)(rectangle.width / 8) + d;
                int k = 0;
                boolean flag1 = false;
                do
                    if(ai2[k] >= (int)d7)
                    {
                        double d12 = -1D * ((1.0D / Math.sqrt(6.2831853071795862D)) * Math.exp(-Math.pow(2.6499999999999999D * d14, 2D) / 11D) * d2) + (double)rectangle.y + (double)rectangle.height;
                        ai7[k] = (int)d12;
                        ai5[k] = (int)d7;
                        ai5[k + 1] = (int)d7;
                        ai7[k + 1] = rectangle.y + rectangle.height;
                        ai5[k + 2] = rectangle.x;
                        ai7[k + 2] = rectangle.y + rectangle.height;
                        flag1 = true;
                    } else
                    {
                        ai5[k] = ai2[k];
                        ai7[k] = ai3[k];
                        k++;
                    }
                while(!flag1 && k < 22);
                g.setColor(color1);
                g.fillPolygon(ai5, ai7, k + 3);
            }
        }
    
        Label prompt1;
        Label prompt2;
        Label prompt3;
        Label prompt4;
        Label prompt5;
        TextField input1;
        TextField input2;
        TextField input3;
        TextField input4;
        TextField input5;
        Button submit;
        [COLOR="Red"][B]Probability probability;[/B][/COLOR]
    }

    Any ideas?

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    There is a java file name Probability, and the compiler is not able to find it in the same location. Check that file is available or not.

    Java Code:
     probability = new Probability();
    This is wrong way of defining and initialization of an object. You should study more about the basis of Java.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    compiler is not able to find it in the same location.
    That could be expanded to
    The compiler looks on its classpath to find the definition of a class.

  4. #4
    kaizen is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    There is a java file name Probability, and the compiler is not able to find it in the same location. Check that file is available or not.

    Java Code:
     probability = new Probability();
    This is wrong way of defining and initialization of an object. You should study more about the basis of Java.
    OK. Got it working now.

    What is wrong with
    Java Code:
     probability = new Probability();
    I have no need to go studying JAVA as this is a once off.

    Thanks

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    What is wrong with
    It looks ok, provided that it is correctly placed in the program and that everything is defined and in scope that needs be.
    this is a once off.
    What does that mean?

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by kaizen View Post
    What is wrong with
    Java Code:
     probability = new Probability();
    Yes, it's ok. But the place seems to me not correct. Did you get any compile errors there.

  7. #7
    kaizen is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    All working now thanks.

    I mean it is once off as I normally write C# code

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  9. #9
    kaizen is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    Iit is solved but I have no idea where the mark as solved button is...

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 5
    Last Post: 11-20-2011, 10:22 PM
  2. My Java program will not compile and run?
    By sabrown311313 in forum Java Applets
    Replies: 1
    Last Post: 09-23-2008, 10:38 AM
  3. class or interface expected -compile err
    By ravi503 in forum Java Servlet
    Replies: 1
    Last Post: 03-26-2008, 12:45 PM
  4. Replies: 0
    Last Post: 02-17-2008, 09:57 AM
  5. Help with Java Compile File
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •