1 / 16

Marine Biology Simulation Case Study Lab04 Slides Investigate the Utility Classes

Marine Biology Simulation Case Study Lab04 Slides Investigate the Utility Classes. MBCS Utility Classes/Interfaces. Debug class Direction class EnvDisplay interface Locatable interface Location class RandNumGenerator class. MBCS Black Box Classes.

jeslyn
Download Presentation

Marine Biology Simulation Case Study Lab04 Slides Investigate the Utility Classes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Marine Biology Simulation Case Study Lab04 Slides Investigate the Utility Classes

  2. MBCS Utility Classes/Interfaces Debug class Direction class EnvDisplay interface Locatable interface Location class RandNumGenerator class

  3. MBCS Black Box Classes The utility classes are also called the black box classes. The code for these classes are hidden in the jar files. You cannot see the implementation code of the utility classes, and you do need to know the code to understand and manipulate the MBCS. You do need to know the capabilities of these classes and how to use their available methods.

  4. Java Library ClassesUsed by MBCS ArrayList class Color class Random class The use of these Java library classes is not explained in the MBCS manual in any detail. However, an understanding of the use of these three classes is necessary for a better overall understanding of the MBCS program.

  5. What does the Debug class do? The Debug class allows you to observe MBCS simulation testing by viewing Debug messages. Debug messages appear in the text window, which is normally hidden behind the GUI window output of the MBCS execution. All Debug methods are static or class methods.

  6. // Debug class methods static void turnOn() // activates debugging; generates debug messages static void restoreState() // restores debugging to state prior to turnOn static void print (String message) // displays debug message with out line-feed static void println (String message) // displays debug messages with line-feed

  7. Where is Debugging Turned On? The Debug.turnOn(); activates debugging and can be placed in various methods of the Fish class. During the hands-on part of the Lab04 session you will be examining different approaches to activating the debug feature of the MBCS.

  8. The Other Utility Classes Interfaces EnvDisplay and Locatable along with classes Direction, Location and RandNumGenerator will not be studied or observed in detail during Lab04 beyond a listing of available methods.

  9. // Class Direction methods Direction () Direction (int degrees) Direction (String str) int inDegrees() boolean equals (Object other) Direction toRight () Direction toRight (int degrees) Direction toLeft () Direction toLeft (int degrees) Direction reverse () String toString () static Direction randomDirection () // The following methods are not tested: int hashCode () Direction roundedDir (int numDirections, Direction startingDir)

  10. // Interface EnvDisplay method void showEnv()

  11. // Interface Locatable method Location location()

  12. // Class Location methods Location (int row, int col) int row() int col() boolean equals (Object other) int compareTo (Object other) String toString() // The following method is not tested: int hashCode()

  13. // Class RandNumGenerator static Random getInstance()

  14. public class SimpleMBSDemo1 { private static final int ENV_ROWS = 10; // rows in environment private static final int ENV_COLS = 10; // columns in environment private static final int NUM_STEPS = 15; // number of timesteps private static final int DELAY = 1000; // delay in milliseconds public static void main(String[] args) { BoundedEnv env = new BoundedEnv(ENV_ROWS, ENV_COLS); Fish f1 = new Fish(env, new Location(2, 2)); Fish f2 = new Fish(env, new Location(2, 3)); Fish f3 = new Fish(env, new Location(5, 8)); SimpleMBSDisplay display = new SimpleMBSDisplay(env, DELAY); display.showEnv(); for ( int i = 0; i < NUM_STEPS; i++ ) { f1.act(); f2.act(); f3.act(); display.showEnv(); } } }

  15. public class SimpleMBSDemo2 { private static final int ENV_ROWS = 10; // rows in environment private static final int ENV_COLS = 10; // columns in environment private static final int NUM_STEPS = 15; // number of timesteps private static final int DELAY = 1000; // delay in milliseconds public static void main(String[] args) { BoundedEnv env = new BoundedEnv(ENV_ROWS, ENV_COLS); Fish f1 = new Fish(env, new Location(2, 2)); Fish f2 = new Fish(env, new Location(2, 3)); Fish f3 = new Fish(env, new Location(5, 8)); SimpleMBSDisplay display = new SimpleMBSDisplay(env, DELAY); Simulation sim = new Simulation(env, display); for ( int i = 0; i < NUM_STEPS; i++ ) { sim.step(); } } }

  16. public class MBSGUI1 { public static void main(String[] args) { String[] fishClassNames = {"Fish"}; DisplayMap.associate("Fish", new FishDisplay()); String[] boundedClassNames = {"BoundedEnv"}; String[] unboundedClassNames = {"UnboundedEnv"}; MBSFactory.addEnvObjClassNames(fishClassNames); MBSFactory.addBoundedEnvClassNames(boundedClassNames); MBSFactory.addUnboundedEnvClassNames(unboundedClassNames); MBSGUIFrame guiFrame = new MBSGUIFrame(); guiFrame.setVisible(true); } }

More Related