14,662,530 members
Rate this:
See more:
Create a Java application which has the following classes within the packages

Define a class Polynomial which includes the following:
Attributes:
i) coefficients : an array of double values

Methods:
i) Encapsulate the class.
ii) parameterized constructor which takes an array of double values as arguments.
iii) Override the toString() method to display the polynomial in the given format:
coefficients[n] * x^n + coefficients[n-1] * x^(n-1) +... + coefficients[0]
where n = coefficients.length – 1
For example if coefficients = {5.0, 4.4, 3.5,2.0} the polynomial should be displayed as:
5.0 x^3 + 4.4 x^2 + 3.5 x^1 + 2.0
iv) Include the following methods to the class:
polynomial add(polynomial ob): adds this polynomial to the polynomial given as argument and returns the resultant as a new polynomial.
polynomial minus(polynomial ob): subtracts the polynomials given as argument from this polynomial and returns the resultant as a new polynomial.
polynomial multiply(polynomial ob): multiplies this polynomial to the polynomial given as argument and returns the resultant as a new polynomial.

Write a TestPolynomial class to test the working of all the methods of the Polynomial class using multiple objects.

The program must throw and handle the user-defined exception WrongInputException if the input entered for : coefficients is in incorrect format.

Sample Test Cases:
poly1 = 4x^3 + 3x^2 + 2x + 1
poly2 = 3x^2 + 5
poly1.add(poly2) = 4x^3 + 6x^2 + 2x + 6
poly1.multiply(poly2) = 12x^5 + 9x^4 + 26x^3 + 18x^2 + 10x + 5
poly1.minus(poly2)) = 4x^3+ 2x - 4

Functionality of Test class present in it.tests package [of the specific question allocated to each student]
a) The Test classes main thread must create an array capable of holding ‘n’ objects of class present in it.core package [of the specific question allocated to each student]
Note: The value of ‘n’ must be taken as command line argument.
b) The main thread must then create two more threads namely ObjectCreator and MethodTester
c) The job of the ‘ObjectCreator’ is to create ‘n’ objects of class present in it.core package and store their references in the array created in step (a)
d) The job of the ‘MethodTester’ is to call the appropriate methods (i.e toString .. etc) for testing purpose.

What I have tried:

I tried but I am unable to do it using threads and command line arguments
Posted
Updated 11-Oct-20 19:59pm
Richard MacCutchan 12-Oct-20 4:42am

I think you need to have a serious talk with your teacher.

Rate this:

## Solution 1

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

Top Experts
Last 24hrsThis month
 Richard MacCutchan 250 CPallini 210 OriginalGriff 145 Patrice T 78 Sandeep Mewara 60
 OriginalGriff 4,043 Richard MacCutchan 2,655 CPallini 1,830 Sandeep Mewara 1,315 Patrice T 1,009

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100