Write a program in a class called Program. Your program will use two command lin
ID: 3919814 • Letter: W
Question
Write a program in a class called Program. Your program will use two command line arguments that specify a starting and stopping index (1 <= start < stop <= 26). Your program will then create an array of (stop - start + 1) Box objects. Each box’s a attribute will be a single letter in the alphabet and they will range from the start-th letter to the stop-th letter. For example, is start=2 and stop = 4, then the boxes will have attributes ”b”, ”c” and ”d”. The b attributes will be the corresponding upper case letters. Assume you have the public static arrays
String letters = "abcdefghijklmnopqrstuvwxyz";
String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
in your class (you do not need to rewrite these). Next, write a helper method that takes your box array as input and returns a new array of boxes that only contain the vowels present in the input. Have your program call this method and then print out the results.
Explanation / Answer
public class Program { public static boolean isVowel(char ch) { ch = Character.toLowerCase(ch); return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'; } public static Box[] filterVowelBoxes(Box[] boxes) { int count = 0; for(int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.