Results 1 to 8 of 8
  1. #1
    DPdieciocho is offline Member
    Join Date
    Jun 2013
    Location
    Philippines
    Posts
    15
    Rep Power
    0

    Question 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. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Method body unknown!

    I see you didn't bother to read Jim's response in your earlier thread.
    MyTriangle Class

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    allaudin's Avatar
    allaudin is offline Senior Member
    Join Date
    Apr 2013
    Posts
    271
    Rep Power
    0

    Default 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. #4
    DPdieciocho is offline Member
    Join Date
    Jun 2013
    Location
    Philippines
    Posts
    15
    Rep Power
    0

    Default 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. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default 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. #6
    DPdieciocho is offline Member
    Join Date
    Jun 2013
    Location
    Philippines
    Posts
    15
    Rep Power
    0

    Default 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. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Method body unknown!

    Quote Originally Posted by DPdieciocho View Post
    @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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default Re: Method body unknown!

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

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Completing the method body
    By Michael305rodri in forum New To Java
    Replies: 16
    Last Post: 11-04-2012, 05:58 AM
  2. Replies: 15
    Last Post: 06-25-2012, 02:11 AM
  3. Replies: 5
    Last Post: 10-27-2011, 07:47 AM
  4. Replies: 2
    Last Post: 09-27-2011, 03:59 PM
  5. Replies: 3
    Last Post: 05-25-2009, 08:50 PM

Posting Permissions

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