Java - Write code to canonlize Punctuational Abbreviation

Requirements

Write code to canonlize Punctuational Abbreviation

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s1 = "he's a students";
        System.out.println(canonlizePunctuationalAbbreviation(s1));
    }// ww w  .j av  a 2  s  . com

    static String[] validHead = { "he", "she", "it", "they", "we", "there",
            "you", "I" };
    static String[][] substitionPattern = { { "'s", " is" },
            { "'re", " are" }, { "'d", " would" } };

    public static String canonlizePunctuationalAbbreviation(String s1) {
        String fin = s1;

        for (String head : validHead) {
            char[] temp = head.toCharArray();
            temp[0] = Character.toUpperCase(temp[0]);
            String head2 = String.valueOf(temp);
            for (String[] pair : substitionPattern) {
                String seeking = head + pair[0];
                String replacing = head + pair[1];
                fin = fin.replace(seeking, replacing);
                String seeking2 = head2 + pair[0];
                fin = fin.replace(seeking2, replacing);
            }
        }

        return fin;
    }
}

Related Exercise