Question

please help completing this short assignment that needs to be done in linux, in java code...

please help completing this short assignment that needs to be done in linux,

in java code create a program The program must do the conversion without using any of the built-in functions from the Java library. Thank you in advance.

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

to do the following:

In your Ubuntu, linux, using terminal mode ONLY, do the following:

- Create a folder named pgm2

- In this folder place the text file located at: http://users.cis.fiu.edu/~mrobi002/databases/RAMerrors4

***some of the lines in the file have spaces at the biggining, read the lines overcoming that trick instructed by the professor*****

Do not modify the file putting it adjacent to the left.

******* MAKE SURE NOT TO CHANGE THE FILE NAME *******

Each record in this file represents the location of an error found in RAM

Assume your computer has 4 gigs of RAM, each gig in a different memory chip, therefore you have 4 one gig RAM chips. A gigabyte contains 1,073,741,824 or 1024^3 or 2^30 bytes, which is also equivalent to 1,048,576 kilobytes or 1,024 megabytes.

These are the addresses in each RAM chip in a computer with 4 (gigs) of RAM:

------ decimal adresses ----------

RAM chip 0 contain addresses: 0 - 1,073,741,823 bytes

RAM chip 1 contain addresses: 1,073,741,824 - 2,147,483,647 bytes

RAM chip 2 contain addresses: 2,147,483,648 - 3,221,225,471 bytes

RAM chip 3 contain addresses: 3,221,225,472 - 4,294,967,295 bytes

- In the same folder (pgm2), use an editor in terminal mode, create a Java program to do the following:

- Open the text file

- Read each record in the file

- Convert the record to binary

- Convert the binary result to decimal

- Find in which RAM chip is the decimal error found

- Print the RAM memory chip where the error is located for each record as follows: example:

hex number = binary number = decimal number located at x RAM chip

*** CREATE YOUR OWN METHODS THAT WILL CONVERT HEX TO BINARY AND BINARY TO DECIMAL

*** DO NOT USE JAVA'S AUTOMATIC CONVERSION METHODS, IT HAS TO BE DONE DOING MATH ONLY *****

0 0
Add a comment Improve this question Transcribed image text
Answer #1

You can create a directory in UNIX using mkdir command.

$mkdir pgm2

Now, for JAVA program (WITHOUT ANY AUTOMATIC CONVERSION FUNCTION).

1. checkRAMChip(): This method checks if the converted decimal number will be in chip 0 or chip 1 or chip 2 or chip 3.

2. binToDecimal(): This method takes a binary number (in string form) as an input and returns its decimal equivalent.

3. getHexEquivalent(): This method returns the hexadecimal value (in the form of string) of the given single binary digit (in the form of a single char).

4. hexToBinary(): This method converts the hexadecimal value to binary.

5. removeSpaces(): This method removes the leading and trailing space from the string and returns the new string with only data value.

6. startCalculation(): This method invokes all the other methods to perform the final calculation.

JAVA SOURCE CODE (RAMERROR.java):

import java.util.*;
import java.io.*;

class RAMERROR{

// check if the input falls into the chip 0/1/2/3.
int checkRAMChip(double deci){
    int chip=-1;

    if(deci>=0 && deci<=1073741823.0)
      chip=0; // chip 0
    else
      if(deci>=1073741824.0 && deci<=2147483647.0)
        chip=1; // chip 1
      else
        if(deci>=2147483648.0 && deci<=3221225471.0)
          chip=2; // chip 2
        else
          if(deci>=3221225472.0 && deci<=4294967295.0)
            chip=3; // chip 3
        
    return chip;
}

// convert binary to decimal value
double binToDecimal(String bin){
    double d=0;

    for(int i=0; i<bin.length();i++){
      if(bin.charAt(i)=='1'){
        // calculate if digit is 1
        d=d+Math.pow(2,bin.length()-1-i);
      }
    }
    return d;
}

// get the hexadecimal equivalent of input character
String getHexEquivalent(char c){
    String h="";
    switch(c){
      case '0':
        h="0000"; break;
      case '1':
        h="0001"; break;
      case '2':
        h="0010"; break;
      case '3':
        h="0011"; break;
      case '4':
        h="0100"; break;
      case '5':
        h="0101"; break;
      case '6':
        h="0110"; break;
      case '7':
        h="0111"; break;
      case '8':
        h="1000"; break;
      case '9':
        h="1001"; break;
      case 'A':
      case 'a':
        h="1010"; break;
      case 'B':
      case 'b':
        h="1011"; break;
      case 'C':
      case 'c':
        h="1100"; break;
      case 'D':
      case 'd':
        h="1101"; break;
      case 'E':
      case 'e':
        h="1110"; break;
      case 'F':
      case 'f':
        h="1111"; break;
      default:
        assert(false);
        h="";
    }
    return h;
}

// hexadecimal to binary
String hexToBinary(String hex){
    String bin="";

    for(int i=0; i<hex.length(); i++){
      bin+=getHexEquivalent(hex.charAt(i));
    }
  
    return bin;
}

// start calculating the values and print the desired output
void startCalculation(String hex){
    String bin;
    int chip;

    bin=hexToBinary(hex); // convert hex to bin
    double deci = binToDecimal(bin); // convert bin to decimal
    chip=checkRAMChip(deci); // check which RAM it belongs to
    if(chip!=-1){  
      System.out.printf("%s = %s = %.0f located at %d RAM chip\n",hex,bin,deci,chip);
      System.out.println("-----------------------");
    }
    else{
      System.out.printf("%s = %s = %.0f not located at any RAM chip (out of memory)\n",hex,bin,deci);
      System.out.println("-----------------------");
    }
}

// remove the spaces (leading + trailing) in the input string.
String removeSpaces(String str){
    String s="";
    char c=' ';

    for(int i=0; i<str.length();i++){
      c=str.charAt(i);
      if(c!=' '){ // create new string if char is not space
        s+=c;
      }
    }
    return s;
}

public static void main(String args[]){
    // create an object of Triangle
    RAMERROR rerror = new RAMERROR();

    try{
      // File reading using FileReader
      File file = new File("RAMerrors4");
      FileReader fileReader = new FileReader(file);
      BufferedReader bufferedReader = new BufferedReader(fileReader);
      //StringBuffer stringBuffer = new StringBuffer();
      String line;
      String value="";

      // process each line
      while ((line = bufferedReader.readLine()) != null) {
        value=rerror.removeSpaces(line);
        rerror.startCalculation(value);
      }

      fileReader.close();
   }catch (IOException e) {
      e.printStackTrace();
   }
}
}

OUTPUT:

080000000 = 000010000000000000000000000000000000 = 2147483648 located at 2 RAM chip
-----------------------
0F2D05DFF = 000011110010110100000101110111111111 = 4073741823 located at 3 RAM chip
-----------------------
4DE743E0 = 01001101111001110100001111100000 = 1307001824 located at 1 RAM chip
-----------------------
FFfDFF5DF = 111111111111110111111111010111011111 = 68717376991 not located at any RAM chip (out of memory)
-----------------------
0046535FF = 000000000100011001010011010111111111 = 73741823 located at 0 RAM chip

Add a comment
Know the answer?
Add Answer to:
please help completing this short assignment that needs to be done in linux, in java code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • need help with this assignment, please. Part 1 - Java program named MemoryCalculator In your Ubuntu...

    need help with this assignment, please. Part 1 - Java program named MemoryCalculator 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.) It is down below. Ths is the file RAMErrors 3CDAEFFAD ABCDEFABC 7A0EDF301 1A00D0000 Each record in this file represents the location of an error...

  • Java code. Need help with either 1. or 2. Nothing too complicated and the code needs...

    Java code. Need help with either 1. or 2. Nothing too complicated and the code needs at least one loop and 3 switch statements! Artificial Intelligence elements in programming. Creating stories with user input. For this assignment, you can do one of two things 1. Create a chat box that allows a conversation to go on as long as the user wants . Welcome the user when they start. . look for key words or other things that could guide...

  • This assignment shpuld be code in java. Thanks Overview In this assignment you will write a...

    This assignment shpuld be code in java. Thanks Overview In this assignment you will write a program that will model a pet store. The program will have a Pet class to model individual pets and the Assignment5 class will contain the main and act as the pet store. Users will be able to view the pets, make them age a year at a time, add a new pet, and adopt any of the pets. Note: From this point on, your...

  • write programs with detailed instructions on how to execute. code is java What you need to...

    write programs with detailed instructions on how to execute. code is java What you need to turn in: You will need to include an electronic copy of your report (standalone) and source code (zipped) of your programs. All programming files (source code) must be put in a zipped folder named "labl-name," where "name" is your last name. Submit the zipped folder on the assignment page in Canvas; submit the report separately (not inside the zipped folder) as a Microsoft Word...

  • This needs to be done in Java using Using Multiple Generic Data Structures – LinkedList and Array...

    this needs to be done in Java using Using Multiple Generic Data Structures – LinkedList and ArrayList In this assignment, you will write a system to manage email address lists (ostensibly so that you could send emails to a list which has a name – which would send an email to each of the addresses in the list – although we will not actually implement sending emails.  Displaying the list will simulate being able to send the emails). We will...

  • Java Thank you!! In this assignment you will be developing an image manipulation program. The remaining...

    Java Thank you!! In this assignment you will be developing an image manipulation program. The remaining laboratory assignments will build on this one, allowing you to improve your initial submission based on feedback from your instructor. The program itself will be capable of reading and writing multiple image formats including jpg, png, tiff, and a custom format: msoe files. The program will also be able to apply simple transformations to the image like: Converting the image to grayscale . Producing...

  • *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J...

    *** FOR A BEGINNER LEVEL JAVA CLASS, PLEASE KEEP CODE SIMPLE, AND WE USE BLUE J IN CLASS (IF IT DOESNT MATTER PLEASE COMMENT TELLING WHICH PROGRAM YOU USED TO WRITE THE CODE, PREFERRED IS BLUE J!!)*** ArrayList of Objects and Input File Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info...

  • i need help with this scripting assignment in power shell thanks Lab 7: PowerShell Search and...

    i need help with this scripting assignment in power shell thanks Lab 7: PowerShell Search and Report Search Report host path date Execution time nnn Directories n, nnn, nnn Files nnnnnnn Sym links nnnnnnn Old files nnnnnnn Large files nnnn, nnn Graphics files nnnnnnn Executable files nnnnnnn Temporary files n, nnn, nnn TotalFileSize nnnn, nnn Introduction Lab 7 is nearly identical to Lab 2, except it is written in PowerShell, uses no UNIX/Linux tools to do its work, creates no...

  • Please help me code the following in: JAVA Please create the code in as basic way...

    Please help me code the following in: JAVA Please create the code in as basic way as possible, so I can understand it better :) Full points will be awarded, thanks in advance! Program Description Write a program that demonstrates the skills we've learned throughout this quarter. This type of project offers only a few guidelines, allowing you to invest as much time and polish as you want, as long as you meet the program requirements described below. You can...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT