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 20:00
What statement best describes operating systems? it’s possible for modern computers to function without operating systems. most operating systems are free or very inexpensive. operating systems are managed by the computer’s microprocessor (cpu). operating systems manage the computer’s random access memory (ram).
Answers: 1
question
Computers and Technology, 23.06.2019 09:50
Allison and her group have completed the data entry for their spreadsheet project. they are in the process of formatting the data to make it easier to read and understand. the title is located in cell a5. the group has decided to merge cells a3: a7 to attempt to center the title over the data. after the merge, allison points out that it is not centered and looks bad. where would the title appear if allison unmerged the cells in an attempt to fix the title problem?
Answers: 2
question
Computers and Technology, 25.06.2019 00:30
What is a typeface? a. a collection of similar text b. a collection of similar fonts c. a collection of similar designs d. a collection of similar colors e. a collection of similar images
Answers: 1
question
Computers and Technology, 25.06.2019 01:30
What controls can be found on the file tab of microsoft word
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
Chemistry, 28.01.2021 20:20
question
Mathematics, 28.01.2021 20:20
question
Chemistry, 28.01.2021 20:20
question
Mathematics, 28.01.2021 20:20
question
Mathematics, 28.01.2021 20:20
Questions on the website: 13722362