Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions

Question

1 . Television News channels importantance of our Life pattern ?

Answered: 1 week ago

Question

1. How is the newspaper help to our daily life?

Answered: 1 week ago

Question

1. Prepare a short profile of Mikhail Zoshchenko ?

Answered: 1 week ago

Question

What is psychology disorder?

Answered: 1 week ago

Question

=+ What do you think about the Feds recent policy decisions?

Answered: 1 week ago