Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a JAVA program to color code a population of binary population (made of

ID: 675418 • Letter: D

Question

Develop a JAVA program to color code a population of binary population (made of 0 or 1) based on the how crowded their neighborhood is. The population represents the presence/absence of an entity in a grid of 100X100 (their land). The color of an entity (its survival) depends on the population of its neighbors (3X3 grid around the cell).

If a cell is surrounded by less than 2 cells color code is white

If a cell is surrounded by 2 or 3 cells color code is green

If a cell is surrounded by 4 or 5 cells color code is blue

If a cell is surrounded by 6 or 7 cells color code is red

Otherwise color code is black

Develop a menu-driven GUI interface to allow the user to generate random populations and color code them. Create two menus:

File

About

Exit

Explanation / Answer

Solution :

// Code for neighborhood

Use the previous state when tracking neighbors.

We are calling a function newState() to assign a new state to each cell.

else

do nothing

// Menu-driven GUI Interface

public interface ActionListener

{ public void actionPerformed(ActionEvent e); }

public interface WindowListener

{

public void windowActivated(WindowEvent e);

public void windowClosed(WindowEvent e);

public void windowClosing(WindowEvent e);

public void windowDeactivated(WindowEvent e);

public void windowDeiconified(WindowEvent e);

public void windowIconified(WindowEvent e);

public void windowOpened(WindowEvent e);

}

public interface ListSelectionListener

{ public void valueChanged(ListSelectionEvent e); }

public interface Observer

{ public void update(Observable ob, Object arg); }

public interface Icon

{ public int getIconHeight();

public int getIconWidth();

public void paintIcon(Component c, Graphics g, int x, int y);

}