guys I have to write a code and create an applet that asks the user to enter a seq of doubles and give a value for X0 and the program should create a a polynomial and evaluate it for the given X0.
For example: if the user enter 4.3 2 6.8 8 -3 1 5 0, the polynomial is 4.3X^2 + 6.8X^8 -3X + 5.
The compilation goes fine, but when I execute, it gives me the following exception:
java.lang.NoSuchMethodError: main
Exception in thread "main"
Process completed.
CODE
public class DoubleNode
{
private double data;
private DoubleNode link;
public DoubleNode(double d, DoubleNode l)
{
data = d;
link = l;
}
public DoubleNode(double d)
{
data = d;
}
// access to fields
public double getData()
{
return data;
}
public DoubleNode getLink()
{
return link;
}
// modify fields
public void setData(double dd)
{
data = dd;
}
public void setLink(DoubleNode dl)
{
link = dl;
}
}
CODE
public class DoubleSeq implements Cloneable
{
private DoubleNode head;
private int listcount;
private DoubleNode link;
private DoubleNode current;
public DoubleSeq()
{
head = null;
listcount = 0;
}
public DoubleSeq(double data)
{
head = new DoubleNode(data);
listcount = 1;
}
public DoubleNode getHead()
{
return head;
}
public DoubleNode getCurrent()
{
return current;
}
public void addAfter(double element)
{
link = new DoubleNode(element, link);
}
public void addAll(DoubleSeq ds)
{
DoubleNode cursor = head;
while(cursor.getLink() != null)
cursor = cursor.getLink();
cursor.setLink(ds.getHead());
int dscount = 0;
while(cursor.getLink() != null)
{
dscount++;
}
listcount = listcount + dscount;
}
public void addBefore(double element)
{
DoubleNode cur = head;
while(cur.getData() == element)
{
cur = new DoubleNode(element, cur);
}
}
public void advance()
{
current = current.getLink();
}
public DoubleSeq catenation(DoubleSeq s1, DoubleSeq s2)
{
DoubleSeq s;
if(s1 == null)
s = s2;
if(s2 == null)
s = s1;
else
{
s = s1;
while((s.getCurrent()).getLink() != null)
s.advance();
(s.getCurrent()).setLink(s2.getHead());
}
return s;
}
public DoubleSeq clone()
{
if (head == null)
return null;
else
{
DoubleSeq s = new DoubleSeq(head.getData());
DoubleNode sc = s.getHead();
DoubleNode nc = sc;
DoubleNode current = head;
while (current.getLink() != null)
{
current = current.getLink();
nc.setLink(new DoubleNode(current.getData()));
nc = nc.getLink();
}
return s;
}
}
public boolean isCurrent()
{
if(current != null)
return true;
else
return false;
}
public void removeCurrent()
{
DoubleNode temp;
for(temp = head; temp.getLink() != current; temp = temp.getLink());
temp.setLink(current.getLink());
}
public int size()
{
return listcount;
}
public void start()
{
current = head;
}
}
CODE
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Seq extends Applet
{
DoubleSeq DS = new DoubleSeq();
double answer = 0;
Label Header1 = new Label("You are supposed to provide a list of double numbers and a value of Xo.");
Label Label1 = new Label("The list:");
TextField list = new TextField(15);
Label Label2 = new Label("Xo:");
TextField X = new TextField(5);
Button eval = new Button("Evaluate Your Polynomial");
TextArea output = new TextArea(10,70);
public void init()
{
setSize(new Dimension(500,400));
add(Header1);
add(Label1);
add(list);
add(Label2);
add(X);
add(eval);
add(output);
EvaluateListener el = new EvaluateListener();
eval.addActionListener(el);
}
class EvaluateListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
String s = list.getText();
double Xo = Double.parseDouble(X.getText());
StringTokenizer tokenizer = new StringTokenizer(s," ");
String s1;
while(tokenizer.hasMoreTokens())
{
DS.addAfter(Double.parseDouble(tokenizer.nextToken()));
DS.advance();
}
DS.start();
while(DS.getHead()!=null)
{
double C = DS.getCurrent().getData();
DS.advance();
double E = DS.getCurrent().getData();
DS.advance();
answer = answer + C * Math.pow(Xo, E);
}
output.append("The value of your polynomial is: " + answer);
}
}
}