| | |
stuck
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Apr 2009
Posts: 2
Reputation:
Solved Threads: 0
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");
}
}
}
}
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");
}
}
}
}
•
•
Join Date: Apr 2008
Posts: 1,030
Reputation:
Solved Threads: 153
http://www.daniweb.com/forums/thread187065.html may be useful to you
Last edited by JamesCherrill; Apr 20th, 2009 at 7:25 am.
•
•
Join Date: Jun 2008
Posts: 46
Reputation:
Solved Threads: 1
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;
//{
}
hope this will be of some help
for(index=0;index < x.length;index++)
{
for(int i=Min;i<=Max;i++)
{
x[index]=i;
//{
}
![]() |
Similar Threads
- Windows XP is stuck! (Windows NT / 2000 / XP)
- Advertisment icons stuck to my desktop!!! (Viruses, Spyware and other Nasties)
- Stuck writing a Function (C++)
- error message when shutting down, startup page stuck to http://dr-search4u.com/ind... (Viruses, Spyware and other Nasties)
- Stuck In Restart Loop (Windows NT / 2000 / XP)
- Help with Class, stuck. (C++)
- CPU use stuck at 100% (Viruses, Spyware and other Nasties)
- Stuck on start up (Windows NT / 2000 / XP)
- Internet explorer 5 gets stuck (Web Browsers)
- stuck in lower case, lost functions (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: event handling prob
- Next Thread: J2ME Bluetooth Master Slave Switch for Nokia
Views: 246 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arguments array arrays automation bidirectional binary birt bluetooth calculator chat class classes client code columns component database designadrawingapplicationusingjavajslider detection draw eclipse editor error errors event exception expand file fractal game givemetehcodez graphics gui guidancer helpwithhomework html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jmf jni jpanel julia linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie number object oracle os plazmic print problem program programming project recursion scanner screen server set signing size smart sms smsspam socket sort sql string subclass support swing test threads time transfer tree windows






