SlideShare a Scribd company logo
1 of 6
Download to read offline
Reply if you have any doubts.
public class Life {
public static final int DEAD = 0;
public static final int LIVING = 1;
public static final int DYING = 2;
public static final int BORNING = 3;
private int size;
private int[][] cells;
/* Constructor is done. */
public Life(int size) {
this.size = size;
cells = new int[size][size];
}
/* getSize is a stub. */
public int getSize() {
return this.size;
}
/* setState is a stub. */
public void setState(int row, int col, int state)
{
cells[row][col] = state;
}
/* getState is a stub. */
public int getState(int row, int col) {
return this.cells[row][col];
}
/* evolve is a stub. */
public void evolve()
{
//Creating tempArray
//only after full cycle cells should evolve
int[][] TempCells = new int[size][size];
//looping through all the cells
for(int i=0;i 3)
{
TempCells[i][j] = DEAD;
}
}
else if(CurrentState == DEAD)
{
if(NeighbourCount == 3)
{
TempCells[i][j] = LIVING;
}
}
}
}
//set the cells to nex gen states
this.cells = TempCells;
}
/* getNumberOfNeighbors is a stub; note that it's private. */
private int getNumberOfNeighbors(int row, int col)
{
int neighbourX[] = new int[8];
int neighbourY[] = new int[8];
neighbourX[0] = row - 1; neighbourY[0] = col - 1;
neighbourX[1] = row - 1; neighbourY[1] = col;
neighbourX[2] = row - 1; neighbourY[2] = col + 1;
neighbourX[3] = row; neighbourY[3] = col - 1;
neighbourX[4] = row; neighbourY[4] = col + 1;
neighbourX[5] = row + 1; neighbourY[5] = col - 1;
neighbourX[6] = row + 1; neighbourY[6] = col;
neighbourX[7] = row + 1; neighbourY[7] = col + 1;
for(int i=0;i<8;i++)
{
if(neighbourX[i] < 0)
neighbourX[i] = size - 1;
if(neighbourY[i] < 0)
neighbourY[i] = size - 1;
if(neighbourX[i] >= size)
neighbourX[i] = 0;
if(neighbourY[i] >= size)
neighbourY[i] = 0;
}
int count = 0;
for(int i=0;i<8;i++)
{
count += this.cells[neighbourX[i]][neighbourY[i]];
}
return count;
}
/* The main only instantiates the objects and sets them working. */
public static void main(String[] args) {
Life life = new Life(25);
CellWorld world = new CellWorld(life);
}
}
Solution
Reply if you have any doubts.
public class Life {
public static final int DEAD = 0;
public static final int LIVING = 1;
public static final int DYING = 2;
public static final int BORNING = 3;
private int size;
private int[][] cells;
/* Constructor is done. */
public Life(int size) {
this.size = size;
cells = new int[size][size];
}
/* getSize is a stub. */
public int getSize() {
return this.size;
}
/* setState is a stub. */
public void setState(int row, int col, int state)
{
cells[row][col] = state;
}
/* getState is a stub. */
public int getState(int row, int col) {
return this.cells[row][col];
}
/* evolve is a stub. */
public void evolve()
{
//Creating tempArray
//only after full cycle cells should evolve
int[][] TempCells = new int[size][size];
//looping through all the cells
for(int i=0;i 3)
{
TempCells[i][j] = DEAD;
}
}
else if(CurrentState == DEAD)
{
if(NeighbourCount == 3)
{
TempCells[i][j] = LIVING;
}
}
}
}
//set the cells to nex gen states
this.cells = TempCells;
}
/* getNumberOfNeighbors is a stub; note that it's private. */
private int getNumberOfNeighbors(int row, int col)
{
int neighbourX[] = new int[8];
int neighbourY[] = new int[8];
neighbourX[0] = row - 1; neighbourY[0] = col - 1;
neighbourX[1] = row - 1; neighbourY[1] = col;
neighbourX[2] = row - 1; neighbourY[2] = col + 1;
neighbourX[3] = row; neighbourY[3] = col - 1;
neighbourX[4] = row; neighbourY[4] = col + 1;
neighbourX[5] = row + 1; neighbourY[5] = col - 1;
neighbourX[6] = row + 1; neighbourY[6] = col;
neighbourX[7] = row + 1; neighbourY[7] = col + 1;
for(int i=0;i<8;i++)
{
if(neighbourX[i] < 0)
neighbourX[i] = size - 1;
if(neighbourY[i] < 0)
neighbourY[i] = size - 1;
if(neighbourX[i] >= size)
neighbourX[i] = 0;
if(neighbourY[i] >= size)
neighbourY[i] = 0;
}
int count = 0;
for(int i=0;i<8;i++)
{
count += this.cells[neighbourX[i]][neighbourY[i]];
}
return count;
}
/* The main only instantiates the objects and sets them working. */
public static void main(String[] args) {
Life life = new Life(25);
CellWorld world = new CellWorld(life);
}
}

More Related Content

Similar to Reply if you have any doubts.public class Life {    public stati.pdf

GameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdfGameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdf
aravlitraders2012
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan101
 
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxNewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
curwenmichaela
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
info382133
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
fonecomp
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdf
poblettesedanoree498
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lecture
anishgoel
 
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docxC346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
humphrieskalyn
 

Similar to Reply if you have any doubts.public class Life {    public stati.pdf (20)

Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Introduction to cpp (c++)
Introduction to cpp (c++)Introduction to cpp (c++)
Introduction to cpp (c++)
 
GameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdfGameOfLife.cs using System; using System.Collections.Generic;.pdf
GameOfLife.cs using System; using System.Collections.Generic;.pdf
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
TilePUzzle class Anderson, Franceschi public class TilePu.docx
 TilePUzzle class Anderson, Franceschi public class TilePu.docx TilePUzzle class Anderson, Franceschi public class TilePu.docx
TilePUzzle class Anderson, Franceschi public class TilePu.docx
 
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxNewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
 
#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx#include stdafx.h using namespace std; #include stdlib.h.docx
#include stdafx.h using namespace std; #include stdlib.h.docx
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
C++11 - STL Additions
C++11 - STL AdditionsC++11 - STL Additions
C++11 - STL Additions
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
i have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdfi have a code that runs, but it only lets the player to guess where .pdf
i have a code that runs, but it only lets the player to guess where .pdf
 
Huraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docxHuraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docx
 
ARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lectureARM 7 LPC 2148 lecture
ARM 7 LPC 2148 lecture
 
An introduction to Google test framework
An introduction to Google test frameworkAn introduction to Google test framework
An introduction to Google test framework
 
Kotlin Collections
Kotlin CollectionsKotlin Collections
Kotlin Collections
 
Kotlin for Android Developers
Kotlin for Android DevelopersKotlin for Android Developers
Kotlin for Android Developers
 
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docxC346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
C346_PA3_W12srccommonBaseThread.javaC346_PA3_W12srccommonB.docx
 

More from nareshsonyericcson

#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf
#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf
#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf
nareshsonyericcson
 
Look at the position of Pb in the periodic table .pdf
                     Look at the position of Pb in the periodic table .pdf                     Look at the position of Pb in the periodic table .pdf
Look at the position of Pb in the periodic table .pdf
nareshsonyericcson
 
The process of sperm competition is defined as ‘the competition with.pdf
The process of sperm competition is defined as ‘the competition with.pdfThe process of sperm competition is defined as ‘the competition with.pdf
The process of sperm competition is defined as ‘the competition with.pdf
nareshsonyericcson
 
TCO is the assessment of all life time costs from owning ertain kind.pdf
TCO is the assessment of all life time costs from owning ertain kind.pdfTCO is the assessment of all life time costs from owning ertain kind.pdf
TCO is the assessment of all life time costs from owning ertain kind.pdf
nareshsonyericcson
 
Outear includes the pinna (also called auricle), the ear canal, and .pdf
Outear includes the pinna (also called auricle), the ear canal, and .pdfOutear includes the pinna (also called auricle), the ear canal, and .pdf
Outear includes the pinna (also called auricle), the ear canal, and .pdf
nareshsonyericcson
 

More from nareshsonyericcson (20)

5 steps (make sure to press See full answer)- make observat.pdf
5 steps (make sure to press See full answer)- make observat.pdf5 steps (make sure to press See full answer)- make observat.pdf
5 steps (make sure to press See full answer)- make observat.pdf
 
2cosx=(cosxtanx+sinx)(tanx)taking RHS cosxtanx+sinx)(tanx)= .pdf
2cosx=(cosxtanx+sinx)(tanx)taking RHS  cosxtanx+sinx)(tanx)= .pdf2cosx=(cosxtanx+sinx)(tanx)taking RHS  cosxtanx+sinx)(tanx)= .pdf
2cosx=(cosxtanx+sinx)(tanx)taking RHS cosxtanx+sinx)(tanx)= .pdf
 
1.5 X 10-8Solution1.5 X 10-8.pdf
1.5 X 10-8Solution1.5 X 10-8.pdf1.5 X 10-8Solution1.5 X 10-8.pdf
1.5 X 10-8Solution1.5 X 10-8.pdf
 
