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

program # 2 pgm2_5dCGS3767OS This assignment is worth 6 points total, partial cr

ID: 3587664 • Letter: P

Question

program # 2 pgm2_5dCGS3767OS This assignment is worth 6 points total, partial credit will be given, 1 - Worth 6 points In your Ubuntu VM (virtual machine), using terminal mode ONLY, do the following: Create a folder named pgm2 In this folder (pgm2) place the text file located at: http://users.cis.fiu.edu/~mrobi002/databases/RAMerrors Each record in this file represents the location of an error found in RAM Assume you have a computer with 4 gigs of RAM, each gig in a different memory chip, therefore you have 4 one gig RAM chips. ---------decimal address ----------- HINT: RAM chip 0 contain addresses: 0 - 8,589,934,584 bits RAM chip 1 contain addresses: 8,589,934,585 - 17,179,869,184 bits RAM chip 2 contain addresses: 17,179,869,185 - 25,769,803,768 bits RAM chip 3 contain addresses: 25,769,803,769 - 34,359,738,368 bits In the same folder (pgm2), in terminal mode, using an editor, create a Java program named: your lastName, First letter of your first name, _OS, pgm2, java example: robinsonM_OSpgm2.java This program will do the following: - Open the text file - Read each record, which is the location of an error in RAM, in hex - Convert that hex value to binary - Convert the binary value to decimal value - Print the RAM chip number where the error is located for each record note: Location addresses for RAM chips are decimal *** DO NOT CHANGE THE FILE NAME *** MAKE SURE THE FILE IS IN THE SAME FOLDER AS YOUR JAVA PROGRAM *** CREATE YOUR OWN METHODS THAT WILL CONVERT HEX TO BINARY AND BINARY TO DECIMAL *** DO NOT USE JAVA'S AUTOMATIC CONVERSION METHODS *** DO NOT USE JAVA'S PARSE COMMANDS *** USE System.out.printf commands ONLY to print any data

Explanation / Answer

import java.util.Scanner;

import java.io.File;

import java.io.IOException;

import java.math.BigInteger;

public class robinsonM_OSpgm2

{

public static String decoutput="";

public static void hexTobinary(String s)

{

String digits = "0123456789ABCDEF";

String binaryNum="";

String binnum[] = {"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};

System.out.print("Binary Value : ");

for (int i = 0; i < s.length(); i++)

{

char c = s.charAt(i);

int d = digits.indexOf(c);

System.out.print(binnum[d] +" ");

decoutput=decoutput.concat(binnum[d]);

}

System.out.print(" ");

}

public static void BinaryToDecimal(String binaryNumber)

{

long p=0;

int d;

int len= binaryNumber.length();

for(int i=0;i<len;i++)

{

char c=binaryNumber.charAt(i);

d=Character.getNumericValue(c);

p= (p * 2) + d;

}

System.out.println("Decimal value : " + p);

RamChip(p);

}

  

public static void RamChip(long Adress)

{   

if(Adress >= 0 && Adress <= 8589934584L)

{System.out.println("Error found in RAM chip 0 ");}

else if(Adress >= 8589934585L && Adress <= 17179869184L)

System.out.println("Error found in RAM chip 1 ");

else if(Adress >= 17179869185L && Adress <= 25769803768L)

System.out.println("Error found in RAM chip 2 ");

else if(Adress >= 25769803769L && Adress <= 34359738368L)

System.out.println("Error found in RAM chip 3 ");

else

System.out.println("No error Found");

}

public static void main(String args[])

{

String fileName = "pgm2.txt";

String hexvalue;

try (Scanner scanner = new Scanner(new File(fileName))) {

while (scanner.hasNext()){

hexvalue=scanner.nextLine();

System.out.println(" Hex Value : " + hexvalue);

hexTobinary(hexvalue.trim());

BinaryToDecimal(decoutput);

decoutput="";

}

} catch (IOException e) {

e.printStackTrace();

}

  

  

  

  

}

}