Question
Could anyone help me with how would I print out this code? Any help is appreciated! This project is about creating algebraic trees of a
Could anyone help me with how would I print out this code? Any help is appreciated!
This project is about creating algebraic trees of a fixed size
1 import java.util.*; 2 3 public class TestAlgebraic { 4 static Random r = new Random(); 5 6 public static Node randOperator() { 7 Node n; 8 int operator = r.nextInt(4); 9 switch(operator) { 10 case 0: 11 n = new Plus(); 12 break; 13 case 1: 14 n = new Minus(); 15 break; 16 case 2: 17 n = new Mult(); 18 break; 19 case 3: 20 n = new Divide(); 21 break; 22 case 4: 23 n = randConst(); 24 break; 25 case 5: 26 n = randVariable(); 27 break; 28 default: 29 n = new Plus(); 30 break; 31 } 32 return n; 33 } 34 35 public static Node randConst() { 36 Node n; 37 int Const = r.nextInt(20) + 1; 38 n = new Const(Const); 39 return n; 40 } 41 42 public static Node randVariable() { 43 Node n; 44 int var = r.nextInt(); 45 n = new Variable(var); 46 return n; 47 } 48
The output is supposed to look like this:
((11.0 / X0) + (2.0 - X0)) = 2.4483870967741934 ((2.0 * X0) * (4.0 / X0)) = 8.0 ((8.0 - X0) / (11.0 * X0)) = 0.1436950146627566 ((9.0 * X0) / (8.0 * X0)) = 1.125 (18.0 * X0) + (6.0 * X0)) = 74.4
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started