how to write a main method using input and display include?
up vote
-2
down vote
favorite
This is what i have.
I need to add main with input and display. I need to use a linked list to show, a family tree. I wasn't given a clear explanation as to how the main method should look, so I'm very confused. I'm not sure how to go about writing the main.
public class FamilyTree
{
private class Node
{
String value;
Node left, right;
Node(String val)
{
value = val;
left = null;
right = null;
}
Node(String val, Node leftChild, Node rightChild)
{
value = val;
left = leftChild;
right = rightChild;
}
}
private Node root = null;
public boolean root(String x)
{
if (root == null){
root = new Node(x);
return true;}
else
return false;
}
public boolean addLeft(String p, String x)
{
Node parent = locate(p);
if (root == null ){
return false;}
else if (parent != null && parent.left == null){
parent.left = new Node(x);
return true;}
else
return false;
}
public boolean addRight(String p, String x)
{
Node parent = locate(p);
if (root == null ){
return false;}
else if (parent != null && parent.right == null){
//Adds node
parent.right = new Node(x);
return true;}
else
return false;
}
public Node locate(String p)
{
return locate(p, root);
}
}
java
add a comment |
up vote
-2
down vote
favorite
This is what i have.
I need to add main with input and display. I need to use a linked list to show, a family tree. I wasn't given a clear explanation as to how the main method should look, so I'm very confused. I'm not sure how to go about writing the main.
public class FamilyTree
{
private class Node
{
String value;
Node left, right;
Node(String val)
{
value = val;
left = null;
right = null;
}
Node(String val, Node leftChild, Node rightChild)
{
value = val;
left = leftChild;
right = rightChild;
}
}
private Node root = null;
public boolean root(String x)
{
if (root == null){
root = new Node(x);
return true;}
else
return false;
}
public boolean addLeft(String p, String x)
{
Node parent = locate(p);
if (root == null ){
return false;}
else if (parent != null && parent.left == null){
parent.left = new Node(x);
return true;}
else
return false;
}
public boolean addRight(String p, String x)
{
Node parent = locate(p);
if (root == null ){
return false;}
else if (parent != null && parent.right == null){
//Adds node
parent.right = new Node(x);
return true;}
else
return false;
}
public Node locate(String p)
{
return locate(p, root);
}
}
java
1
I wasn't given a clear explanation as to how the main method should look If this is the case I would go to your teacher and ask for clarification. We know less about the requirements of your project than you do
– GBlodgett
Nov 19 at 0:15
2
writing a main method- what have you tried so far? Dumping some other non-relevant code doesn't help. TBH a simple search forjava main methodwill take you half way there.
– Scary Wombat
Nov 19 at 0:16
add a comment |
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
This is what i have.
I need to add main with input and display. I need to use a linked list to show, a family tree. I wasn't given a clear explanation as to how the main method should look, so I'm very confused. I'm not sure how to go about writing the main.
public class FamilyTree
{
private class Node
{
String value;
Node left, right;
Node(String val)
{
value = val;
left = null;
right = null;
}
Node(String val, Node leftChild, Node rightChild)
{
value = val;
left = leftChild;
right = rightChild;
}
}
private Node root = null;
public boolean root(String x)
{
if (root == null){
root = new Node(x);
return true;}
else
return false;
}
public boolean addLeft(String p, String x)
{
Node parent = locate(p);
if (root == null ){
return false;}
else if (parent != null && parent.left == null){
parent.left = new Node(x);
return true;}
else
return false;
}
public boolean addRight(String p, String x)
{
Node parent = locate(p);
if (root == null ){
return false;}
else if (parent != null && parent.right == null){
//Adds node
parent.right = new Node(x);
return true;}
else
return false;
}
public Node locate(String p)
{
return locate(p, root);
}
}
java
This is what i have.
I need to add main with input and display. I need to use a linked list to show, a family tree. I wasn't given a clear explanation as to how the main method should look, so I'm very confused. I'm not sure how to go about writing the main.
public class FamilyTree
{
private class Node
{
String value;
Node left, right;
Node(String val)
{
value = val;
left = null;
right = null;
}
Node(String val, Node leftChild, Node rightChild)
{
value = val;
left = leftChild;
right = rightChild;
}
}
private Node root = null;
public boolean root(String x)
{
if (root == null){
root = new Node(x);
return true;}
else
return false;
}
public boolean addLeft(String p, String x)
{
Node parent = locate(p);
if (root == null ){
return false;}
else if (parent != null && parent.left == null){
parent.left = new Node(x);
return true;}
else
return false;
}
public boolean addRight(String p, String x)
{
Node parent = locate(p);
if (root == null ){
return false;}
else if (parent != null && parent.right == null){
//Adds node
parent.right = new Node(x);
return true;}
else
return false;
}
public Node locate(String p)
{
return locate(p, root);
}
}
java
java
asked Nov 19 at 0:13
John
1
1
1
I wasn't given a clear explanation as to how the main method should look If this is the case I would go to your teacher and ask for clarification. We know less about the requirements of your project than you do
– GBlodgett
Nov 19 at 0:15
2
writing a main method- what have you tried so far? Dumping some other non-relevant code doesn't help. TBH a simple search forjava main methodwill take you half way there.
– Scary Wombat
Nov 19 at 0:16
add a comment |
1
I wasn't given a clear explanation as to how the main method should look If this is the case I would go to your teacher and ask for clarification. We know less about the requirements of your project than you do
– GBlodgett
Nov 19 at 0:15
2
writing a main method- what have you tried so far? Dumping some other non-relevant code doesn't help. TBH a simple search forjava main methodwill take you half way there.
– Scary Wombat
Nov 19 at 0:16
1
1
I wasn't given a clear explanation as to how the main method should look If this is the case I would go to your teacher and ask for clarification. We know less about the requirements of your project than you do
– GBlodgett
Nov 19 at 0:15
I wasn't given a clear explanation as to how the main method should look If this is the case I would go to your teacher and ask for clarification. We know less about the requirements of your project than you do
– GBlodgett
Nov 19 at 0:15
2
2
writing a main method - what have you tried so far? Dumping some other non-relevant code doesn't help. TBH a simple search for java main method will take you half way there.– Scary Wombat
Nov 19 at 0:16
writing a main method - what have you tried so far? Dumping some other non-relevant code doesn't help. TBH a simple search for java main method will take you half way there.– Scary Wombat
Nov 19 at 0:16
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53366780%2fhow-to-write-a-main-method-using-input-and-display-include%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I wasn't given a clear explanation as to how the main method should look If this is the case I would go to your teacher and ask for clarification. We know less about the requirements of your project than you do
– GBlodgett
Nov 19 at 0:15
2
writing a main method- what have you tried so far? Dumping some other non-relevant code doesn't help. TBH a simple search forjava main methodwill take you half way there.– Scary Wombat
Nov 19 at 0:16