import
java.io.*;
/**
* Has all the reversing, circling and
shifting methods on Strings
* Will implement all methods within main and
do all the output
* @author James Kempsell
* Oregon Episcopal School Intermediate
*/
public
class BitString
{
private MethodHolder[] toBeRun = new
MethodHolder[5];
/**
* Constructor for objects of class
BitString
*/
public BitString(String filename){
try
{
BufferedReader in = new
BufferedReader(new FileReader(filename));
String str;
int i = 0;
while ((str = in.readLine()) != null)
{
toBeRun[i] = new
MethodHolder(str);
i++;
}
in.close();
}
catch (IOException e) {
System.out.println("cannot open
or read from input file");
}
}
/**
*
* Left Shift (eliminate to #'s)
* @param
y a sample parameter for a
method
* @return the sum of x and y
*/
public static String leftShift(String
bitString, int X){
String rightSection =
bitString.substring(X);
for(int i = 0; i < X; i++)
rightSection += "#";
return rightSection;
}
public static String rightShift(String
bitString, int X){
String leftSection = bitString.substring(0,bitString.length()-X);
for(int i = 0; i < X; i++)
leftSection = "#" +
leftSection;
return leftSection;
}
public static String leftCircle(String
bitString, int X){
String rightSection = bitString.substring(X),
leftSection = bitString.substring(0,X);
return rightSection+leftSection;
}
public static String rightCircle(String
bitString, int X){
String rightSection =
bitString.substring(bitString.length()-X), leftSection = bitString.substring(0,bitString.length()-X);
return rightSection+leftSection;
}
public static String
multipleCircles(String bitString, int position, int length, int movement, char
direction){
String leftSection =
bitString.substring(0,position-1), middle =
bitString.substring(position-1,position+length-1), rightSection =
bitString.substring(position+length-1);
if(direction == 'L')
return leftSection +
BitString.leftCircle(middle, movement) + rightSection;
if(direction == 'R')
return leftSection +
BitString.rightCircle(middle, movement) + rightSection;
return "error?!";
}
public static String reverseString(String
reversed){
char[] newString = new
char[reversed.length()];
int j = 0;
for(int i = reversed.length(); i >
0; i--){
newString[j] =
reversed.charAt(i-1);
j++;
}
return new String(newString);
}
public static String reverseSection(String
bitString, int position, int length){
String leftSection =
bitString.substring(0,position-1), middle =
bitString.substring(position-1,position+length-1), rightSection =
bitString.substring(position+length-1);
middle =
BitString.reverseString(middle);
return
leftSection+middle+rightSection;
}
public static void main(String[] args){
BitString finalOutput = new
BitString("BitStringInput.txt");
for(int i = 0; i < 5; i++){
for(int j = 0; j <
finalOutput.toBeRun[i].getMethodAndString().length-1; j++){
finalOutput.toBeRun[i].chooseMethod(j);
}
System.out.println(finalOutput.toBeRun[i].getMethodAndString()[finalOutput.toBeRun[i].getMethodAndString().length-1]);
}
}
}