Thursday, July 17, 2014

Parity Bit Java

/////////////////////////////////////////////////////////////////////////
// YOUR NAME HERE                                          //
//                                                                              //
//                                                                              //
//takes random 2d array and determines a parity bit//
//                                                               //
//////////////////////////////////////////////////////////////////////////
package lab;

import java.util.Random;

public class LabFirst1
{
public static void main(String[] args)
{
//setting up array
final int rowWidth = 8;
final int colHeight = 4;
   int total = 0;


   Random rand = new Random();

int [][] board = new int [colHeight][rowWidth];

  for (int row = 0; row < board.length; row++)
  {
for (int col = 0; col < board[row].length; col++)
{
board[row][col] = rand.nextInt(2);
}

//setting up array and Parity bit
}
System.out.println( "Data     \t Parity bit");
for(int i = 0; i < board.length; i++)
{
for(int j = 0; j < board[i].length; j++)
{
System.out.print( board[i][j] + " " );
}
//setting up Parity Bit
{
total +=  board[i][colHeight];
// didn't remember the method you used in class
if (total == 1)
   total = 1;
else if (total == 3)
   total = 1;
else if (total == 5)
   total = 1;
else if (total == 8)
   total = 1;
else if (total == 6)
   total = 0;
else if (total == 2)
   total = 0;
else if (total == 4)
   total = 0;
else if (total == 6)
   total = 0;
else if (total == 7)
   total = 0;
}
System.out.print(" ");
System.out.println(total);
}

}
  }



No comments:

Post a Comment