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

Java: Background Physics, Chemistry, Geology, and Material Science, among other

ID: 3751935 • Letter: J

Question

Java:

Background Physics, Chemistry, Geology, and Material Science, among other fields, all can include the study of Percolation Theory. Put simply, percolation concerns the movement and filtering of fluids through porous materials. (Thank you, Wikipedia.) Other applications of percolation modeling can examine movement of electricity or fire, but the idea is the same Given a grid consisting of open squares and closed squares, (think of the game "Minesweeper".) a simple percolation model checks whether there is a path through the open squares from the top of the grid to the bottom, without passing through closed squares or moving diagonally. To make things more interesting, the selection of which blocks are closed is typically generated using some random probability distribution. This technique belongs to a much larger class of computational algorithms called Monte Carlo methods, widely used to simulate complex physical and mathematical systems that cannot otherwise be well understood

Explanation / Answer

using System;

using System.Collections;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace RandomGrid

{

class Program

{

static void Main(string[] args)

{

RandomGrid grid = new RandomGrid(3);

grid.gridGenerate();

Console.WriteLine("**********************");

Console.WriteLine(grid.getValue(2, 2));

Console.WriteLine("**********************");

grid.setValue(0, 0, 10);

grid.gridGenerate();

Console.WriteLine("**********************");

Console.WriteLine("Size of the grid:{0} x {0}" , grid.getSize());

Console.ReadLine();

}

}

class RandomGrid {

public int Row { get; private set; }

public int Col { get; private set; }

public int Radius { get; private set; }

private List<int> _numbers;

private Random _rnd;

private int[][] randomGrid;

public RandomGrid(int n)

{

Row = n;

Col = n;

Random r = new Random();

var v = r.NextDouble();


_rnd = new Random();

_numbers = Enumerable.Range(0,Row * Col).OrderBy(_ => _rnd.Next()).ToList();

this.randomGrid = new int[n][];

for (int i = 0,k = 0; i < n; i++, k = k + n)

{

this.randomGrid[i] = new int[] { _numbers[k],_numbers[k+1],_numbers[k+2]};

}

}

public void gridGenerate()

{

for (int i = 0; i < this.Row; i++)

{

for (int j = 0; j < this.Col; j++)

{

Console.WriteLine(this.randomGrid[i][j]);

}

}

}

public int getValue(int row, int col)

{

if (row < Row && col < Col)

{

return this.randomGrid[row][col];

}

else

{

return 0;

}

}

public void setValue(int row, int col, int value)

{

if (row < Row && col < Col)

{

randomGrid[row][col] = value;

Console.WriteLine("Value set success....");

}

else

{

Console.WriteLine("Error in setting value..");

}

}

public int getSize()

{

return randomGrid.Length;

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote