Consider the Box class. this.b = b; Rewrite the class so that it is a concrete c
ID: 3920081 • Letter: C
Question
Consider the Box class.
this.b = b;
Rewrite the class so that it is a concrete class. The natural ordering of boxes is such that (let b1 and b2 be two box instances):
• b1 < b2 whenever b1.a comes before b2.a alphabetically (lexicographic).
• b1 < b4 whenever b1.a and b2.a are the same the length of b1.a + b1.b is less than the
length of b2.a + b2.b.
• b1 is equal to b2 when b1.a is the same as b2.a and the lengths of b1.a + b1.b and
b2.a + b2.b are the same.
This natural ordering should not be able to be redefined in any subclass.
2.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
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.
Box.java
Program.java???
Not sure how to do this one here. Thanks !
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.