Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please answer in java and also include the main class to test the program. please You are to develop a Java program that adds polynomials.

please answer in java and also include the main class to test the program. please
image text in transcribed
image text in transcribed
You are to develop a Java program that adds polynomials. The polynomials will be represented in youe program as singly linked lists of tems. All of the polynomials will be in terms of the variable x. You will wite four Java classes The Term Class Term represents a term in a polynomial. It will have two private instance variables (data ficlds) named coefficient and exponent. For example, 4x4 would be represented by a Term object with coefficient 4 and exponent 6 . In terms of methods, this class nceds - getters for each instance variable - a constructor that takes parameters for both instance variables - a tostring that retums the Term in the form: 4x26 - an addferm method that takes a Term as a parameter and returns a Term that is the sum of the calling object and the parameter. If the sam of the two Terms cannot be expresied as a single Term (because the exponcnts don't match), it retums null. The Polynomial Class Polynomial is the central class of your program, repecsenting the actual polynomial ecprersions. It will include the following elemeats: - A private inner class Node with two instance variables termData of type Term and next of type Node. This class functions as the node class for the singly linked list representing your polynomial and should have the necessary fanctionality for that. - Two private instance variables of type Node: termsHead and termsiail. These will be nuil if the polynomial has no terms. Otherwise, they will point to the firnt and last terms of the polynomial. respectively. - The following public methods: a default constructor a constructor that accepts a String representing a polynomial in the form 4x6. 2x3+1x2 and initialices the object to represent that polynomial, We are simplifying the problem by guarantecing spaces between terms and operatons and explicitly representing cocfficients of 1 (so x2 is 1x22 mather than x22). Note that subtraction in the polynomial will result in a nepative cocfficicat: 3x22 will have two terms, one with coefficient 3 and exponent 2 and one with coefficient -2 and exponent 0 . There will be no negative expoocots. an add Term ToPolynomial that adds a Tem to the end of the list of terms a toString that retarns a String reptesenting the polynornal is the form shown in the sarmple oeiput below. 2. an addPolynomial that accepts a Polynomial object as a pirameter and teturms a Polynomial object representing the sam of the calling object and abe paramster Your ncw polynomial must have the sems in the standard onder (largst cypeneat to smallest) and must not include terms with coefficients of 0 . - You may add private micthods as desired to improve the desiga of the program. Your fourth class will include main and will use the other classes to write a program that alluws users to eater pain of polynemials to be added. Your fourth class will include main and will use the other classes to write a program that users to enter pairs of polynomials to be added. Sample program run (user input in bold). Welcome to the Polynomial Addition Program. Please enter your first polynomial: 4x3+2x7 Please enter the second polynomial: 10x4+2x32x+3 The sum is: 10x4+6x34 Would you like to add two more polynomials? y Please enter your first polynomial: 6x35x2+4 Please enter the second polynomial: 2x37x2+3x4 The sum is: 4x312x2+3x Would you like to add two more polynomials? n Thank you for using the Polynomial Addition Program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago