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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 17:00, naomicervero
Which process would best represent the opposite of exhausting air from a system?
Answers: 2
image
Computers and Technology, 22.06.2019 02:00, ayoismeisjuam
The word ‘play’ comes with many different interpretations and a variety of definitions. discuss some of the various meanings tied to the word play. why is the concept of play thought to be an important addition to the workplace? do some (brief) research online and give an example of how play in the workplace is being done right.
Answers: 2
image
Computers and Technology, 24.06.2019 21:50, TamB01
Maddie is traveling to india and would like to document her trip for friends and family to access online. what tool would be best? app blog listserver web page
Answers: 1
image
Computers and Technology, 24.06.2019 22:30, rayniqueamee2002
When can you access the bios setup utility?
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 in other subjects: