ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 2 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 27 Apr 2017 My Price 9.00

Part 1 - Java program named MemoryCalculator

Assignment 2


 Part 1 - Java program named MemoryCalculator - Worth 5 points
     In your Ubuntu VM (virtual machine), using terminal mode ONLY, do the following:
     
     Create the folder program2
     
     In this folder place the text file located on my faculty website in Module 2 called RAMerrors (Do not rename this file, it has no extension.)
     
     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---------------   
     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
           
           
     HINT: RAM chip 0 contain addresses:             0 -  1,073,741,823 bytes
           RAM chip 1 contain addresses: 1,073,741,824 -  2,147,483,648 bytes 
           RAM chip 2 contain addresses: 2,147,483,647 -  3,221,225,471 bytes 
           RAM chip 3 contain addresses: 3,221,225,472 -  4,294,967,296 bytes 

                                
     In the same folder, in terminal mode using an editor, create a Java program 
     to do the following:
     - Call the Java program - MemoryCalculator
     - Open the RAMerrors text file  
     - Read each record
     - Print the RAM memory chip where the error is located for each record
 
     *** CREATE YOUR OWN METHODS THAT WILL CONVERT 
           HEX TO BINARY AND BINARY TO DECIMAL

     *** DO NOT USE JAVA'S AUTOMATIC CONVERSION METHODS 

 

MemoryCalculator (1).java

/*********************************************************************
Author : Christopher Kepple
Course : COP 3767 - Operating Systems
Professor : Caryl Rahn
Program # : MemoryCalculator
{The intent of this program is to buid a program that will change
hexidicimals to Binary and Binary back to Decimal, allowing the user to see what
memory address are used for a RAM chip with 4 GHz, }
Due Date : 03/12/2017 Certification:
I hereby certify that this work is my own and none of it is the work of any
other person.
..........{ Christopher Kepple }..........
*********************************************************************/ import java.util.*;
import java.io.*;
public class MemoryCalculator{ public static long hex2dec(String s)
{
//
System.out.println("\t\thex2dec method");
//
System.out.println("\t\tString Input: "+s);
String digits = "0123456789ABCDEF";
s = s.toUpperCase();
long val = 0;
for (int i = 0; i<s.length(); i++)
{
char c = s.charAt(i);
int d = digits.indexOf(c);
System.out.println("\t\td: "+d);
val = 16*val + d;
System.out.println("\t\tVal: "+val);
} //
// } return val; public static String dec2bin(long dec)
{
//System.out.println("\t\tdec2bin method");
long decnum =dec;
//System.out.println("\t\tDecNum: "+decnum);
String binD="";
String thisD="";
while (decnum > 0)
{
thisD=""+decnum%2;
binD =thisD +binD;
decnum = decnum/2;
}
return binD.replaceAll("^[0]","");
} // public static void main(String args) throws Exception
{
System.out.println("Main method"); FileInputStream fstream = new FileInputStream("RAMerrors4.txt");
BufferedReader br = new BufferedReader(new
InputStreamReader(fstream));
long maxRam=(int)Math.pow(1024,3);
System.out.println("maxRam: "+maxRam);
//long ramRange = {0,maxRam, maxRam*2, maxRam*3, (maxRam*4)-1};
long ramRange = new long[5];
for(int i=0;i<ramRange.length;i++)
{
ramRange[i]=maxRam*i;
}
for(int i=0;i<ramRange.length;i++)
{
System.out.println(ramRange[i]);
}
String strLine="";
while ((strLine =br.readLine()) != null)
{
//System.out.println("main while");
strLine =strLine.trim();
//System.out.println("\t"+strLine);
long decimal = (long)hex2dec(strLine);
String bin = dec2bin(decimal);
boolean notfound = true;
//System.out.println("\t\tDecimal: "+decimal);
for(int i =0; i<ramRange.length-1;i++)
{
if((decimal>=ramRange[i]) && (decimal<ramRange[i+1]))
{
System.out.println("Binary: "+bin);
System.out.printf("%s = %d =%s = decimal number
located at RAM chip %d\n", strLine, decimal, bin, i);
notfound = false;
break;
}
}
if(notfound )
System.out.printf("%s = %d = %s = decimal number not
located in Ram chip\n", strLine, decimal, bin);
}
br.close();
}
}

 

Attachments:

Answers

(11)
Status NEW Posted 27 Apr 2017 05:04 AM My Price 9.00

-----------

Not Rated(0)