write program in C language, the first good answer will be rated. Below are the
ID: 3825479 • Letter: W
Question
write program in C language, the first good answer will be rated. Below are the contents of the file needed piglatinin.txt:
Program 1 English to Pig Latin Introduction As most of you know, pig Latin is a language game played with English words. It is based on discriminating between vowels and consonants within the word. (Note that a "vowel" is any of the characters "a 'e', 'i', o', or 'u'. A "consonant" is any non-vowel character.) Any English word can be converted to its pig Latin equivalent by using the following algorithm: l) Starting from the first character of the word, locate the position of the first vowel. 2) If there is a consonant (or a string of consonants) to the left of that position, do the following: a) Extract the leading consonant(s) from the word. What remains will begin with a vowel by definition. Let's call that the "residual string." b) Append an "ay" to the end of the consonant string creating a "suffix string c) Append the suffix string to the end of the residual string using a hyphen. 3) If the first letter of the word is a vowel, then append "-way" to the end of the word. For example, let's say we want to convert the word "cabin" to pig Latin. Following the above steps, we do the following: 1) We locate the position of the first vowel. This is the 'a' that occurs at index 1 in the string (i.e., it is the second letter in the string). 2) Since there is a leading consonant in this case, "c', it is removed from the word creating the residual string abin a) We take the consonant, c', append an "ay" to it, creating the suffix string cay b) We append that to the end of the residual string using a hyphen.Explanation / Answer
package Excercises;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class PigLatin {
private String word;
private String newWord;
private String[] Array;
private List<String> list = new ArrayList<String>();
public void initializeText() {
System.out.print("Welcome to the Pig Latin Game! Please enter a word: ");
}
public void getWord() {
Scanner scan = new Scanner(System.in);
this.word = scan.next();
}
public void convertWordToStringArray() {
this.Array = word.split("");
}
public void convertArrayToList() {
for(String s : this.Array) {
this.list.add(s);
}
}
public void moveFirstLetterToLast() {
this.list.add("-");
this.list.add(this.Array[0]);
this.list.remove(0);
this.list.add("ay");
}
public void mergeList() {
for(int i = 0; i < list.size(); i++) {
this.newWord = this.newWord + list.get(i);
}
this.newWord = this.newWord.replaceAll("null", "");
}
public String returnNewWord() {
return this.newWord;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.