aspose file tools*
The moose likes Beginning Java and the fly likes A little help please...should be easy Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A little help please...should be easy" Watch "A little help please...should be easy" New topic
Author

A little help please...should be easy

Jamess Davis
Greenhorn

Joined: Sep 11, 2008
Posts: 5
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 ]

James Davis
Terry McKee
Ranch Hand

Joined: Sep 29, 2000
Posts: 173
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

Joined: Oct 06, 2008
Posts: 221
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


SCJP 1.5
"A candle looses nothing by lighting another candle"
itechmentors.com
Jamess Davis
Greenhorn

Joined: Sep 11, 2008
Posts: 5
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

Joined: Oct 13, 2005
Posts: 39834
    
  28
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

Joined: Sep 11, 2008
Posts: 5
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

Joined: Oct 13, 2005
Posts: 39834
    
  28
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A little help please...should be easy