****THIS IS IN JAVA****** For this lab you will write TWO classes TheTree and TheNode in the SAME file. Normally I prefe

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

****THIS IS IN JAVA****** For this lab you will write TWO classes TheTree and TheNode in the SAME file. Normally I prefe

Post by answerhappygod »

****THIS IS IN JAVA******
For this lab you will write TWO classes TheTree
and TheNode in the SAME file. Normally I prefer
EACH class to be in its OWN .java file but it is better to match
the pattern we have been using so far.
Create a Java Project (and package) named
Lab9
Complete the Java main class with the name
TheTree
Complete a Java class named TheNode (do not set
public access) to represent the individual objects
At the TOP of the TheNode class declare 3 NON-STATIC
private object variables:
An integer variable named info with an initial
value of zero
A TheNode variable named leftchild with an initial
value of null
A TheNode variable named rightchild with an
initial value of null
Write the following 6 public GET/SET methods in
class TheNode :
Method getinfo() with no parameter, that
returns the value of the variable info
Method getleftchild() with no parameter, that
returns the value of the variable leftchild
Method getrightchild() with no parameter, that
returns the value of the variable rightchild
Method setinfo() with one parameter, that
assigns the parameter value to the variable
info
Method setleftchild() with one parameter, that
assigns the parameter value to the variable
leftchild
Method setrightchild() with one parameter, that
assigns the parameter value to the variable
rightchild
Complete a Java class named TheTree that will
represent the entire collection of objects in the tree
At the TOP of the TheTree class declare 1 NON-STATIC
private object variable:
A TheNode variable named rootvar with an initial
value of null
Write the following 2 public GET/SET methods in
class TheTree :
Method getrootvar() with no parameter, that
returns the value of the variable rootvar
Method setrootvar() with one parameter, that
assigns the parameter value to the variable
rootvar
Inside the main() method:
Declare an object reference variable named
treevar and assign it an object of type
TheTree
Declare an object reference variable named
arootobj and assign it an object of type
TheNode
Declare an object reference variable named
myleft and assign it an object of type
TheNode
Declare an object reference variable named
a_right and assign it an object of type
TheNode
Use the object arootobj to call the method
setinfo() and pass it the parameter value
58
Use the object myleft to call the method
setinfo() and pass it the parameter value
26
Use the object a_right to call the method
setinfo() and pass it the parameter value
62
Now build your tree from the objects:
Use the object treevar to call the method
setrootvar() and pass it the parameter value
arootobj
Use the object arootobj to call the method
setleftchild() and pass it the parameter value
myleft
Use the object arootobj to call the method
setrightchild() and pass it the parameter value
a_right
DO NOT CHANGE THE VALUES OF THE VARIABLES DIRECTLY, YOU MUST
CALL THE SET METHODS
Print the message 'Root method arootobj.getinfo returns '
followed by the value returned by calling
arootobj.getinfo
Print the message 'Left child method myleft.getinfo returns '
followed by the value returned by calling
myleft.getinfo
Print the message 'Right child method a_right.getinfo returns '
followed by the value returned by calling
a_right.getinfo
DO NOT PRINT THE VALUES OF THE VARIABLES DIRECTLY, YOU MUST CALL
THE GET METHODS
Here is the starter code:
package lab9;
// DO NOT TOUCH these import statements, add yours below
import java.net.*;
import java.io.*;
import java.lang.reflect.*;
class TheNode {

}// end TheNode class
public class TheTree {
static boolean doSubmit = false;
// DO NOT MOVE (true=submit)
// DECLARE YOUR NON-STATIC GLOBAL VARIABLES
HERE
public static void main(String[] args)
{

SubmitProject9.start(956); // DO NOT TOUCH/MOVE
// Insert code for
main here

// DO NOT TOUCH/MOVE

SubmitProject9.locals("arootobj",arootobj);
SubmitProject9.locals("treevar",String.valueOf(treevar));
SubmitProject9.locals("myleft",String.valueOf(myleft));
SubmitProject9.locals("a_right",String.valueOf(a_right));
SubmitProject9.end(406);
// DO NOT TOUCH/MOVE
} // end of main


} // end TheTree class
// STOP! DO NOT TOUCH ANY CODE BEYOND THIS
POINT
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply