Question: fix my code to pass all the tests: import java.util.Random; / / Testing Algebra Expressions public class TestAlgebra { public static void main ( String

fix my code to pass all the tests:
import java.util.Random;
// Testing Algebra Expressions
public class TestAlgebra {
public static void main(String[] args){
// Build tree for expression: ((16.0/ X0)-(7.0* X1))
Node tree1= new Binop(
new Binop(new Const(16.0), new Variable(0),'/'),
new Binop(new Const(7.0), new Variable(1),'*'),
'-'
);
// Build tree for expression: ((X0+ X1)/(12.0/12.0))
Node tree2= new Binop(
new Binop(new Variable(0), new Variable(1),'+'),
new Binop(new Const(12.0), new Const(12.0),'/'),
'/'
);
Node tree3= new Binop(
(tree1),(tree2),'/'
);
// Test values: {1.0,2.0,3.0}
double[] values1={1.0,2.0,3.0};
// Test values: {4.0,5.0,6.0}
double[] values2={4.0,5.0,6.0};
// Evaluate and print results for tree1
System.out.printf("((16.0/ X0)-(7.0* X1))=%.1f%n", tree1.eval(values1)); // Expected output: 2.0
System.out.printf("((16.0/ X0)-(7.0* X1))=%.1f%n", tree1.eval(values2)); // Expected output: -31.0
// Evaluate and print results for tree2
System.out.printf("((X0+ X1)/(12.0/12.0))=%.1f%n", tree2.eval(values1)); // Expected output: 3.0
System.out.printf("((X0+ X1)/(12.0/12.0))=%.1f%n", tree2.eval(values2)); // Expected output: 9.0
// Evaluate and print results for tree3
System.out.printf("(((16.0/ X0)-(7.0* X1))/((X0+ X1)/(12.0/12.0)))=%.1f%n", tree3.eval(values1));
System.out.printf("(((16.0/ X0)-(7.0* X1))/((X0+ X1)/(12.0/12.0)))=%.1f%n", tree3.eval(values2));
}
}Test Algebra, 2 Trees (4 lines)
58
59
60((16.0/ X0)-(7.0* X1))=2.0
61((16.0/ X0)-(7.0* X1))=-31.0
62((X0+ X1)/(12.0/12.0))=3.0
63((X0+ X1)/(12.0/12.0))=9.0
64(((16.0/ X0)-(7.0* X1))/((X0+ X1)/(12.0/12.0)))=0.7
65(((16.0/ X0)-(7.0* X1))/((X0+ X1)/(12.0/12.0)))=-3.4
66
67 failed - Test Algebra, 2 Trees (4 lines)
68::error::The output for test Test Algebra, 2 Trees (4 lines) did not match%0AExpected:%0A[(][(]([12]?[0-9]([.]0)?|X1|X2|X0)([/*+]|-)([12]?[0-9]([.]0)?|X1|X2|X0)[)]([/*+]|-)[(]([12]?[0-9]([.]0)?|X1|X2|X0)([/*+]|-)([12]?[0-9]([.]0)?|X1|X2|X0)[)][)]=-?[0-9]+[.][0-9]+*(\r|
|\r
)+(.*(\r|
|\r
))+[(][(]([12]?[0-9]([.]0)?|X1|X2|X0)([/*+]|-)([12]?[0-9]([.]0)?|X1|X2|X0)[)]([/*+]|-)[(]([12]?[0-9]([.]0)?|X1|X2|X0)([/*+]|-)([12]?[0-9]([.]0)?|X1|X2|X0)[)][)]=-?[0-9]+[.][0-9]+*(\r|
|\r
)+(.*(\r|
|\r
))+[(][(]([12]?[0-9]([.]0)?|X1|X2|X0)([/*+]|-)([12]?[0-9]([.]0)?|X1|X2|X0)[)]([/*+]|-)[(]([12]?[0-9]([.]0)?|X1|X2|X0)([/*+]|-)

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 Programming Questions!