January 9th, 2018
Classwork/Homework:
Design and implement a new ADT called Symbiopoly. A Symbiopoly object has a symbiotic relationship with a different ADT object. The purpose of this assignment is to work with an interface, Countable and appreciate its powerful feature: different objects share common members. This application is an example of polymorphic behavior that takes place during late binding.
The outline of the Symbiopoly ADT is very similar to the DataSet ADT.
Below is an example of the minimum required for this assignment’s driver. You need to write the code for the ADTs used in this application.
/* * @GE * @11/6/14 * @revisions 11/2/15, 11/26/16, 1/9/18 * A symbiotic system with different "countable" objects. * In this symbiotic system there are "complex" (e.g. clownfish) * and "simple" organisms (e.g. green algae) */ public class Symbiopoly { private int totalCount; private int symbioCount; private Countable mostSymbioticObjects; /** Constructs an empty symbiotic objects system. */ public Symbiopoly() { // total number of symbiotic objects in the whole symbiotic system // (e.g. # of anemones + # of clownfish + # of green algae organisms) totalCount = 0; // the symbiotic object with the most complex objects // (e.g. the anemone with most # of clownfish + # of green algae organisms mostSymbioticObjects = null; } ... // public void add( what????); // only one add method can be implemented - NO OVERLOADING ... }
An example of a test class:
/** This program tests the Symbiopoly class by creating a reef and adding sea life to it. */ public class CoralReefDriver { public static void main(String[] args) { // create sea life for the coral reef Anemone cnidarians = new Anemone("cnidarians"); // courtesy from Jason Shao Anemone condy = new Anemone("condy"); // courtesy from Jason Shao Anemone ritteri = new Anemone("ritteri"); // courtesy from Jason Shao Clownfish glowy = new Clownfish("glowy"); // courtesy from Jason Shao Clownfish bashful = new Clownfish("bashful"); // courtesy from Jason Shao Clownfish flowy = new Clownfish("flowy"); // courtesy from Jason Shao GreenAlgae gAlgeaS = new GreenAlgae("gAlgeaS"); // courtesy from Jason Shao GreenAlgae gAlgeaN = new GreenAlgae("gAlgeaN"); // courtesy from Jason Shao GreenAlgae gAlgeaE = new GreenAlgae("gAlgeaE"); // courtesy from Jason Shao GreenAlgae gAlgeaW = new GreenAlgae("gAlgeaW"); // courtesy from Jason Shao // add friends to an anemone cnidarians.add(glowy); cnidarians.add(bashful); cnidarians.add(gAlgeaS); cnidarians.add(gAlgeaW); // create a reef Symbiopoly redReef = new Symbiopoly(); // add sea life to the reef redReef.add(cnidarians); redReef.add(gAlgaeE); redReef.add(flowy); // print reef with most sea life System.out.println("Number of all symbiotic friends " + redReef.getTotalCount()); // get the number of symbiotic friends System.out.println("Number of friends in this object " + cnidarians.getSymbioCount()); // get the animal with the most sea life Countable mostSeaLife = redReef.mostSymbioticObjects(); // get the animal's name System.out.println("The species with the most friends: " + mostSeaLife.getName()); } }
Output samples: // @author: MS // OUTPUT: // Number of symbiotic friends 7 // Number of friends in this object 4 // The species with the most friends: Anemone
/** * ee * Driver for Symbiopoly * @author emily * * output: * Number of symbiotic friends 7 * Number of friends in this object 4 * The species with the most friends: Cnidarians * */
Natural History
This green plantlike creature is actually an animal with algae plants living inside it. In this symbiotic relationship, the algae gain protection from snails and other grazers and don’t have to compete for living space, while the anemones gain extra nourishment from the algae in their guts. Contrary to popular opinion, this anemone’s green color is produced by the animal itself, not the algae that it eats.
Use the Countable interface:
/** * Interface Countable: use the "implements" keyword to indicate that a class * implements an interface type. Unlike a class, an interface type provides no implementation * @GE * @11/6/14 * @revisions 11/2/15, 11/26/16 */ /** Describes any class whose objects can be counted. */ public interface Countable { /** Computes the number of object there are in a host. @return the count */ int getSymbioCount(); // count of symbiotic objects "this" object has(e.g. # of clownfish in each // anemones, # of green algae organisms in each anemones) int symbioCount; // it is "public"!!!!! so it can be accessed without getSymbioCount(); /** * animal's name */ String getName(); }