Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A little help please...should be easy

 
Jamess Davis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I need a little push in the right direction. I have to write a polynomial class that adds, subtracts and multiplies polynomials. This is my code so far for the class. My tester is below. It says the constructor is undefined but I don't know how to define it. Also I have to use arrays and have no idea how to start off...any help would be appreciated. I don't need code, maybe just a few examples pertaining to my problem. I just need a push in the right direction.




[ October 09, 2008: Message edited by: Bear Bibeault ]
 
Terry McKee
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your Polynomial class you have the following constructor defined:

public Polynomial(int[] coefficients)

In your PolynomialTester class you use the following constructor:

new Polynomial();

Hmmm... I wonder what coefficients the tester class wants to use.
 
harilal ithikkat
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi dude,
i think the problem is there is no zero argument constructor.Since you already defined an argumented constructor comppiler will not add the zero argument constructor as in the case of no constructors.


hope you got it
 
Jamess Davis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can I ask this...Does the code for the polynomial make sense so far? In my head I can't see the logic of how to write the add method. What does it mean...



...like what is it asking for? In the (Polynomial op2) is that creating a new polynomial or what? I'm not used to seeing that.

Oh, so what you're trying to say is that I need a zero Polynomial() too? What could be included if you don't mind me asking?
[ October 09, 2008: Message edited by: Jamess Davis ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it logical to create a polynomial with no coefficients? If no, then you oughtn't to have a zero-args constructor.
Yes it is logical to pass Polynomial op2 as a parameter; that has to be a polynomial you created elsewhere.
The problem is that in the main method you are calling a polynomial constructor with no arguments; that constructor doesn't exist, so you have to change that invocation with parameters to match, eg new Polynomial(new int[]{1, 4, 6, 6, 4, 1}).
[ October 10, 2008: Message edited by: Campbell Ritchie ]
 
Jamess Davis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell that helped out a little bit. My problem now is in my polynomial class. I don't understand how you're supposed to pass the Polynomial method as a parameter and use it in the actual equation.

Should I create an array within the add() method and work from there? Is the code in the constructor correct? Man i'm so confused...
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jamess Davis:
Thanks Campbell that helped out a little bit. You're welcome

Is the code in the constructor correct? Afraid not, no


The idea of a constructor is to set up the initial state of the object. What you are doing is taking the array passed, then adding 1 to each of the members. What you want for a polynomial is simply to record an array of numbers, like 1, 4, 6, 4, 1. You can set up a new array the same size as the array passed, then copy all the values into the new array. Remember to use the length parameter of the old array.

[There is a quicker way to do this, but I am intentionally keeping quiet about it.]

Suggest you get one bit working, then try the next bit. Remember you eat an elephant one mouthful at a time!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic