I'm not an expert on java, but I believe I am able to help. First you should look up the toString() method on the java API and find out what it does (Object (Java 2 Platform SE v1.4.2) ). Now if you're a beginner, it may look like jibberish to you. Basically, toString() is a method of an object that converts whatever you need to a string. What you want to do, i'm guessing, is to override the method ( meaning that you want to replace what toString() does with what you want it to do, which is to print out a christmas tree).
Code:
public class ChristmasTree
{
private String Tree;
public ChristmasTree()
{
Tree = (" /\\ \n / \\ \n / \\ \n / \\ \n -------- \n \" \" \n \" \" \n \" \" ");
}
}
What you did was to construct a ChristmasTree object with properties "Tree" meaning that ChristmasTree object will be able to print out a christmas tree if you so desire. Frankly I would just move everything to the toString() instead.
Code:
class ChristmasTree
{
private String Tree;
public String toString()
{
return Tree = (" /\\ \n / \\ \n / \\ \n / \\ \n -------- \n \" \" \n \" \" \n \" \" ");
}
}
But if your professor requires to go have a constructor, then this works as well:
Code:
class ChristmasTree
{
private String Tree;
public ChristmasTree()
{
Tree = (" /\\ \n / \\ \n / \\ \n / \\ \n -------- \n \" \" \n \" \" \n \" \" ");
}
public String toString()
{
return Tree;
}
}