Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java Create the Box class as defined by public class Box implements Comparable Each box object should have a String attribute and boxes should be
Java Create the Box class as defined by public class Box implements Comparable Each box object should have a String attribute and boxes should be compared by the length of these Strings. Override the toString method (inherited from Object) to simply display object's string attribute. A sample testing program is provided. It creates an array of boxes, prints them, sorts them and then prints them again. The testing program should output before sorting ------------------------ [kitten, cat, dog, oh, cow, oxen] after sorting ------------------------- [oh, cat, dog, cow, oxen, kitten] Change the strings array to be sure your code works correctly with different inputs. Comparable Complete the provided Team class by overriding the compareTo method (inherited from the Comparable interface) and overriding the toString() method (inherited from Object) as described below. Each team will have zero or more points. The number of points that a team has is two times the number of wins a team has plus the number of draws. So, if a team has 3 wins and 1 draw then that team has 7 points. Let A and B be two teams. The ordering of teams (when compared) is as follows: 1. A < B when A has less points than B. 2. A > B when A has more points than B. When A and B have the same amount of points, then a. A < B when A has played more games than B b. A > B when A has played less games than B 3. When A and B have the same amount of points and have played the same amount of games, then a. A < B when A has less wins than B b. A > B when A has more wins than B 4. A == B when A and B have the same amount of points, played the same number of games, have the same number of wins and same number of draws. 5. When you print a team object (toString()) it should be of the form "name[points]: w/l/d" where w,l,d are the wins, losses and draws of the team. For example, the output might look like Carleton[12]: 5/3/2 import java.util.Arrays; public final class TestBox{ private static String[] strings = {"kitten", "cat", "dog", "oh", "cow", "oxen"}; public static void main(String[] args){ Box[] boxes = new Box[ strings.length ]; for(int i=0; i
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