Guest User

Untitled

a guest
Feb 6th, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Poetry{
  4.  
  5.   public static void main(String [] args) {
  6.    Scanner s=new Scanner(System.in);
  7.    int verses= s.nextInt();
  8.    char[][] lines= new char[verses*4][];
  9.    String[] rhymeType= new String[verses];
  10.    String[] lastSyllable= new String[verses*4];
  11.    
  12.    s.nextLine();
  13.    for(int i=0; i< verses*4; i++){
  14.      lines[i]=s.nextLine().toLowerCase().toCharArray();
  15.      
  16.      for( int o= lines[i].length-1; o>-1; o--){
  17.        if(lines[i][o]=='a'||lines[i][o]=='e'||lines[i][o]=='i'||
  18.           lines[i][o]=='o'||lines[i][o]=='u'||lines[i][o]==' '){
  19.          lastSyllable[i]= new String(lines[i], o, (lines[i].length-1)-o);
  20.          break;
  21.        }
  22.        // have to put this else if here, otherwise one letter lines with no vowel or space will
  23.        // just be skipped past on the first go and not be added into lastSyllable
  24.        else if(lines[i].length==1){
  25.          lastSyllable[i]= new String(lines[i]);
  26.        }
  27.      }
  28.    }
  29.    
  30.    for(int i=0; i< verses*4; i=i+4){// when comparing objects, use object.equals(object) to test whether values are equal,
  31.                                     // == just tests for reference equality( whether they are same object)
  32.      if(lastSyllable[i].equals(lastSyllable[i+1])&&lastSyllable[i+1].equals(lastSyllable[i+2])&&
  33.         lastSyllable[i+2].equals(lastSyllable[i+3]))
  34.        rhymeType[i/4]="perfect";
  35.      else if(lastSyllable[i].equals(lastSyllable[i+1])&&lastSyllable[i+2].equals(lastSyllable[i+3]))
  36.        rhymeType[i/4]="even";
  37.      else if(lastSyllable[i].equals(lastSyllable[i+2])&&lastSyllable[i+1].equals(lastSyllable[i+3]))
  38.        rhymeType[i/4]="cross";
  39.      else if(lastSyllable[i].equals(lastSyllable[i+3])&&lastSyllable[i+2].equals(lastSyllable[i+1]))
  40.        rhymeType[i/4]="shell";
  41.      else
  42.        rhymeType[i/4]="free";
  43.    }
  44.    
  45.     for(String xd: rhymeType){
  46.      System.out.println(xd);
  47.     }
  48.    
  49.   }
  50. }
Add Comment
Please, Sign In to add comment