Question

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 found in RAM. (Hint: One of them is not on one of the chips.)
 
     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.java
     - 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 
 
 
 Part 2 - Linux Shell Scripting. 
   - NOT using editors, create a sh file named: program2.sh
- Set the permissions for this this *.sh file using this command to make it executable: chmod 755 *.sh
- program2.sh should append your name and the current date and time to a NEW file called results.txt
-program2.sh should then do the following:
How:
- Ask the user to enter a number.
- Verify that the number is between 1 and 50, inclusive.
- If the number is not between 1 and 50, then keep asking the user to enter a number until it is
valid.
- Use a loop from 1 to the value entered by the user
- Sum the results of all the included numbers, but do not include any output yet.
- After the loop ends, display the sum and
append it to the results.txt file on a new line as follows Sum of numbers is xxx
 
 
Zip your files into one file named FirstnameLastnameA2.zip submit them in the Assignment 2 dropbox.
 
Only include the folowing files: - MemoryCalculator.java
- program2.sh Zip your files into one file named FirstnameLastnameA2.zip submit them in the Assignment 2 dropbox. 
   Only include the folowing files:
   - MemoryCalculator.java
   - program2.sh
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Problem 1: MemoryCalculator.java

RAMErrors

Execution :

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Problem 2 : program2.sh

Execution ::

RAW CODE :::

______________________________________ MemoryCalculator.java ______________________________________

import java.io.*;
class MemoryCalculator {
   static String hex2bin(String hex) {
       String bin = "";
       for(int i=0; i<hex.length(); i++){
           char chr = hex.charAt(i);
           switch(chr){
               case '0' : bin += "0000";break;
               case '1' : bin += "0001";break;
               case '2' : bin += "0010";break;
               case '3' : bin += "0011";break;
               case '4' : bin += "0100";break;
               case '5' : bin += "0101";break;
               case '6' : bin += "0110";break;
               case '7' : bin += "0111";break;
               case '8' : bin += "1000";break;
               case '9' : bin += "1001";break;
               case 'A' : bin += "1010";break;
               case 'B' : bin += "1011";break;
               case 'C' : bin += "1100";break;
               case 'D' : bin += "1101";break;
               case 'E' : bin += "1110";break;
               case 'F' : bin += "1111";break;
           }
       }
       return bin;
   }
   static long bin2decimal(String bin){
       int len,i,j;
       long value = 0,powvalue; // for long integers
       len = bin.length();
       for(i=0; i<len; i++){
           if (bin.charAt(i) == '1'){ // If 1 is there in bit
               powvalue = 1; // For pow(2,(len-i-1))
               for(j=0;j<(len-i-1);j++) powvalue *= 2;
               value = value + powvalue; // Then add that correspond power of 2 to value
               // System.out.println(powvalue);
           }
       }
       return value;
   }
   public static void main(String args[]){
       long value; String hex;
       try{
           FileInputStream fstream = new FileInputStream("RAMErrors");
           DataInputStream in = new DataInputStream(fstream);
           BufferedReader br = new BufferedReader(new InputStreamReader(in));
           String strLine;
           //Read File Line By Line
           while ((strLine = br.readLine()) != null) {
               hex = hex2bin(strLine); // Coverting the line to hex
               value= bin2decimal(hex); // Hex to decimal
               // Then Cheking that decimal with conditions of bits
               if( value <= 8589934584L) System.out.println("RAM chip 1");
               else if ( value <= 17179869184L ) System.out.println("RAM chip 2");
               else if ( value <= 25769803768L ) System.out.println("RAM chip 3");
               else if ( value <= 34359738368L ) System.out.println("RAM chip 4");
               else System.out.println("RAM chip : out of value"); // Out of conditions
           }
           in.close();
       }catch (Exception e){//Catch exception if any
           System.err.println("Error: " + e.getMessage());
       }
   }
}

##################################################################################################

____________________________________________ RAMErrors ___________________________________________

3CDAEFFAD
ABCDEFABC
7A0EDF301
1A00D0000

#################################################################################################

__________________________________________ program2.sh ___________________________________________

#!/bin/bash

read -p 'Enter a number: ' N
Sum=0
if [ $N -ge 1 ]
then
   if [ $N -le 50 ]
   then
       for i in $(seq 1 $N) # for loop from 1 to N
           do # Then Adding those value to Sum
               Sum=$[$Sum+$i]
           done # Writing the Sum to result.txt
       echo "Sum of numbers is $Sum" > results.txt
   else
       echo "The number must be <= 50"
   fi
else
   echo "The number must be >= 1"
fi

###################################################################################################

Add a comment
Know the answer?
Add Answer to:
need help with this assignment, please. Part 1 - Java program named MemoryCalculator In your Ubuntu...
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
  • 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...

  • CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods...

    CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods Create a folder called Unit03 and put all your source files in this folder. Write a program named Unit03Prog1.java. This program will contain a main() method and a method called printChars() that has the following header: public static void printChars(char c1, char c2) The printChars() method will print out on the console all the characters between c1 and c2 inclusive. It will print 10...

  • The objectives of this assignment are to: Further enhance your knowledge and skill in Java. Gain...

    The objectives of this assignment are to: Further enhance your knowledge and skill in Java. Gain an understanding and experience with stacks. Gain further experience using generics. Continue to practice good programming techniques. Create a stack class named MyStack that stores generics with the methods shown below. Write a test program that thoroughly tests your stack implementation. void push(E item) push item onto top of stack E peek() return item on top of stack E pop() return item on top...

  • Your mission in this programming assignment is to create a Python program that will take an...

    Your mission in this programming assignment is to create a Python program that will take an input file, determine if the contents of the file contain email addresses and/or phone numbers, create an output file with any found email addresses and phone numbers, and then create an archive with the output file as its contents.   Tasks Your program is to accomplish the following: ‐ Welcome the user to the program ‐ Prompt for and get an input filename, a .txt...

  • Need help on following Java GUI problem: Write a program that lets a user display and...

    Need help on following Java GUI problem: Write a program that lets a user display and modify pictures. Create a window. Add four buttons so that clicking a particular button will shift the image by a small amount in the north, south, east or west direction inside the window. Add a menu bar with two menus: File and Image. The File menu should contain an Open menu item that the user can select to display JPEG and PNG files from...

  • in java instructions Assignment 2 Complete Exercise E9.3 (checking account problem). What to turn in: A...

    in java instructions Assignment 2 Complete Exercise E9.3 (checking account problem). What to turn in: A zip file containing ONLY 3 java source code.files (BankAccount.java, BudgetCheckingAccount.java, and CheckingAccount.java). NO FOLDERS may be included in your zip file, or l will simply reject it. You are not giving me the AccountDemo.java file, because I have my own copy, and you are not permitted to modify it. Also, the package statement must be correct, as explained later in the assignment description. You...

  • Could you help me do the commands from nmber 16 to 21 For this assignment, you...

    Could you help me do the commands from nmber 16 to 21 For this assignment, you will: Unpack a tar archive. Change the unpacked files. Repack the files into a new tar archive. Turn in your new tar archive. Details Do not use an editor unless it specifically states to edit the file. By "editor" I mean vim, gedit, pico, etc. Despite its name, we don't consider sed to be an editor in this assignment, so you may use it...

  • I need help with my assignment. It is a java program. Please make it as simple...

    I need help with my assignment. It is a java program. Please make it as simple as you can. Create an ArrayList with elements the objects of previous class. Using a simple loop populate the ArrayList with data from some arrays with data, or from console. Use a loop with iterator and write the information in a File using PrintWriter. Use this address for the file (c:\\result\\MyData.txt). Use the Scanner class to display the content of the file on console.

  • CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1....

    CPT 180 Chapter 2 Assignment 3 Directions Using the following guidelines, create a python program. 1. Create a program named printRandomNumbers that gets input from the user and then produces a list of random numbers. 2. Import the random module 3. Add three comment lines at the top of the program that contain: a. Program Name b. Program Description c. Programmer's Name (You) 4. Prompt the user for the following: a. Number of random numbers required b. Lower limit of...

  • 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...

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