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 17:50
Farah works in an office with two other employees. all three share a printer and an internet connection. the utility that makes this possible is defragger quicktime soho winzip
Answers: 1
question
Computers and Technology, 22.06.2019 19:00
In he example code, what does the title attribute create? a tool tip an element a source a markup
Answers: 1
question
Computers and Technology, 22.06.2019 20:40
Assume that there is a 4% rate of disk drive failure in a year. a. if all your computer data is stored on a hard disk drive with a copy stored on a second hard disk drive, what is the probability that during a year, you can avoid catastrophe with at least one working drive? b. if copies of all your computer data are stored on three independent hard disk drives, what is the probability that during a year, you can avoid catastrophe with at least one working drive?
Answers: 1
question
Computers and Technology, 23.06.2019 10:30
Would a ps4 wired controller work on an xbox one
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, 02.10.2021 14:00
Questions on the website: 13722361