clanecollege

Group Assignment Solution - Extended

May 14th, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.05 KB | None | 0 0
  1. public class GroupProject
  2.  
  3. {
  4.  
  5.     public static String weLoveTheLetterS(String word)
  6.  
  7.     {
  8.  
  9.         word = word.replaceAll(" ", "S");
  10.  
  11.         return word;
  12.  
  13.     }
  14.  
  15.     public static String weReallyLoveTheLetterS(String word)
  16.     {
  17.         String phrase = word;
  18.         phrase = phrase.replaceAll(" ", "S");
  19.  
  20.         // extend
  21.         char[] letters = phrase.toCharArray();
  22.         int flag = 0;
  23.             for (int i = 0;i < phrase.length();i++)
  24.             {
  25.                 if(letters[i] != 's' && letters != 'S')
  26.                 {
  27.                     if (flag == 0)
  28.                     {
  29.                         letters[i]='s';
  30.                         flag=1;
  31.                     }
  32.  
  33.                     else if (flag == 1)
  34.                     {
  35.                         letters[i]='S';
  36.                         flag = 0;
  37.                     }
  38.                 }
  39.             }
  40.         String answer = String.copyValueOf(letters);
  41.         return answer;
  42.     }
  43.  
  44.     public static boolean sequenceChecker(String stringToBeChecked,
  45.             String sequence)
  46.     {
  47.         boolean check = false;
  48.  
  49.         if (stringToBeChecked.contains(sequence))
  50.         {
  51.             return true;
  52.         }
  53.         return check;
  54.     }
  55.  
  56.     public static String replaceThis(String theWord, String letter1,
  57.             String letter2)
  58.     {
  59.         String res1 = "";
  60.         String res2 = "";
  61.         res1 = theWord.replaceAll(letter1, " ");
  62.         res2 = res1.replaceAll(letter2, " ");
  63.         return res2;
  64.     }
  65.  
  66.     public static void main(String[] args)
  67.  
  68.     {
  69.  
  70.         // extended questions - Q1
  71.  
  72.         String reallyLoveS = "I'd love it if every sentence that contained the letter s where the spaces are supposed to be";
  73.         System.out.println("Ext. Q1: " + weReallyLoveTheLetterS(reallyLoveS));
  74.  
  75.         // extended questions - Q2
  76.  
  77.         System.out.println("Ext. Q2: ");
  78.         String seqCheck = "abbcccdddeeefffgggiiisssiii!!!$$$";
  79.         System.out.println(sequenceChecker(seqCheck, "abb"));
  80.         System.out.println(sequenceChecker(seqCheck, "cdd"));
  81.         System.out.println(sequenceChecker(seqCheck, "i!!"));
  82.         System.out.println(sequenceChecker(seqCheck, "$$$"));
  83.         System.out.println(sequenceChecker(seqCheck, "dsa"));
  84.  
  85.         // extended questions - Q3
  86.         System.out.print("Ext. Q3: ");
  87.         String repThis = "This is the word that will be replaced shortly";
  88.         String lett1 = "e";
  89.         String lett2 = "a";
  90.  
  91.         System.out.println(replaceThis(repThis, lett1, lett2));
  92.  
  93.     }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment