Question

Modify the virtual translator program: virtual.java Modify it so it loops ten times asking the user...

Modify the virtual translator program: virtual.java

Modify it so it loops ten times asking the user for the ten virtual address from the work sheet we did the week before spring break.

Once you have it working run it in a script command capturing the output. Make sure the script file has a .txt extension and upload the output.

//Java Program

import java.util.Scanner;

public class virtual{

   public static void main(String[] args){

   int[] virtualAddressPace={2,1,6,0,4,3,-1,-1,-1,5,-1,7,-1,-1,-1,-1};

   Scanner input = new Scanner(System.in);
   System.out.print("Enter a virtual address: ");
   int vAdd = input.nextInt();

   System.out.println("Address as Hex " + Integer.toHexString(vAdd));
   System.out.println("Address as Binary " + Integer.toBinaryString(vAdd));

   int maskUpper = 0xFFFFF000;
   int maskLower = 0xFFFF0FFF;

   int highBits = vAdd & maskUpper;
   int lowBits = vAdd & maskLower;


   System.out.println("High Bits " + Integer.toHexString(highBits));
   System.out.println("Low Bits " + Integer.toHexString(lowBits));

   highBits = highBits >> 12;

   System.out.println("High Bits shifted: " + Integer.toHexString(highBits));

  
   int pIndex = virtualAddressPace[highBits];

   if (pIndex >= 0){

       pIndex = pIndex << 12;
       int physicalMemory = pIndex + lowBits;
       System.out.println("The physcial address is: " + physicalMemory);
   }
   else{
       System.out.println("Page Fault");
   }

   }
}

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

just add a do while loop

import java.util.Scanner;

public class virtual{

   public static void main(String[] args){

   int[] virtualAddressPace={2,1,6,0,4,3,-1,-1,-1,5,-1,7,-1,-1,-1,-1};

int count = 0;

   do{

   Scanner input = new Scanner(System.in);
   System.out.print("Enter a virtual address: ");
   int vAdd = input.nextInt();

   System.out.println("Address as Hex " + Integer.toHexString(vAdd));
   System.out.println("Address as Binary " + Integer.toBinaryString(vAdd));

   int maskUpper = 0xFFFFF000;
   int maskLower = 0xFFFF0FFF;

   int highBits = vAdd & maskUpper;
   int lowBits = vAdd & maskLower;


   System.out.println("High Bits " + Integer.toHexString(highBits));
   System.out.println("Low Bits " + Integer.toHexString(lowBits));

   highBits = highBits >> 12;

   System.out.println("High Bits shifted: " + Integer.toHexString(highBits));

  
   int pIndex = virtualAddressPace[highBits];

   if (pIndex >= 0){

       pIndex = pIndex << 12;
       int physicalMemory = pIndex + lowBits;
       System.out.println("The physcial address is: " + physicalMemory);
   }
   else{
       System.out.println("Page Fault");
   }

   }

}while(count<10);
}

For running a txt file containing java code use bean shell.

Add a comment
Know the answer?
Add Answer to:
Modify the virtual translator program: virtual.java Modify it so it loops ten times asking the user...
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 put both of this loops into one program. Set it up so that there is...

    Please put both of this loops into one program. Set it up so that there is one main function and both loops are within it. Thank You. import java.util.Scanner; public class WhileDavidMungomaLab12 { public static void main(String[] args) { int aScore = -1; while (aScore < 0 || aScore > 100) { Scanner sc = new Scanner(System.in); System.out.println("Please enter a valid number that is within the specified range(0 and 100): "); aScore = sc.nextInt(); } } } AND import java.util.Scanner;...

  • Modify the program below so it also calculates and displays the amount of money Package A...

    Modify the program below so it also calculates and displays the amount of money Package A customers would save if they purchased Package B or C, and the amount of money Package B customers would save if they purchased Package C. If there would be no savings, no message should be printed. import java.util.*; public class Lab2 { public static void main (String[] args) {    //scanner Scanner input = new Scanner(System.in);    //declarations int hours; char pack; double totalCharges...

  • in Java This program will output a right triangle based on user specified height triangleHeight and...

    in Java This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a character. Modify the given program to output a right triangle that instead uses the user-specified trianglechar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as % or* Each subsequent line will...

  • Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util...

    Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util.*; import java.lang.*; /** * * @author STEP */ public class ShiftCipher { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); String plainText; System.out.print("Please enter your string: "); // get message plainText = input.nextLine(); System.out.print("Please enter your shift cipher key: "); // get s int s = input.nextInt(); int...

  • I am creating a program where a user will enter in a price amount. And then...

    I am creating a program where a user will enter in a price amount. And then the program will determine how many 20, 10, 5, 1, etc.. they get back. I keep getting "error: unexpected type" in my findValue method. Not too sure why I am getting this. There also might be more bugs in there that I am not aware of because it wont compile. Any help is appreciated. Here is my code: import java.util.Scanner; public class prac1 {...

  • Modify the program that you wrote for the last exercise in a file named Baseball9.java that...

    Modify the program that you wrote for the last exercise in a file named Baseball9.java that uses the Player class stored within an array. The program should read data from the file baseball.txt for input. The Player class should once again be stored in a file named Player.java, however Baseball9.java is the only file that you need to modify for this assignment. Once all of the input data from the file is stored in the array, code and invoke a...

  • This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The...

    This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow base height, arrow base width, and arrow head width. (1) Modify the given program to use a loop to output an arrow base of height arrowBaseHeight. (1 pt) (2) Modify the given program to use a loop to output an arrow base of width arrowBaseWidth. Use a nested loop in which the inner loop draws the...

  • I need help with a java error Question: Consider a graphics system that has classes for...

    I need help with a java error Question: Consider a graphics system that has classes for various figures—say, rectangles, boxes, triangles, circles, and so on. For example, a rectangle might have data members’ height, width, and center point, while a box and circle might have only a center point and an edge length or radius, respectively. In a well-designed system, these would be derived from a common class, Figure. You are to implement such a system. The class Figure is...

  • I need help with a java error Question: Consider a graphics system that has classes for...

    I need help with a java error Question: Consider a graphics system that has classes for various figures—say, rectangles, boxes, triangles, circles, and so on. For example, a rectangle might have data members’ height, width, and center point, while a box and circle might have only a center point and an edge length or radius, respectively. In a well-designed system, these would be derived from a common class, Figure. You are to implement such a system. The class Figure is...

  • Modify the program so that it uses a loops repeatedly doing: • prompt for input (using...

    Modify the program so that it uses a loops repeatedly doing: • prompt for input (using line seqNum and the prompt phrase: "Enter a line") • reads the line of input • stores the line of input in the next position of an array of Line or an ArrayList of Line. Once the user enters STOP as input, the loop should terminate and another loop should print each line in reverse order. For example (the input you should type in...

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