Question
In mathematics, a magma is a type of algebraic structure that has a set of elements, all of the same type, and one binary operation.
In mathematics, a magma is a type of algebraic structure that has a set of elements, all of the same type, and one binary operation. Such a pairing of a set (e.g., positive integers) with this operation is a semigroup when the operation is associative and produces an element from the same set.
Another common algebraic structure features a unary operation that is its own inverse, commonly called the complement. One example is the boolean complement operator, which takes a boolean and produces a boolean. By definition, applying a complrement operator twice gives the original value.
In this assignment, you will create a complement interface and semigroup abstract class support some general operations. You will then create fully concrete implementations of some familiar semigruops: positive integers paired with common addition, and RGB colors paired with a combination operation (e.g., averaging the color components of the two operands). You will also implement the complementable interface.
Complementable Interface
Define a typed interface Complementable that specifies the completement operation. Because this will be an object method, it takes on argument but produces an object of the (parameterized) complementable type.
BinaryWordClasss
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. Hint: you may want to check Integer class declaration in the Java API as an example.
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.
Semigroup Class
Recall that a semigroup requires a binary operation, which means the operation takes two arguements. Define an abstract, typed class Semigroup<AnyType>that speicfies an operator operation, which takes one argument. (Note that the other implicit argument of the operation is the object receiving the method call.)
Semigroup objects should be immutable; that is, any operation should return new objects of the generic type, rather than being mutators.
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 an interface while PositiveInteger extends a 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 of 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].
Testing
Demonstrate the functionality of your concrete classes by providing your test program.
Step by Step Solution
3.43 Rating (156 Votes )
There are 3 Steps involved in it
Step: 1
given code Mainjava import javautil public class Mainli public static void mainString args String binaryNum BinaryWord word comp PositiveInteger pos Intl posInt2 pos Int3 posIntSum int numberl number2 ...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