I have been trying to get the error correction portion of this program to work for days now and I just can't. Can someone please assist me.
I am teaching myself so I really am not familiar with much yet. I have just started...my third week.
import java.io.*;
public class Assign5
{
public static void main(String[]args) throws IOException
{
char str[] = new char[100];
int count =0;
BufferedReader read = new BufferedReader (new InputStreamReader (System.in));
String word;
String letter;
String input;
System.out.println("******Word Count, Formation & Reformation Function******");
System.out.println("\nEnter your word of choice ending with $ e.g. Scavenger$ ");
word = read.readLine();
do
{
if (Character.isSpaceChar(word.charAt(count)) == true)
{
System.out.println("You forgot the $ to indicate the end of the word");
System.out.println( "Enter word to which manipulation must be done, ending with $ e.g. Scavenger$");
word = read.readLine();
}
str[count]= word.charAt(count);
count ++;
}while (str[count -1] != '$');
int m = count -1;
System.out.println("\nThe number of letters in the word is " +m);
//Word Re-Formation Function
System.out.println("\nEnter a letter that you wish to stuff into your word");
letter = read.readLine();
System.out.println( "\nEnter the letter position (an integer) after which to stuff your letter");
input = read.readLine();
int n = Integer.parseInt(input);
n = n - 1 ;
while(n <= 0)
{
System.out.println("\nI am sorry...that position is invalid");
System.out.println("\nEnter the letter position (an integer) after which to stuff your letter");
input = read.readLine();
n = Integer.parseInt(input);
n = n-1;
}
char temp[] = new char[100];
int index = 0;
for(int i = (n+1);i <= m; i++)
{
index = index +1;
temp[index] = str;
}
str[n +1] = letter.charAt(0);
index = 1;
for(int i = (n+2); i <= (m+1) ; i++)
{
str[i] = temp[index];
index = index + 1;
}
//Printing the new word
System.out.print("\nThe new reconstructed word is: ");
for(int i = 0; i <= m ; i++)
{
System.out.print(str[i]);
}
System.out.println();
int newM = m + 1;
//Error Correction Module
System.out.print("\n\n\n\n\n\n****Error Correction Module****");
System.out.print("\nThe new reconstructed word is: ");
for(int i = 0; i <= m ; i++)
{
System.out.print(str[i]);
}
char errorLetter[] = new char[1];
do
{
System.out.println("\n\nEnter a letter that you wish to remove from your word");
input = read.readLine();
errorLetter[1] = input.charAt(1);
int position = 0;
for(int findLetter = 1; findLetter <= newM; findLetter++)
{
if(errorLetter[1] == str[findLetter])
{
position = findLetter;
}
if(position == 0)
{
System.out.println("I am sorry?that letter is NOT contained in the word.");
errorLetter[1] = ' ';
position = 0;
}
}
}while (errorLetter[1] == ' ');
/*System.out.println("The new word formed after removing your letter is: ");
for(i = 1; i <= 100; i++)
{
if(i == position)
{
str[i] = temp[i + 1];
for(fillLoop = i + 1; fillLoop <= 99; fillLoop++)
{
str[fillLoop] = temp[fillLoop + 1];
}
}
}
for(i = 0; i <= 100; i++)
{
System.out.print(str[fillLoop]);
}*/
}
}