import java.util.Random; /** * Write a description of class Memory here. * * @author (your name) * @version (a version number or a date) */ public class Memory { public static int[][] memory; public static int Row; public static int Col; public static int[] tag; Random Gen = new Random(); public Memory() { Row = 128; Col = 8; memory = new int[Row][Col]; tag = new int[32]; // Total Mem space = 1024 } public void addDataToNearestEmptySpace(int value) { //int rowspace = 0; // int colspace = 0; for (int i = 0; i < Row; i++) { for (int j = 0; j < Col; j++) { if ( i == 0 ) { if ( j == 0 ) { memory[i][j] = value; } } } } } public void addRandomDataToMemory(Object obj) { Memory memoryobj = (Memory)obj; //int rowspace = 0; // int colspace = 0; for (int i = 0; i < Memory.Row; i++) { for (int j = 0; j < Memory.Col; j++) { Memory.memory[i][j] = Gen.nextInt(); } } } public void addDataToSpecificLocation(int RowNumber, int ColumnNumber, int value) { memory[RowNumber][ColumnNumber] = value; } public int totalRows() { return Row; } public int totalColumns() { return Col; } public int getData(int selectRow, int selectColumn) { return memory[selectRow][selectColumn]; } public void deleteData(int selectRow, int selectColumn) { memory[selectRow][selectColumn] = 0; } public String toString() { int slotno = 0; System.out.println("Memory contents:"); for (int i = 0; i < Row; i++) { for (int j = 0; j < Col; j++) { System.out.println("Memory slot number " + slotno + " - (Row:" + i + " | Column" + j +") - content is: " + memory[i][j] ); slotno++; } } System.out.println("---------------------"); return "Finished"; } }