import jan.*; class MyString { String string; MyString(String string) { this.string=string; } public void delSub (String subString) { String sub1, sub2; int subIndex = string.indexOf(subString); int subLength = subString.length(); int strLength = string.length(); if (subIndex==-1) { Biotope.message("No such substring found."); } else { sub1=string.substring(0, subIndex); sub2=string.substring(subIndex+subLength); string=sub1+sub2;} } public void repSub (String subString, String newString) { String sub1, sub2; int subIndex=string.indexOf(subString); int subLength=subString.length(); int strLength = string.length(); if (subIndex==-1) { Biotope.message("No such substring found."); } else { sub1=string.substring(0, subIndex); sub2=string.substring(subIndex+subLength); string=sub1+newString+sub2;} } public void insSub(String subString, int pos) { String sub1, sub2; if (pos<0 || pos > string.length() ) Biotope.message("The position is out of bounds."); else { sub1=string.substring(0,pos); sub2=string.substring(pos); string = sub1 + subString+sub2; } } } public class A3P2 extends Biotope implements Executable { public static void main (String arguments []) {main ("A3P2", "mode=input,output");} MyString source; String sourceStr, oper; public void initialize () { addDataLine ("abcdefg i xxxx 3"); message("Insert: string i string2 index"); message("Delete: string d string2"); message("Replace: string r string2 string3"); } public void execute () { sourceStr=readString(); source=new MyString(sourceStr); oper = readString(); String sub = readString(); switch (oper.charAt(0)) { case 'i': int position=readInteger()-1; if ((position<0) || (position>sub.length()+4)) { message("Out of bounds"); break;} else source.insSub(sub, position); break; case 'd' : source.delSub(sub); break; case 'r' : String sub2 = readString(); source.repSub(sub, sub2); break; default: message("Sorry, this operation is not supported.");} writeln(source.string.toString()); } }