hibby jibby 123456789
<p>I am currently trying to create an application that can shorten a word with its abbreviation 
   that is stored in an external text file. The word can be followed by punctuation
   characters which should also be retained after shortening. </p>

<p>I am unable to have the method return the original word if it cannot find an 
   abbreviation for it. By the looks of it the method isn't reaching my final return statement and
   I am unsure why.</p>

<pre><code>public class WordShortener {


private Scanner fileIn;
private String shortenedWord ="";
private String s="";

    public WordShortener() throws Exception {
    // to be completed
    Scanner fileIn = new Scanner(new File("abbs.txt"));
    this.fileIn = fileIn;
    }

public String wordShortener( String WordToShorten ) {
    // to be completed
        String s = wordToShorten;
            String shortened ="";
        while ( shortenedWord.equals(WordToShorten) &amp;&amp; fileIn.hasNextLine()  ) {
            String line = fileIn.nextLine();
            String punctuationChar="";
            String[] lines = line.split(",");
            String originalWord = lines[0];
            String shortenedWord = lines[1];
            String punctuations = "'?.";

            if ( punctuations.contains(s.substring(s.length() - 1)) ) {
                punctuationChar = s.substring(s.length() - 1);
            }

            if ( wordToShorten.contains(lines[0]) ) {
                String shortenedWord = s.replaceAll(wordToShorten, lines[1]);
                shortenedWord = shortened + punctuationChar;
            }
        }
        if ( shortenedWord == wordToShorten ) {
            return wordToShorten;
            }
fileIn.close();
return shortenedWord;
}

this is the otherfile that is used to conduct the shortenWord message on a given word(I have imported java util and java io in the file on my computer:



public class cmdShortener {


    public static void main(String[] args) throws Exception {
        WordShortener WS = new WordShortener();
        String return = WS.shortenWord("hello");
        System.out.println( "Shortened Message:" + return );
        }
}
</code></pre>

<p>some example lines from abbreviations file seperated by commas (these will not be edited):</p>

<p>eight,8</p>

<p>nine,9</p>

<p>you,u</p>
