Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

Hi, you helped me before with my Java program.  I need help again. 

Hi, you helped me before with my Java program.  I need help again.  I am getting errors when I run my

fill-in-the-blanks Java program.  Can you take a look and help me with fixing it? Initially, I thought the errors were related to this line in my code: for(int i=0;i<st.length();i++)

But this doesn’t appear to be the issue.  I continue to receive this error message: Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range:

Here are my files and the instructions.

/*When developing programs, you must consider the problems that may arise and* the exceptions that Java could throw as a result of those problems. In this* Application, you develop a program that reads in a story template from afile,* prompts the user to supply missing words, and then displays the completed* story. Exceptions that this type of program would need to handle may include* an inability to locate the story template file or another I/O problem.** Create a text file containing a story, with “blanks” (terms in brackets) to* be filled in.*/package blanksstory;import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.Scanner;import javax.swing.JFileChooser;import javax.swing.JOptionPane;/**** @author*/public class BlanksStory {ArrayList<String> str =new ArrayList<>();public BlanksStory()//Reads in the story.txt file{File file=null;JFileChooser chooser = new JFileChooser();chooser.setDialogTitle(“Load which file?”);int result = chooser.showOpenDialog(null);if (result == JFileChooser.APPROVE_OPTION) {file = chooser.getSelectedFile();}String fileName=null;try{fileName = file.getCanonicalPath();}catch(IOException e){System.out.println(“Input ouput Exception “);System.exit(1);}catch(Exception e){int i= JOptionPane.showConfirmDialog(null,”Do You Want to Try to ReadAnother File?”,”Error”,0);if(i==0){new BlanksStory();}elseSystem.exit(2);}try{BufferedReader myReader =new BufferedReader(new FileReader(fileName));int i=0;
Background image of page 1
while(myReader.ready()){str.add(myReader.readLine());}}catch(FileNotFoundException e){int i= JOptionPane.showConfirmDialog(null,”Do You Want to Try to ReadAnother File?”,”Error”,0);if(i==0){new BlanksStory();}elseSystem.exit(2);}catch(IOException e){System.out.println(“Error While Reading the File”);System.exit(1);}}public void play(){Scanner input = new Scanner(System.in);ArrayList<String> out =new ArrayList<>();int count=0;for(String st:str){StringBuffer sb=new StringBuffer();int initalIndex=0;String temp=st,temp1;for(int i=0;i<st.length();i++){if(st.charAt(i)=='[‘){int inital=i;while(st.charAt(i)!=’]’)i++;int finalIndex=i;String subStr=st.substring(inital+1,finalIndex);String replaceStr = st.substring(inital,finalIndex+1);if(subStr.equalsIgnoreCase(“adjective”)||subStr.equalsIgnoreCase(“intransitive verb”)||subStr.equalsIgnoreCase(“adverb”)){System.out.print(“Enter in an “+subStr+ ” : “);}else{System.out.print(“Enter in a “+subStr+” : “);}String sub =input.next();temp=st.replace(replaceStr,sub);sb.append(temp.substring(initalIndex,temp.indexOf(sub)+sub.length()));initalIndex=temp.indexOf(sub)+replaceStr.length()+1;}}out.add(sb.toString());}for(String st:out){
Background image of page 2

Show 

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"