Advertisement
Guest User

Hawaii.java - Day 2

a guest
Nov 22nd, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. public class Hawaii{
  2.    private String word;//instance variable
  3.    
  4.    public Hawaii( String w ){//constructor
  5.       word = w;
  6.    }
  7.    
  8.    //method to check if hawaii word is valid
  9.    public boolean isValid(){
  10.       String legalCharacters = "aeioupkhlmnw '";
  11.       for( int i = 0; i < word.length(); i++ ){
  12.          String letter = word.substring(i, i+1);
  13.          if( legalCharacters.indexOf( letter ) == -1 ) return false;
  14.       }
  15.       return true;
  16.    }
  17.    
  18.    //method to determine if pair is special
  19.    private boolean isSpecialPair(String pair){
  20.       String[] pairs = {"ai", "ae", "ao", "au", "ei", "eu", "iu", "oi", "ou", "ui"};
  21.       for(int i = 0; i < pairs.length; i++){
  22.          if( pair.equals( pairs[i] ) ) return true;
  23.       }
  24.       return false;
  25.    }
  26.    
  27.    //method to return the pronunciation of the special pair
  28.    private String pronouncePair(String pair){
  29.       String[] pairs = {"ai", "ae", "ao", "au", "ei", "eu", "iu", "oi", "ou", "ui"};
  30.       String[] pronounce = {"eye", "eye", "ow", "ow", "ay", "eh-oo", "ew", "oy", "ow", "ooey"};
  31.       for(int i = 0; i < pairs.length; i++){
  32.          if( pair.equals( pairs[i] ) ) return pronounce[i];
  33.       }
  34.       return "";
  35.    }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement