Computers and Technology

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

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 05:00, 105001964
Write a loop that reads positive integers from standard input and that terminates when it reads an integer that is not positive. after the loop terminates, it prints out, on a line by itself and separated by spaces, the sum of all the even integers read, the sum of all the odd integers read, a count of the number of even integers read, and a count of the number of odd integers read, all separated by at least one space. declare any variables that are needed. assume the availability of a variable, stdin, that references a scanner object associated with standard input. that is, stdin = new scanner(system. in); is given.
Answers: 3
image
Computers and Technology, 22.06.2019 18:00, alexj29227405
Write a method named addall that could be placed inside the hashintset class. this method accepts another hashintset as a parameter and adds all elements from that set into the current set, if they are not already present. for example, if a set s1 contains [1, 2, 3] and another set s2 contains [1, 7, 3, 9], the call of s1.addall(s2); would change s1 to store [1, 2, 3, 7, 9] in some order. you are allowed to call methods on your set and/or the other set. do not modify the set passed in. this method should run in o(n) time where n is the number of elements in the parameter set passed in.
Answers: 2
image
Computers and Technology, 23.06.2019 19:00, jacobbecker99
Choose the correct citation for the case which established the "minimum contacts" test for a court's jurisdiction in a case. select one: a. brown v. board of education of topeka, 347 u. s. 483 (1954). b. international shoe co. v. washington, 326 u. s. 310 (1945) c. haynes v. gore, 531 u. s. 98 (2000). d. international shoe co. v. washington, 14 u. s. code 336.
Answers: 1
image
Computers and Technology, 24.06.2019 07:00, jordaaan101
Guys do you know sh27 cause he hacked me : ( pidgegunderson my old user
Answers: 2
Do you know the correct answer?
For this project you will write three classes: Term, Expression, and Main. (BTW the project has to...

Questions in other subjects:

Konu
Social Studies, 07.07.2020 16:01