jeudi 12 mars 2015

AutoCorrect/Replace a word that is similar to a word in a file text



The intentions of this program is to prompt a user to enter a file name, and then reads the file. The program will prompt the user to enter a word that needs to be corrected. So lets say I have a text file containing "My name is OP and I Like goind to the Park!" I want to change "goind" to "going",


Now, my second method "isSimilar" executes a similar word with more than one same letter and same length, but I dont know how to execute that whole thing in my third method "correctThisLine" . Any tips on how i can call that isSimilar method and read in that text file and change that word into that?


Sorry for my newbie code, its amongst my first assignments. Much appreciated ! :)



import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class WahidMuhammadA3Q2{

String fileName = "AutoCorrectMe.txt";
public static void main (String [] args){
Scanner sc = new Scanner (System.in);

String name = getFileName();
}


public static String getFileName(){
Scanner sc = new Scanner (System.in);
String name;

do {
System.out.println("Please enter the name of the file, and include .txt");
name = sc.nextLine();
}while (!name.toLowerCase().endsWith(".txt"));

return name;
}

public static boolean isSimilar(String s1, String s2)
{
boolean similarWords = true;

if(s1.length()!=s2.length()){
return similarWords = false;
}

for (int i = 0; i<=s1.length(); i++){
for (int j = 0; j<=s2.length(); j++){
if(s1.charAt(i)!=s2.charAt(j)){
return similarWords = false;
}
else return similarWords;
}
}
return similarWords; }

public static String correctThisLine(String currentLine, String correctedWord){
Scanner sc = new Scanner (System.in);

Scanner file = new Scanner(fileName);

System.out.println("which word would you like to auto correct: ");
String correctWord = sc.nextLine();



}
}



Aucun commentaire:

Enregistrer un commentaire