// CSE 142, Summer 2008 (Helene Martin) // Determines whether a two-line verse is "good." // Good couplets get at least two points according to rules: // 1 point for the two verses being within 4 characters of each other // 1 point for "rhyming" (same 2 letters) // 1 point for alliteration import java.util.*; public class CheckCouplet { public static void main(String[] args) { System.out.println("Let's check that couplet!\n"); Scanner console = new Scanner(System.in); System.out.print("First verse: "); String verse1 = console.nextLine().toLowerCase(); System.out.print("Second verse: "); String verse2 = console.nextLine().toLowerCase(); int points = 0; // check lengths if(Math.abs(verse1.length() - verse2.length()) <= 4) { points++; } // check whether they end with the same two letters if(verse2.length() >= 2 && verse1.endsWith(verse2.substring(verse2.length() - 2))) { points++; } // check whether they alliterate if(verse1.startsWith(verse2.substring(0, 1))) { points++; } if(points > 1) { System.out.println(points + " points: Keep it up, lyrical genius!"); } else { System.out.println(points + " points: Aw, come on. You can do better..."); } } }