Hi All,
First of all Here is the question and what I have done so far.
A) The helper method boolean isVowel (char c) should return true if the character it recieves is an uppercase or lowercase English vowel. For Our purposes, Vowels are the letters a, e, i, o, and u. The metod should do this by checking if the character c is contained in a string composed of vowel characters.
B) The public String shorthand(String in) method should use the class StringBuilder to build an output string by appending non-vowel characters from its argument in to the result it returns. You will need to identitfy vowels to be removed using the helper method you developed in part (a).
C) The run method of this class should contain a loop that repeatedly prompts the user to enter a line of text from the keyboard, using Scanner class to read the input.
After each line is entered and return is pressed , the method should repeat the text back to the user but with any vowels removed using shorthand method and the method should terminate if when user enters *
I have done all the code but not sure if it it correct and specially the last method.
import java.io.*;
import java.util.*;
import java.util.Scanner;
public class Shorthand
{
public boolean isVowel(char c)
{
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A'|| c == 'E'||c == 'I'|| c == 'O'|| c == 'U')
{
return true;
}
else
{
return false;
}
}
//TODO Complete the shorthand method
public String shorthand(String in)
{
StringBuilder vowel = new StringBuilder();
for (int i=0; i < in.length(); i++)
{
if (isVowel(in.charAt(i)) == false)
{
vowel.append(in.charAt(i));
}
}
return vowel.toString();
}
//TODO Complete the run method
public void run() throws IOException
{
String txt = "";
Scanner sc = new Scanner(System.in);
for(int i = 0; i < sc.length; i++)
{
System.out.println("Enter your line text");
txt.append(shortHand);
String line = sc.nextLine();
if (line.equals("*")) break;
String shortHandLine = shorthand(line);
System.out.println(String.format("Short hand form", line, shortHandLine));
}
}
}