Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming: Below is the ProgramNode extends Node.java file. There is an error in the 3rd curly brace after the system.out.println(): so please fix that

Java Programming: Below is the ProgramNode extends Node.java file. There is an error in the 3rd curly brace after the system.out.println(): so please fix that error. Attached is the rubric that is circled in black all the components the ProgramNode extends Node.java file must have. Attached is the output it must produce. Make sure to show the full code without any errors.

ProgramNode.java

package mypack;

import java.util.HashMap;

public abstract class ProgramNode extends Node { private HashMap functions;

public ProgramNode() { functions = new HashMap(); } public void addFunction(String name, FunctionNode function) { functions.put(name, function); }

public FunctionNode getFunction(String name) { return functions.get(name); }

public void printFunctions() { for (String name : functions.keySet()) { System.out.println(name); functions.get(name).print(); System.out.println(); } } }

FunctionNode myFunction = new FunctionNode("myFunction"); myFunction.addParameter(new VariableNode("x")); myFunction.addParameter(new VariableNode("y")); myFunction.addVariable(new VariableNode("z")); myFunction.addConstant(new ConstantNode("PI", 3.14159)); myFunction.addStatement(new AssignmentNode("z", new BinaryOpNode("+", new VariableNode("x"), new VariableNode("y")))); myFunction.addStatement(new ReturnNode(new VariableNode("z")));

program.addFunction("myFunction", myFunction);

HashMap functionMap = new HashMap (); for (FunctionNode functionNode: functionNodes) { functionMap.put(functionNode.getName(), functionNode); } return new ProgramNode(functionMap); }

}

image text in transcribed

image text in transcribed

Output:- 123456789101112myFunctionParameters:xyVariables:zConstants:-PI:3.14159Statements:-zx+y-returnz Output:- 123456789101112myFunctionParameters:xyVariables:zConstants:-PI:3.14159Statements:-zx+y-returnz

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago