Question: Using Java Design, implement, and test the SOP expression hierarchy. Sums of Products The SOP processor executes SOP expressions. class Processor { public Double execute

Using Java Design, implement, and test the SOP expression hierarchy.

Using Java Design, implement, and test the SOP expression hierarchy. Sums ofProducts The SOP processor executes SOP expressions. class Processor { public Double

Sums of Products The SOP processor executes SOP expressions. class Processor { public Double execute (Expression exp) { return exp.execute(); The SOP language currently has three types of expressions: numbers, sums, and products. expression ::= number | sum product A sum is the token "sum" followed by a list of 2 or more expressions: sum(a, b, ...) A product is the token "mul" followed by a list of 2 or more expressions: mul (a, b, ...) A number has the format num(x) where x is any Java Double: num(-3.14) Here are a few examples of SOP expressions and their values: num (5.1) // = 5.1 sum (num (3.0), num (4.0), num (5.0)) // = 12 mul (num (2.0), sum (num (3.0), num (4.0), num (5.0))) // - 24 Design, implement, and test the SOP expression hierarchy. Notes Here's a start on a test harness. Add more tests: TestSOP.java. My constructors for Sum and Product use Java's varargs feature: Sum (Expression operand ...) (...) For example new Sun (a, b, c) gathers the inputs into an array (a, b, c). public class Test SOP { public static void main(String[] args) { Processor proc = new Processor(); Expression el = new Number(2.0); Expression e2 = new Number(3.1); Expression e3 = new Number(-5.0); Sum sl = new Sum(el, e2, e3); System.out.println("sl - " + proc.execute(sl)); Product pl = new Product(si, e3); System.out.println("sl - " + proc.execute(sl)); 11 etc. Sums of Products The SOP processor executes SOP expressions. class Processor { public Double execute (Expression exp) { return exp.execute(); The SOP language currently has three types of expressions: numbers, sums, and products. expression ::= number | sum product A sum is the token "sum" followed by a list of 2 or more expressions: sum(a, b, ...) A product is the token "mul" followed by a list of 2 or more expressions: mul (a, b, ...) A number has the format num(x) where x is any Java Double: num(-3.14) Here are a few examples of SOP expressions and their values: num (5.1) // = 5.1 sum (num (3.0), num (4.0), num (5.0)) // = 12 mul (num (2.0), sum (num (3.0), num (4.0), num (5.0))) // - 24 Design, implement, and test the SOP expression hierarchy. Notes Here's a start on a test harness. Add more tests: TestSOP.java. My constructors for Sum and Product use Java's varargs feature: Sum (Expression operand ...) (...) For example new Sun (a, b, c) gathers the inputs into an array (a, b, c). public class Test SOP { public static void main(String[] args) { Processor proc = new Processor(); Expression el = new Number(2.0); Expression e2 = new Number(3.1); Expression e3 = new Number(-5.0); Sum sl = new Sum(el, e2, e3); System.out.println("sl - " + proc.execute(sl)); Product pl = new Product(si, e3); System.out.println("sl - " + proc.execute(sl)); 11 etc

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!