Question
Consider the Box class. public abstract class Box implements Comparable { public String a; protected String b; public Box(String a, String b){ this.a = a;
Consider the Box class.
public abstract class Box implements Comparable{ public String a; protected String b;
public Box(String a, String b){ this.a = a;
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 boxs 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.
Box.java
public abstract class Box implements Comparable{ public String a; protected String b; public Box(String a, String b){ this.a = a; this.b = b; } @Override //set it to final so that base class cannot redefined it public final int compareTo(Box boxIn) { //compare a first if(a.compareTo(boxIn.a)<0){ return -1; }else if(a.equalsIgnoreCase(boxIn.a)){ //if a are same than checking length of a+b int firstLength = a.length()+b.length(); int secondLength = boxIn.a.length() + boxIn.b.length(); if(firstLength return -1; }else if(firstLength==secondLength){ return 0; }else{ return 1; } }else{ return 1; } } }
Program.java???
Not sure how to do this one here. Thanks !
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started