Question: Using java. Phase 1: Chemicals First, implement the related classes Chemical and ChemicalList . The Chemical class should have: Two instance variables: the chemicals name

Using java. Phase 1: Chemicals

First, implement the related classes Chemical and ChemicalList.

The Chemical class should have:

Two instance variables: the chemicals name (a String), and a list of the other chemicals that it interacts with (a ChemicalList).

A constructor with one parameter giving the chemicals name. The list of interactions should initially be empty.

An instance method void addInteraction(Chemical) which will add an interaction between this chemical and another chemical. This interaction should be added to the list of interactions for both chemicals. So the call one.addInteraction(two) should add two to the list of interactions with one, and also add one to the list of interactions with two.

A standard toString method that returns only the name of the chemical.

A special String toStringExtended() method that will also include the list of interactions, on a separate line, preceded by a tab character (use and \t to create such a String). For example, see the sample output below, which uses this method.

The ChemicalList class should have:

Instance variables that will allow a list of up to 100 Chemical objects to be stored. Use a simple partially-full array to do this. You may assume that the list will never become full no error checking is needed.

A constructor with no parameters that creates an empty list.

An instance method void addChemical(Chemical) which will add a chemical to the list.

A standard toString method which will return the names of the chemicals, separated by commas. There should be no comma after the last chemical. See the sample output below for an example.

You can test your classes using the supplied test program TestPhase1.java. You should get the output shown below.

Chemicals

---------

1: aaratine

interacts with boricium

2: boricium

interacts with aaratine,eekamouse

3: catboxite

interacts with drystophan,eekamouse

4: drystophan

interacts with catboxite

5: eekamouse

interacts with boricium,faroutman,catboxite

6: faroutman

interacts with eekamouse

7: gooeygood

interacts with

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!