Results 1 to 8 of 8
Thread: Method body unknown!
- 08-25-2013, 06:00 PM #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.
- 08-25-2013, 06:12 PM #2
Re: Method body unknown!
I see you didn't bother to read Jim's response in your earlier thread.
http://www.java-forums.org/new-java/...tml#post351597
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
- 08-25-2013, 06:28 PM #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 ...
- 08-26-2013, 06:53 AM #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?
- 08-26-2013, 06:56 AM #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
- 08-26-2013, 09:13 AM #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
- 08-26-2013, 09:16 AM #7
- 08-26-2013, 09:41 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: Method body unknown!
I think Horner's rule can be of help here.
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
Similar Threads
-
Completing the method body
By Michael305rodri in forum New To JavaReplies: 16Last Post: 11-04-2012, 06:58 AM -
creating unknown number of JFrame with an unknown number of JComboBox in each JFrame
By Mokomi in forum New To JavaReplies: 15Last Post: 06-25-2012, 03:11 AM -
Regular expession that matchs a Java Method declaration and body
By rmp in forum Advanced JavaReplies: 5Last Post: 10-27-2011, 08:47 AM -
error: Missing method, body, or declare abstract public static void main
By MBD in forum New To JavaReplies: 2Last Post: 09-27-2011, 04:59 PM -
[SOLVED] Why does the compiler return "not a statement" for this method body please?
By trueblue in forum New To JavaReplies: 3Last Post: 05-25-2009, 09:50 PM
Bookmarks