subject

For this project you will write three classes: Term, Expression, and Main. (BTW the project has to be in java)

An algebraic expression is one or more algebraic terms in a phrase. It can include variables, constants, and operating symbols, such as plus and minus signs. It's only a phrase, not the whole sentence, so it doesn't include an equal sign.

Algebraic expression:

3x2 + 7x

In an algebraic expression, terms are the elements separated by the plus or minus signs. This example has two terms, 3x2 and 7x.

Your Term class will represent a term in an algebraic expression. A term has a coefficient and exponent. These variables should both be integers. You do not need to have an instance field that keeps track of the variable (x in our example). We’ll assume that each term has a single variable which we’ll represent as x.

Write a packed and default constructor for this class. Your default constructor should use this to call the packed constructor. The packed constructor should use this with shadowed parameters. Write accessors and modifiers for both instance fields. Additionally, you should override the toString() method so that it returns a string with the object’s coefficient and exponent. A Term with a coefficient of 2 and an exponent of 5 would return the string 2x^5 when you call it’s toString() method.

Finally, write the function evaluate(int x). This function is passed a value for x and should calculate and return what the Term would evaluate to with this value. For example, if we called evaluate(3) on a Term with a coefficient of 2 and an exponent of 5, or 2x^5, your function would return 486, because 35 equals 243 and 243 * 2 equals 486.

Your Expression class will represent an algebraic expression with two terms. The class should have two instance fields term1 and term2. These variables should both be Terms.

Write a packed and default constructor for this class. Your default constructor should use this to call the packed constructor. The packed constructor should use this with shadowed parameters. Write accessors and modifiers for both instance fields. Additionally, you should override the toString() method so that it returns a string representation of the expression. Be sure to make use of the Term class’s toString() method when you write this method. Do take into account the fact that the coefficient for a term can be either positive or negative.

Finally, write the function evaluate(int x). This function is passed a value for x and should calculate and return what the Expression would evaluate to with this value. For example, if we called evaluate(3) on the Expression 2x^2 + 3x^1, your function would return 27.

In your Main class you should ask the user to enter the coefficient and exponent for two Terms. Use the values that the user entered to construct an Expression object. Next, ask the user if they would like to change the coefficient or exponent for either term. If they decide to change any of these values, than you should read in the new value and update the Expression. Finally, ask the user to enter a value for x and evaluate and print the Expression.

Here's an example of what your program should look like when you run it:

Please enter the coefficient and exponent for the first term:

3 4

Please enter the coefficient and exponent for the second term:

2 1

Your expression is 3x^4 + 2x^1

Would you like to change the first term's coefficient or exponent? Enter ‘c’ to change the coefficient, ‘e’ to change the exponent, ‘b’ to change both and ‘n’ to change neither.

e

What is the new exponent?

5

Would you like to change the second term’s coefficient or exponent? Enter ‘c’ to change the coefficient, ‘e’ to change the exponent, ‘b’ to change both and ‘n’ to change neither.

c

What is the new coefficient?

-5

Your expression is 3x^5 - 5x^1

Enter a value for x:

4

If x = 4, 3x^5 - 5x^1 = 3052


For this project you will write three classes: Term, Expression, and Main.

(BTW the project has t
For this project you will write three classes: Term, Expression, and Main.

(BTW the project has t

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 19:30
The following is an excerpt from a slide presentation. today we will inverse operations solving equations using inverse operations solving inequalities using inverse operations from which part of the presentation does the slide most likely come from? a. introduction b. outline c. body d. conclusion
Answers: 1
question
Computers and Technology, 23.06.2019 22:20
Read “suburban homes construction project” at the end of chapters 8 and 9 (in the textbook) and then develop a wbs (work breakdown structure) in microsoft excel or in microsoft word (using tables)
Answers: 1
question
Computers and Technology, 25.06.2019 13:30
Which tab contains the font style attributes? home insert review view
Answers: 1
question
Computers and Technology, 25.06.2019 16:00
Which formulas would work to combine cells with first, middle, and last names from columns a through c and row 2 into a new cell?
Answers: 1
You know the right answer?
For this project you will write three classes: Term, Expression, and Main. (BTW the project has to...
Questions
question
Mathematics, 07.07.2019 08:30
question
History, 07.07.2019 08:30
question
Mathematics, 07.07.2019 08:30
question
Mathematics, 07.07.2019 08:30
question
Mathematics, 07.07.2019 08:30
Questions on the website: 13722362