-2

parsePolynomial -- this method takes one parameter (a String) and returns a new Polynomial. The parameter is a String that represents a polynomial of the form similar to 2x^2+5.You must return a new instance of a Polynomial that correctly represents the string.

You will have to use some of the methods in the Java String class, so you should probably review the online documentation for the Java String class. For example, you might want to look at the replaceAll(), lastIndexOf(), charAt() and substring() methods (among others).

Andy Hayden
  • 359,921
  • 101
  • 625
  • 535
javaLearner
  • 25
  • 1
  • 7

1 Answers1

2

First split at the +es so you get parts of either the form 2x^2 or 5.

Next test if they contain x^ and if yes use that to split them again so you get the coefficient and the exponent. Then parse them as double and int and you're done.

CodesInChaos
  • 106,488
  • 23
  • 218
  • 262