I am having trouble with getting some kind of output with my program.
I just learned about how to create classes and my assignment gives me the output desired and the main body of the program, wanting me to write the class. It is a postcard, where there are String variables in the object.
I get nothing when I'm finished. What am I doing wrong????
class PostCard
{
public PostCard(String n, String t)
{name = new String;
text = new String(t);
}
public PostCard(String t)
{text = new String(t);
}
public void setRecipient(String n)
{name = new String;
}
public String print()
{return "Dear " + name + ",/t" +
text;
}
private String text;
private String name;
}
public class PostCardDemo {
public static void main(String[] args) {
String text = "\tI'm having a wonderful\n" +
"time at Disney World. Weather's\n" +
"great. Wish you were here!";
PostCard p1 = new PostCard("Vanna", text);
p1.print();
PostCard p2 = new PostCard(text);
// set recipient's name to ""
p2.setRecipient("Merv");
p2.print();
p2.setRecipient("Mom");
p2.print();
PostCard p3 = new PostCard("Sweetie",
"\tI'm miserable without\n" + "you. It's been raining all week.\n" + "I can't wait to get back home.");
p3.print();
}
}
I just learned about how to create classes and my assignment gives me the output desired and the main body of the program, wanting me to write the class. It is a postcard, where there are String variables in the object.
I get nothing when I'm finished. What am I doing wrong????
class PostCard
{
public PostCard(String n, String t)
{name = new String;
text = new String(t);
}
public PostCard(String t)
{text = new String(t);
}
public void setRecipient(String n)
{name = new String;
}
public String print()
{return "Dear " + name + ",/t" +
text;
}
private String text;
private String name;
}
public class PostCardDemo {
public static void main(String[] args) {
String text = "\tI'm having a wonderful\n" +
"time at Disney World. Weather's\n" +
"great. Wish you were here!";
PostCard p1 = new PostCard("Vanna", text);
p1.print();
PostCard p2 = new PostCard(text);
// set recipient's name to ""
p2.setRecipient("Merv");
p2.print();
p2.setRecipient("Mom");
p2.print();
PostCard p3 = new PostCard("Sweetie",
"\tI'm miserable without\n" + "you. It's been raining all week.\n" + "I can't wait to get back home.");
p3.print();
}
}