我正在尝试运行以下 java 代码以使其看起来像这样
但是我遇到了问题,我不确定我做错了什么。我有三个类 testFacebook、Facebookperson 和 facebook。
这是我的代码
public class testFacebook{
// This is the testFacebook class
public static void main (String[] argc){
System.out.println();
FacebookPerson p1 = new FacebookPerson("John");
System.out.println(p1.getName()+ "' mood is "+ p1.getMood() +".");
System.out.println(p1.getName()+ "' facebook content is "+ p1.getFacebookContent() +".");
p1.setMood("happy");
System.out.println(p1.getName()+ "' mood is "+ p1.getMood() +".");
System.out.println(p1.getName()+ "' facebook content is "+ p1.getFacebookContent() +".");
p1.setMood("sad");
System.out.println(p1.getName()+ "' mood is "+ p1.getMood() +".");
System.out.println(p1.getName()+ "' facebook content is "+ p1.getFacebookContent() +".");
}
}
public class FacebookPerson{
// This is the FacebookPerson class
private String myname;
private String mood;
private Facebook fb;
public FacebookPerson(String name){
myname = name;
mood ="initial mood";
fb = new Facebook();
}
public void setMood(String newMood){
mood = newMood;
fb.setContent(mood);
}
public String getMood(){
return mood;
}
public String getFacebookContent(){
return content;
}
public String getName(){
return name;
}
}
public class Facebook{
// This is the Facebook class
private String content;
public void setContent(String newContent){
content = newContent+"_content";
}
public Facebook(){
content = "initial_content";
}
}
但我不确定我做错了什么......