Question: Java language Complementable Interface : Defi ne a typed interface Com plementable that specifi es the complement operation. Because this will be an object method,
Java language
Complementable Interface :Define a typed interface Complementable
BinaryWord Class:Create a BinaryWord class implementing the Complementable interface. Use java.util.BitSet as the underlying storage container. While the BinaryWord constructor implementation is up to you, using a String argument may be the most straightforward. The complement operation should yield a bitwise inversion of the word. For instance, the complement
of 001011 would be 110100. You should also implement equals and toString methods for later testing. What should the parameterized type be for the implements clause? If you're confused, you might refer to the java.lang.Comparable
Semigroup Class: Recall that a semigroup requires a binary operation, which means the operation takes two arguments. Define an abstract, typed class Semigroup
PositiveInteger Class: Create a (concrete) subclass of Semigroup called PositiveInteger. What should the parameterized type be for the extends clause? This is similar to Complementable,
except BinaryWord implements a generic interface while PositiveInteger extends a generic class. Implement the required method of the class (operator) using the typical add operation on integers. You should also implement equals and toString methods for later testing.
RGBColor Class : Create another (concrete) subclass of Semigroup called RGBColor. It should store three integers in the range 0-255. Because colors have complements, RGBColor should also implement the Complementable interface.The operator of the Semigroup will be color blending. That is, the components of the new color should be the (integer) average of the components of the two input colors. The complement operation should give a new color whose components are each 255 minus the original. For example, if [R/G/B] represents the three color components, the operator on [32/96/128] and [0/99/255] would yield [16/97/191]. The complement of the former would be [223/159/127]
Expanding Semigroup: An abstract class may as well be an interface if it has no members or concrete methods. Let's rectify that. Add one static method to your Semigroup class called combine that will compute accumulate the operator results sequentially for all the elements in a Collection (the parent interface of ArrayList) of any Semigroup objects. For example, employing the combine method on a collection of PositiveIntegers would yield their sum. You should use Java's enhanced for loop. We will take as a precondition that the collection is non-empty. Note that every item in the given Collection must be the same kind of Semigroup object, otherwise you probably would not be able to combine them (e.g., what's the operation on 5 and yellow??!?). Note that Collection will need to be imported from java.util.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