#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf
#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf
#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf
 
Neuman System Model helps in studying the stressors, find out the de.pdf
  Neuman System Model helps in studying the stressors, find out the de.pdf  Neuman System Model helps in studying the stressors, find out the de.pdf
Neuman System Model helps in studying the stressors, find out the de.pdf
 
NaOH will completely react will acetic acid and t.pdf
                     NaOH will completely react will acetic acid and t.pdf                     NaOH will completely react will acetic acid and t.pdf
NaOH will completely react will acetic acid and t.pdf
 
the bonding between the carban and the nitrogen i.pdf
                     the bonding between the carban and the nitrogen i.pdf                     the bonding between the carban and the nitrogen i.pdf
the bonding between the carban and the nitrogen i.pdf
 
The salts are more ionic, more soluble they are i.pdf
                     The salts are more ionic, more soluble they are i.pdf                     The salts are more ionic, more soluble they are i.pdf
The salts are more ionic, more soluble they are i.pdf
 
They can form sulfides, but the metal sulfides th.pdf
                     They can form sulfides, but the metal sulfides th.pdf                     They can form sulfides, but the metal sulfides th.pdf
They can form sulfides, but the metal sulfides th.pdf
 
Look at the position of Pb in the periodic table .pdf
                     Look at the position of Pb in the periodic table .pdf                     Look at the position of Pb in the periodic table .pdf
Look at the position of Pb in the periodic table .pdf
 
Yes. A tree which has a root and nothing else.SolutionYe.pdf
Yes. A tree which has a root and nothing else.SolutionYe.pdfYes. A tree which has a root and nothing else.SolutionYe.pdf
Yes. A tree which has a root and nothing else.SolutionYe.pdf
 
First you will want to convert the molarity of ea.pdf
                     First you will want to convert the molarity of ea.pdf                     First you will want to convert the molarity of ea.pdf
First you will want to convert the molarity of ea.pdf
 
Will be uploaded shortlySolutionWill be uploaded shortly.pdf
Will be uploaded shortlySolutionWill be uploaded shortly.pdfWill be uploaded shortlySolutionWill be uploaded shortly.pdf
Will be uploaded shortlySolutionWill be uploaded shortly.pdf
 
The process of sperm competition is defined as ‘the competition with.pdf
The process of sperm competition is defined as ‘the competition with.pdfThe process of sperm competition is defined as ‘the competition with.pdf
The process of sperm competition is defined as ‘the competition with.pdf
 
The answer isA. Public, PrivateThe public and private community .pdf
The answer isA. Public, PrivateThe public and private community .pdfThe answer isA. Public, PrivateThe public and private community .pdf
The answer isA. Public, PrivateThe public and private community .pdf
 
TCO is the assessment of all life time costs from owning ertain kind.pdf
TCO is the assessment of all life time costs from owning ertain kind.pdfTCO is the assessment of all life time costs from owning ertain kind.pdf
TCO is the assessment of all life time costs from owning ertain kind.pdf
 
ROA = Net Income (2015) [Assets (2014) + Assets (2015)] 2= 220.pdf
ROA = Net Income (2015)  [Assets (2014) + Assets (2015)]  2= 220.pdfROA = Net Income (2015)  [Assets (2014) + Assets (2015)]  2= 220.pdf
ROA = Net Income (2015) [Assets (2014) + Assets (2015)] 2= 220.pdf
 
pH + pOH = 14 1. 14-12.2= 1.8pOH pOH = -log(kb) Kb = 10^-1.pdf
pH + pOH = 14 1. 14-12.2= 1.8pOH pOH = -log(kb) Kb = 10^-1.pdfpH + pOH = 14 1. 14-12.2= 1.8pOH pOH = -log(kb) Kb = 10^-1.pdf
pH + pOH = 14 1. 14-12.2= 1.8pOH pOH = -log(kb) Kb = 10^-1.pdf
 
Outear includes the pinna (also called auricle), the ear canal, and .pdf
Outear includes the pinna (also called auricle), the ear canal, and .pdfOutear includes the pinna (also called auricle), the ear canal, and .pdf
Outear includes the pinna (also called auricle), the ear canal, and .pdf
 
Lewis base is a donor of an electron pair (i.e., lone pair of ele.pdf
Lewis base is a donor of an electron pair (i.e., lone pair of ele.pdfLewis base is a donor of an electron pair (i.e., lone pair of ele.pdf
Lewis base is a donor of an electron pair (i.e., lone pair of ele.pdf
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 

Reply if you have any doubts.public class Life {    public stati.pdf

  • 1. Reply if you have any doubts. public class Life { public static final int DEAD = 0; public static final int LIVING = 1; public static final int DYING = 2; public static final int BORNING = 3; private int size; private int[][] cells; /* Constructor is done. */ public Life(int size) { this.size = size; cells = new int[size][size]; } /* getSize is a stub. */ public int getSize() { return this.size; } /* setState is a stub. */ public void setState(int row, int col, int state) { cells[row][col] = state; } /* getState is a stub. */ public int getState(int row, int col) { return this.cells[row][col]; } /* evolve is a stub. */ public void evolve() { //Creating tempArray //only after full cycle cells should evolve int[][] TempCells = new int[size][size]; //looping through all the cells for(int i=0;i 3)
  • 2. { TempCells[i][j] = DEAD; } } else if(CurrentState == DEAD) { if(NeighbourCount == 3) { TempCells[i][j] = LIVING; } } } } //set the cells to nex gen states this.cells = TempCells; } /* getNumberOfNeighbors is a stub; note that it's private. */ private int getNumberOfNeighbors(int row, int col) { int neighbourX[] = new int[8]; int neighbourY[] = new int[8]; neighbourX[0] = row - 1; neighbourY[0] = col - 1; neighbourX[1] = row - 1; neighbourY[1] = col; neighbourX[2] = row - 1; neighbourY[2] = col + 1; neighbourX[3] = row; neighbourY[3] = col - 1; neighbourX[4] = row; neighbourY[4] = col + 1; neighbourX[5] = row + 1; neighbourY[5] = col - 1; neighbourX[6] = row + 1; neighbourY[6] = col; neighbourX[7] = row + 1; neighbourY[7] = col + 1; for(int i=0;i<8;i++) {
  • 3. if(neighbourX[i] < 0) neighbourX[i] = size - 1; if(neighbourY[i] < 0) neighbourY[i] = size - 1; if(neighbourX[i] >= size) neighbourX[i] = 0; if(neighbourY[i] >= size) neighbourY[i] = 0; } int count = 0; for(int i=0;i<8;i++) { count += this.cells[neighbourX[i]][neighbourY[i]]; } return count; } /* The main only instantiates the objects and sets them working. */ public static void main(String[] args) { Life life = new Life(25); CellWorld world = new CellWorld(life); } } Solution Reply if you have any doubts. public class Life { public static final int DEAD = 0; public static final int LIVING = 1; public static final int DYING = 2; public static final int BORNING = 3; private int size;
  • 4. private int[][] cells; /* Constructor is done. */ public Life(int size) { this.size = size; cells = new int[size][size]; } /* getSize is a stub. */ public int getSize() { return this.size; } /* setState is a stub. */ public void setState(int row, int col, int state) { cells[row][col] = state; } /* getState is a stub. */ public int getState(int row, int col) { return this.cells[row][col]; } /* evolve is a stub. */ public void evolve() { //Creating tempArray //only after full cycle cells should evolve int[][] TempCells = new int[size][size]; //looping through all the cells for(int i=0;i 3) { TempCells[i][j] = DEAD; } } else if(CurrentState == DEAD) { if(NeighbourCount == 3)
  • 5. { TempCells[i][j] = LIVING; } } } } //set the cells to nex gen states this.cells = TempCells; } /* getNumberOfNeighbors is a stub; note that it's private. */ private int getNumberOfNeighbors(int row, int col) { int neighbourX[] = new int[8]; int neighbourY[] = new int[8]; neighbourX[0] = row - 1; neighbourY[0] = col - 1; neighbourX[1] = row - 1; neighbourY[1] = col; neighbourX[2] = row - 1; neighbourY[2] = col + 1; neighbourX[3] = row; neighbourY[3] = col - 1; neighbourX[4] = row; neighbourY[4] = col + 1; neighbourX[5] = row + 1; neighbourY[5] = col - 1; neighbourX[6] = row + 1; neighbourY[6] = col; neighbourX[7] = row + 1; neighbourY[7] = col + 1; for(int i=0;i<8;i++) { if(neighbourX[i] < 0) neighbourX[i] = size - 1; if(neighbourY[i] < 0) neighbourY[i] = size - 1; if(neighbourX[i] >= size) neighbourX[i] = 0;
  • 6. if(neighbourY[i] >= size) neighbourY[i] = 0; } int count = 0; for(int i=0;i<8;i++) { count += this.cells[neighbourX[i]][neighbourY[i]]; } return count; } /* The main only instantiates the objects and sets them working. */ public static void main(String[] args) { Life life = new Life(25); CellWorld world = new CellWorld(life); } }