hi am new to java and have a problem in displaying the x and y points on the graph to solve this ax3+bx2=x+d=0

here is the code

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
 * PROGRAM: Cubic
 * DESCRIPTION: This program solves the cubic Equation for a given range of values and plots the graph...  
 * AUTHOR: MUCHINDU ADAM
 * DATE WRITTEN: 05-04-09
 */
public class CubicEquation extends JApplet implements ActionListener
{
    private JLabel B1;
    private JLabel B2;
    private JTextField R1;
    private JLabel B3;
    private JTextField R2;
    private JLabel B4;
    private JTextField R3;
    private JLabel B5;
    private JTextField R4;
    private JLabel B6;
    private JTextField R5;
    private JLabel B7;
    private JTextField R6;
    private JLabel B8;
    private JLabel B9;
    private JButton B10;
    private JTextField R17;
    private JTextArea R7;



   public CubicEquation()
   {
        B1=new JLabel("                                            POLYNOMIAL SOLVER/CUBIC EQUATION                        ");
        B2=new JLabel("Enter the value of a:");
        R1=new JTextField(2);
        B3=new JLabel("Enter the value of b:");
        R2=new JTextField(2);
        B4=new JLabel("Enter the value of c:");
        R3=new JTextField(2);
        B5=new JLabel("Enter the value of d:");
        R4=new JTextField(2);
        B6=new JLabel("Enter the minimum value for the range of X");
        R5=new JTextField(2);
        B7=new JLabel("Enter the maximum value for the range of X");
        R6=new JTextField(2);
        B10=new JButton("SOLVE");
        R17=new JTextField(20);
        R7=new JTextArea();



          JPanel DE=new JPanel(new FlowLayout());
           DE.add(B2);
           DE.add(R1);
           DE.add(B3);
           DE.add(R2);
           DE.add(B4);
           DE.add(R3);
           DE.add(B5);
           DE.add(R4);

           JPanel ARK=new JPanel(new FlowLayout());
            ARK.add(B6);
            ARK.add(R5);
            ARK.add(B7);
            ARK.add(R6);

            JPanel ANS=new JPanel(new FlowLayout());
            ANS.add(B10);

            JPanel FIN=new JPanel(new FlowLayout());
            FIN.add(R7);
            FIN.add(R17);

          setLayout(new GridLayout(5,1));
            add(B1);
            add(DE);
            add(ARK);
            add(ANS);
            add(FIN);

            B10.addActionListener(this);// Puting a listener to button 10.
       }
       public void actionPerformed(ActionEvent e)
       {

            int[]x=new int[5];
            int index;
           //Geting the values of A to D and the range
           int A=Integer.parseInt(R1.getText());
           int B=Integer.parseInt(R2.getText());
           int C=Integer.parseInt(R3.getText());
           int D=Integer.parseInt(R4.getText());
           int Min=Integer.parseInt(R5.getText());
           int Max=Integer.parseInt(R6.getText());

          for(index=0;index < x.length;index++)
          {
              for(int i=Min;i<=Max;i++)
              {
               x[index]=i;
           //{ 
            }


          int F=0,G,H,i;
          int[]Ans=new int[5];


              // int y=7; 
              // int index =0;

                x[index]=F;
            for(F=0;F<x.length;F++)
              {

                Ans[index]=(A*(F*F*F)+B*(F*F)+C*(F)+D);
              // Ans[i]={A*(Min*Min*Min)+B*(Min*Min)+C*(Min)+D};

              //  int y=A*F+B*G+C*H+(D);
               // R7.setText(Integer.toString(y) + "\t");

                // Ans[index]++;

                   //for(Ans[0]=y;Ans[0]<Max-Min; Ans[0]++)

                       // R7.setText(Integer.toString(Ans.length)+"\t");
                    }

             if(e.getSource()==B10)
             {
                  //Ans[index]=y;
                  //for(F=y;F<=Max;F++)
                  //{
                   //for(index=1;index<=Ans.length;index++)
                  // {
                    R7.setText(Integer.toString(Ans[F])+"\t");
                    index--;
                    R17.setText(Integer.toString(Ans[2]));
                 //  R7.setText(Integer.toString(y) + "\t");
                    }

                   }

                }
            }

Recommended Answers

All 3 Replies

hi, i'm not sure what u want yor program to do. But in these lines where you used 2 for loops , the internal loop is doing really nothing, just assiging the maximum value to x [index].....
hope this will be of some help
for(index=0;index < x.length;index++)
{
for(int i=Min;i<=Max;i++)
{
x[index]=i;
//{
}

hi,the code is to calculate and store the result to the array,then it s now must pass the array to the graph which will produce a cubic cuvre,ploting of the graph is okey just puting the two together,the forloop works aright,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.