Method body unknown!

• 08-25-2013, 05:00 PM
DPdieciocho
Method body unknown!
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class MyPolynomial {

// Fields
private double[] coeffs;

// Constructor
public MyPolynomial(double... coeffs){

this.coeffs = coeffs;

}

public MyPolynomial(String filename){
Scanner in = null;

try {

in = new Scanner(new File(filename)); // open file

}
catch (FileNotFoundException e) {

e.printStackTrace();

}

int degree = in.nextInt(); // read the degree
coeffs = new double[degree+1]; // allocate the array

for (int i=0; i<coeffs.length; ++i) {

coeffs[i] = in.nextDouble();

}

}

// Methods
public int getDegree(){

return

}

public String toString(){

return

}

public double evaluate(double x){

return

}

}

I don't know what to put on the three methods. Would you mind to teach me what to put on it. Thanks.
• 08-25-2013, 05:12 PM
DarrylBurke
Re: Method body unknown!
http://www.java-forums.org/new-java/...tml#post351597

db
• 08-25-2013, 05:28 PM
allaudin
Re: Method body unknown!
If you don't know what to put in these methods, then how did you write these methods ??? As their names suggest their purpose ... simply put the return statement what actually these methods should return , I can tell you about toString() method: It will return the string representation of the object of class MyPolynomial ...
• 08-26-2013, 05:53 AM
DPdieciocho
Re: Method body unknown!
@DarrylBurke It is because I didn't notice that he already replied, but no worries. I already got it.
@allaudin no I mean is there any formula in getting the degree. and for evaluating, how am I supposed to substitute x to n?
• 08-26-2013, 05:56 AM
Junky
Re: Method body unknown!
I assume the assignment instructions tell you want the methods need to do. If the getDegree method needs to return the value stored in the degree variable then it needs to be declared as an instance variable. As it is now you have it declared inside the constructor which means it is local and cannot be accessed from any other part of the class
• 08-26-2013, 08:13 AM
DPdieciocho
Re: Method body unknown!
That's all what the diagram says. I need to create a class that contains 1 field which is the private double coeffs [], 2 constructors and 5 methods
• 08-26-2013, 08:16 AM
DarrylBurke
Re: Method body unknown!
Quote:

Originally Posted by DPdieciocho
@DarrylBurke It is because I didn't notice that he already replied, but no worries. I already got it.

I wasn't referring to your not replying to the response. I was referring to the content of the post I linked to at #2.

db
• 08-26-2013, 08:41 AM
JosAH
Re: Method body unknown!
I think Horner's rule can be of help here.

kind regards,

Jos