1. Member
Join Date
Jun 2013
Location
Philippines
Posts
15
Rep Power
0

## 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.

2. ## Re: Method body unknown!

MyTriangle Class

db

3. ## 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 ...

4. Member
Join Date
Jun 2013
Location
Philippines
Posts
15
Rep Power
0

## 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?

5. ## 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

6. Member
Join Date
Jun 2013
Location
Philippines
Posts
15
Rep Power
0

## 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

7. ## Re: Method body unknown!

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

8. ## Re: Method body unknown!

I think Horner's rule can be of help here.

kind regards,

Jos

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•