Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Abstract Classes and Interfaces In mathematics, a magma is a type of algebraic structure that has a set of elements, all of the same

Java Abstract Classes and Interfaces

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.

BinaryWord Classs

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 Semigroupthat 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

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

Does the business have a well-defined target market?

Answered: 1 week ago