Profile cover photo
Profile photo
Anis Alam
68 followers -
Dreamer, Enthusiasitc , Humorous and of course a tech geek.
Dreamer, Enthusiasitc , Humorous and of course a tech geek.

68 followers
About
Anis's posts

Post has shared content
I have a code if anyone could help me that would be great :

(below the code is an explanation of what I would like to get with the code)

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

class Name {

public static String name;
}

public class Project8a {

private static int populatedCells = 1;
private static int unpopulatedCells = 0;


public static void main(String[] args) throws InterruptedException, ParseException{


//int populatedCells = 100, unpopulatedCells = 100;
Scanner scan = new Scanner(System.in);
int mat[][] = new int[10][10];

//get time of day, etc...
timeOfDay();

System.out.println("\nPlease enter list of (i,j) pairs for populated cells (negative i or j to quit) : ");

int i = scan.nextInt();
int j = scan.nextInt();

while(i >= 0 && j >= 0){

mat[i][j] = 1;
i = scan.nextInt();
j = scan.nextInt();

}


System.out.println("Enter number of time steps : ");
int numberOfTimeSteps = scan.nextInt();


System.out.println("Intial Grid : \n");

/********************************

attempt to loop through time steps
and try to use / test 'sleep' method
do {
displayGrid(mat);
}while(mat[i][j] <= 10);

*********************************/
//display and print-out 10x10 grid
displayGrid(mat);
//update cells within 10x10 grid
updateGrid(mat);

}

public static void displayGrid(int mat[][]){


for (int i = 0; i < 10; i++){
System.out.print(i);
}
System.out.println();
System.out.print(" ");
for (int i = 0; i < 10; i++){
System.out.println(i);
for (int j = 0; j < 10; j++){

if(mat[i][j] == 1)
System.out.print("#");
else {
System.out.print(" ");

}
}

/***********************

attempt to make outer-edge
cells = '0'
if(i == 0 || j == 0){
mat[i][j] = 0;
}

************************/




}


}


public static void updateGrid(int mat[][])

throws InterruptedException{
int i = 0;
int j = 0;
int newArray[][] = new int[mat[i].length][mat[j].length];
int populatedCells = 1;
//for(b = 0; b < [mat[i].length][mat[j].length];
//int unpopulatedCells = 2;
int neighborCells = 8;

if(neighborCells <= 1 || neighborCells >= 4)
populatedCells = 0;
else if (neighborCells == 3)
populatedCells = 1;

/**********************************************************************************

For a cell that is “populated”, if the cell has <= 1 neighbors,
or >= 4 neighbors, it dies (becomes 0). Otherwise,
it survives (remains 1). For a cell that is not populated,
if the cell has exactly 3 neighbors, it becomes populated (becomes 1).
Cells on the edge always remain unpopulated (0).

**********************************************************************************/

System.out.println("\n");
System.out.print("Now testing sleep method (for 5 seconds) : ");
System.out.println();
System.out.println();
Thread.sleep(1000);
System.out.println("5");
Thread.sleep(1000);
System.out.println("4");
Thread.sleep(1000);
System.out.println("3");
Thread.sleep(1000);
System.out.println("2");
Thread.sleep(1000);
System.out.println("1");
Thread.sleep(1000);
System.out.print("0");
Thread.sleep(1000);
System.out.print(".");
Thread.sleep(1000);
System.out.print(".");
Thread.sleep(1000);
System.out.print(".\n");
Thread.sleep(2500);
System.out.print("\nBlast!!! It worked!!!\n\n");
Thread.sleep(4000);
System.out.println("Ah you thought it was over HAHA!!!");
System.out.println("Actually that was six seconds!!!\n");
Thread.sleep(1000);
System.out.print("S");
Thread.sleep(750);
System.out.print("E");
Thread.sleep(750);
System.out.print("E" + " ");
Thread.sleep(750);
System.out.print("Y");
Thread.sleep(750);
System.out.print("A");
Thread.sleep(750);
System.out.print("H");
Thread.sleep(750);
System.out.print("!");
Thread.sleep(750);
System.out.print("!");
Thread.sleep(750);
System.out.print("!" + " ");
Thread.sleep(1000);

for (int c = 0; c < Name.name.length(); c++) {
System.out.print(Name.name.charAt(c));
Thread.sleep(750L);
}



}public static int timeOfDay() throws ParseException{

Scanner scan = new Scanner(System.in);
System.out.println("First off, please enter your name for the database storage : ");
Name.name = scan.nextLine();

Date date = new Date() ;
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm") ;
dateFormat.format(date);
//System.out.println(dateFormat.format(date));

if(dateFormat.parse(dateFormat.format(date)).after(dateFormat.parse("6:00"))&& dateFormat.parse(dateFormat.format(date)).before(dateFormat.parse("11:59")))
{
System.out.println("\nOkay " + Name.name + ", hope you're having a good morning - lets play!!!");
}
else if(dateFormat.parse(dateFormat.format(date)).after(dateFormat.parse("11:59"))&& dateFormat.parse(dateFormat.format(date)).before(dateFormat.parse("17:00")))
{
System.out.println("\nOkay " + Name.name + ", hope you're having a good afternoon - lets play!!!");
}
else if(dateFormat.parse(dateFormat.format(date)).after(dateFormat.parse("17:00"))&& dateFormat.parse(dateFormat.format(date)).before(dateFormat.parse("18:59")))
{
System.out.println("\nOkay " + Name.name + ", hope you're having a good evening - lets play!!!");
}
else if(dateFormat.parse(dateFormat.format(date)).after(dateFormat.parse("18:59"))&& dateFormat.parse(dateFormat.format(date)).before(dateFormat.parse("23:59")))
{
System.out.println("\nOkay " + Name.name + ", hope you're having a good night so far - lets play!!!");
}
return populatedCells;


}

}


This is what I would like to accomplish as a next step for this code :

I need to update the 10by10 grid so that each populated cell, if populated will check to see if it has any neighbor cells which are also populated. Each cell can have up to 8 neighbor cells.

This is part of the handout...i just would like some hints if possible to check the update cells. I was told by one person in computer lab that to check neighbors you have to have some formula checking like this :

[a-1+1] [a+1+1] to check diagonally etc...

What your program should do:

This is part of the handout what I would like help on if possible (the flaw I think
with the below instructions is they dont write what happens if the cell has 2
neighbors, maybe I'm getting the <= / >= wrong but it seems cell has 2 neighbors
doesnt write what that means:

We follow Conway’s standard rules for updating the cells, as follows. A “neighbor” is a vertically, horizontally, or diagonally adjacent cell that is populated. A cell has anywhere from 0 to 8 neighbors.  For a cell that is “populated”, if the cell has <= 1 neighbors, or >= 4 neighbors, it dies (becomes 0). Otherwise, it survives (remains 1).  For a cell that is not populated, if the cell has exactly 3 neighbors, it becomes populated (becomes 1).  Cells on the edge always remain unpopulated (0).

Post has shared content
This is by far one of the easiest ways to acquire someone's Wi-Fi password. What do you think?

Post has attachment

Post has attachment

Post has attachment

Post has attachment

Post has attachment

Post has attachment
Wait while more posts are being loaded