0

3人の「語り部」にオリジナルに変更を加えてもらい、最初のストーリーを変更するプログラムを作成しようとしています。ただし、TellStory を実行しようとすると、プログラムは最終的に語られたストーリーに対して「nullnullnull」のみを出力します。私は何を間違えましたか?お時間をいただきありがとうございました:)

public class TellStory{
public String story;
public static void main(String[]args){
    String story="The three little pigs went shopping for lettuce. When they arrived at          the grocery store, they found they had forgotten their money. They asked the manager if they could have some credit, but he refused. The three little pigs saw their friend, Mr. Turtle, and he agreed to give them a loan. They went home happy and had a wonderful meal!";
    System.out.println("Welcome to my Story");
    System.out.println("");
    System.out.println("Initial Story:");
    System.out.println(story);
    System.out.println("");

    Storyteller1 Frank=new Storyteller1();
    Storyteller2 John=new Storyteller2();
    Storyteller3 Jake=new Storyteller3();

    String storyRetoldByFrank=Frank.getStory1();
    String storyRetoldByJohn=John.getStory2();
    String storyRetoldByJake=Jake.getStory3();

    String FinalRetoldStory=storyRetoldByFrank+storyRetoldByJohn+storyRetoldByJake;

    System.out.println("Final Retold Story:");
    System.out.println(FinalRetoldStory);
    }
}

public class Storyteller1 extends TellStory{
public String story1;
public String retellStory(String story1){
    int startIndex1=story.indexOf("three little pigs went");
    String subStr1=story.substring(startIndex1,startIndex1+17);
    String subStr2=story.replaceAll(subStr1,"four chickens");

    int startIndex2=story.indexOf("lettuce. When");
    String subStr3=story.substring(startIndex2,startIndex2+8);
    String subStr4=story.replaceAll(subStr3,"raisins");

    int startIndex3=story.indexOf("grocery store, they");
    String subStr5=story.substring(startIndex3,startIndex3+14);
    String subStr6=story.replaceAll(subStr5,"mall");

    int startIndex4=story.indexOf("money. They");
    String subStr7=story.substring(startIndex4,startIndex4+6);
    String subStr8=story.replaceAll(subStr7,"friend");

    story1=subStr2+" went shopping for "+subStr4+". "+"When they arrived at the    "+subStr6+", they found they had forgotten their "+subStr8+".";
    return story1;
    }
     public String getStory1(){
     return story1;
     }
}

public class Storyteller2 extends TellStory{
public String story2;
public String retellStory(String story2){
    int startIndex5=story.indexOf("manager");
    String subStr9=story.substring(startIndex5,startIndex5+8);
    String subStr10=story.replaceAll(subStr9,"security guard");

    int startIndex6=story.indexOf("some credit");
    String subStr11=story.substring(startIndex6,startIndex6+12);
    String subStr12=story.replaceAll(subStr11,"a phone");

    story2="They asked the "+subStr11+" if they could have "+subStr11+", but he refused.";
    return story2;
    }
     public String getStory2(){
     return story2;
     }
}

public class Storyteller3 extends TellStory{
public String story3;
public String retellStory(String story3){
    int startIndex7=story.indexOf("friend");
    String subStr13=story.substring(startIndex7,startIndex7+7);
    String subStr14=story.replaceAll(subStr13,"nemesis");

    int startIndex8=story.indexOf("Mr. Turtle");
    String subStr15=story.substring(startIndex8,startIndex8+11);
    String subStr16=story.replaceAll(subStr15,"Fearsome Fox");

    int startIndex9=story.indexOf("loan");
    String subStr17=story.substring(startIndex9,startIndex9+5);
    String subStr18=story.replaceAll(subStr17,"ride");

    int startIndex10=story.indexOf("happy and");
    String subStr19=story.substring(startIndex10,startIndex10+10);
    String subStr20=story.replaceAll(subStr19,"with Fearsome Fox - he");

    story3="The three little pigs saw their "+subStr14+","+subStr16+" and he agreed to     give them a "+subStr18+". They went home "+subStr20+"had a wonderful meal!";
    return story3;
    }
     public String getStory3(){
     return story3;
     }
}
4

2 に答える 2

3
  1. 誰もretellStoryメソッドを呼び出していないため、何も作成されていません...
  2. story1story2およびstory3には、値が割り当てられることはありません...
  3. storyによってアクセスされているインスタンス フィールドにはStoryteller1、値が割り当てられることはありません。Storyteller2Storyteller3nullNullPointerException
于 2013-10-14T00:06:12.227 に答える