Java Write statements from the client perspective to accomplish the following ta
ID: 3883093 • Letter: J
Question
Java
Write statements from the client perspective to accomplish the following task.
You are given two ListInterface<String> objects called letters and vowels.
letters contains one-letter strings.
vowels is initially empty.
Remove the Strings from letters.
If the String is a vowel, add it to the vowels list.
Otherwise, discard the String.
Once the letters list is empty, print out the number of vowels that are in the vowels list and the number of times each vowel appears in the list .
Notes:
You can use a second, initially empty ListInterface<String> object, called tempList, if it helps.
For full credit, do not use the toArray() method.
You decide whether y is a vowel or not! :)
For example, if letters initially contained:
a, f, v, q, e, a, o, g, y, h, e, q, u
Then after your code completes, letters will be empty and vowels will contain:
a, e, a, o, e, u
And your program will output something like this:
There are 6 vowels in the list:
a- 2
e- 2
i- 0
o- 1
u- 1
Explanation / Answer
Method for program let me know if you need entire program.
----------------------------------------------
if(!letters.isEmpty()){ // if letters are not empty
String letter = letters.getEntry(1); //letter = letters at position 1
int letterPosition = 1;
assert letter != null;
for(int i=2; i<=letters.getLength(); i++){
String currentLetter = letters.getEntry(i);
if(currentLetter.equals("a")){
letter = currentLetter;
letterPosition = i;
letters.remove(letterPosition);
vowels.add(letter);
}else if(currentLetter.equals("e")){
letter = currentLetter;
letterPosition = i;
letters.remove(letterPosition);
vowels.add(letter);
}else if(currentLetter.equals("i")){
letter = currentLetter;
letterPosition = i;
letters.remove(letterPosition);
vowels.add(letter);
}else if(currentLetter.equals("o")){
letter = currentLetter;
letterPosition = i;
letters.remove(letterPosition);
vowels.add(letter);
}else if(currentLetter.equals("u")){
letter = currentLetter;
letterPosition = i;
letters.remove(letterPosition);
vowels.add(letter);
}else{
letters.remove(letterPosition);
}
}
}
System.out.println(vowels.getLength());
for(int i = 2; i <=vowels.getLength(); i++){
System.out.println("vowels contains: " + i );
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.