943,568 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 300
  • Java RSS
Apr 20th, 2009
0

stuck

Expand Post »
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");
}

}

}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
frozon is offline Offline
2 posts
since Apr 2009
Apr 20th, 2009
0

Re: stuck

Last edited by JamesCherrill; Apr 20th, 2009 at 7:25 am.
Featured Poster
Reputation Points: 1907
Solved Threads: 948
Posting Expert
JamesCherrill is offline Offline
5,754 posts
since Apr 2008
Apr 20th, 2009
0

Re: stuck

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;
//{
}
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
zyaday is offline Offline
70 posts
since Jun 2008
Apr 21st, 2009
0

Re: stuck

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,
Reputation Points: 10
Solved Threads: 0
Newbie Poster
frozon is offline Offline
2 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: event handling prob
Next Thread in Java Forum Timeline: J2ME Bluetooth Master Slave Switch for Nokia





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC