Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

---------------------------------------------------- TestPhase1 public class TestPhase1 { public static void main(String[] args) { //Create test chemicals Chemical aar = new Chemical(aaratine); Chemical bor = new Chemical(boricium);

image text in transcribed

----------------------------------------------------

TestPhase1

public class TestPhase1 { public static void main(String[] args) { //Create test chemicals Chemical aar = new Chemical("aaratine"); Chemical bor = new Chemical("boricium"); Chemical cat = new Chemical("catboxite"); Chemical dry = new Chemical("drystophan"); Chemical eek = new Chemical("eekamouse"); Chemical far = new Chemical("faroutman"); Chemical goo = new Chemical("gooeygood"); //Create test interactions aar.addInteraction(bor); cat.addInteraction(dry); eek.addInteraction(bor); eek.addInteraction(far); cat.addInteraction(eek); //Print results to verify correct operation System.out.println(" Chemicals ---------"); System.out.println("1: "+aar.toStringExtended()); System.out.println("2: "+bor.toStringExtended()); System.out.println("3: "+cat.toStringExtended()); System.out.println("4: "+dry.toStringExtended()); System.out.println("5: "+eek.toStringExtended()); System.out.println("6: "+far.toStringExtended()); System.out.println("7: "+goo.toStringExtended());

} }

Phase 1: Chemicals First, implement the related classes Chemical and ChemicalList.+ The Chemical class should have: Two instance variables: the chemical's name (a String), and a list of the other chemicals that it interacts with (a ChemicalList). A constructor with one parameter giving the chemical's 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.v 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 TestPhasel.java. You should get the output shown below. Chemicals+ 1: aaratine 2: boricium+ 3: catboxite+ 4: drystophan 5: eekamouse+ 6: faroutmant interacts with boricium interacts with aaratine,eekamouse+ interacts with drystophan, eekamouse+ interacts with catboxite interacts with boricium, faroutman, catboxitev interacts with eekamouse interacts with 7: gooeygood

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

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

Identify career planning approaches.

Answered: 1 week ago