I have created a polynomial class without using Polynomial, I am using my own Term(coefficient, exponent)
to create the polynomial expression.
I have some conditions which are as follows:
coefficient = 0 -> Term(0,2) -> 0x^2 -> "0"
coefficient = 1 -> Term(1,2) -> 1x^2 -> "x^2"
coefficient = -1 -> Term(-1,2) -> -1x^2 -> "-x^2"
exponent = 1 = -> Term(5,1) -> 5x^1 -> "5x"
exponent = 0 = -> Term(5,0) -> 5x^0 -> "5"
But implementing all of these to function in and around each other is causing me a massive headache, for example if I have Term(-1,1)
I would like "-x"
to appear, and "x"
for Term(1,1)
. Can anyone help with thinking of some sort of logic to group all of these "rules" together for a toString method?