Jade Ruby T.

asked • 07/18/21

How to construct a class?

Construct a class called Term. It is going to represent a term in polynomial expression. It has an integer coefficient and an exponent. In this case, there is only 1 independent variable that is 'x'.


There should be two operations for the Term:

  1. public Term times(Term t) - multiplies the term with another term and returns the result
  2. public String toString() - prints the coefficient followed by "x^" and appended by the exponent. But with the following additional rules:
  3. if the coefficient is 1, then it is not printed.
  4. if the exponent is 1, then it is not printed ( the caret is not printed as well)
  5. if the exponent is 0, then only the coefficient is printed. 

Input Format

The first line contains the coefficient and the exponent of the first term. The second line contains the coefficient and the exponent of the second term.

Input Sample

1·1
4·3

Output Format

Display the resulting product for each of the test case.

Output Sample

4x^4


1 Expert Answer

By:

Patrick B. answered • 07/18/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.