Problem a (EC1a.java) Write a program that converts words to the CS1 dialect of
ID: 3767251 • Letter: P
Question
Problem a (EC1a.java)
Write a program that converts words to the CS1 dialect of Pig Latin1. This program has several steps. To begin, you will first implement an isVowel method, which takes as arguments a character (the input to be tested) and a Boolean flag, which tells you whether or not ‘Y’ should be counted as a vowel – your method should return true if the input is a vowel, whether it is in upper- or lower-case. Next, write the pigLatin method, which accepts a single String argument and returns the Pig Latin translation as a String. Here are the basic rules for our dialect: 1. If the first letter in the word is in (A, E, I, O, U), add “way” to the end 2. Otherwise, find the first letter (left-to-right) that is in (A, E, I, O, U, Y), move all characters before it to the end of the word, and append “ay” a. If the first letter of the word was capitalized, you should make sure that the first letter of the translation is capitalized, and that the moved first letter is made lower-case (no other capitalization changes should be made) Finally, write the main method, which should prompt the user for a word, translate it into Pig Latin, and repeat until the user enters “exitway” (“exit” in Pig Latin; any case should be acceptable). Consider the following example run of the program:
Enter a word to translate (exitway to finish): Extra Extraway
Enter a word to translate (exitway to finish): Credit Editcray
Enter a word to translate (exitway to finish): eXitwaY
To write this program you may find it useful to reference the Oracle documentation for the String class2, which has several useful methods. In particular, see the substring and toUpperCase/toLowerCase methods, in addition to the length, equals, and charAt methods we’ve covered in class.
Explanation / Answer
import java.util.Scanner; public class PigLatin { public static void main(String[] args) { Scanner sc = new Scanner(System.in); final String vowels = "aeiouAEIOU"; System.out.println("Enter your word."); String word = sc.nextLine(); while (!word.equalsIgnoreCase("done")) { String beforVowel = ""; int cut = 0; while (cutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.