Question: fix the code import java.util.InputMismatchException; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Direct { String[] strAr1 = new String[99]; int printIndex; int storeIndex; public

fix the code import java.util.InputMismatchException; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner;

public class Direct {

String[] strAr1 = new String[99]; int printIndex; int storeIndex;

public void processing() { printIndex = 0; storeIndex = 0;

// while (true) { // System.out.println("0. Exit"); System.out.println("1. Read reference string"); System.out.println("2. Generate reference string"); System.out.println("3. Display current reference string"); System.out.println("4. Simulate FIFO"); System.out.println("Choose an option"); Scanner scannerid = new Scanner(System.in); try { int userid = scannerid.nextInt(); // System.out.println(userid); System.out.println(""); if ((userid 4)){ System.err.println("Invalid option "); processing(); }else { switch (userid) { / case 0: break; case 1: { condis1(); break; } case 2: { condis2(); break; } case 3: { condis3(); break; } case 4: { condis4(); break; }

case5:{

condis5()

break;{

case6:{

condis6()

break;{

case7:{

condis7()

break;{ } } } catch (InputMismatchException ex) { System.err.println("Input input. Please enter numeric value from 0-4."); processing(); } }

public void condis1() { Scanner scannerid1 = new Scanner(System.in); System.out.println("Reading in reference String"); String str = scannerid1.nextLine(); if (str == "") { System.out.println("Can not be an empty string"); condis1(); } else { strAr1[storeIndex] = str; storeIndex++; } processing(); // }

public void condis2() { Scanner scannerid1 = new Scanner(System.in); System.out.println("Generate reference string"); System.out.println("What is the size of the string?"); int n = scannerid1.nextInt(); String AlphaNumericString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "abcdefghijklmnopqrstuvxyz";

// create StringBuffer size of AlphaNumericString StringBuilder sb = new StringBuilder(n); for (int i = 0; i

// add Character one by one in end of sb sb.append(AlphaNumericString.charAt(index)); } strAr1[storeIndex] = sb.toString(); storeIndex++; processing(); // }

public void condis3() { // Scanner scannerid1 = new Scanner(System.in); System.out.println("Display current reference string"); if (strAr1[printIndex] == null) { System.out.println("There are no strings to display!"); } else { System.out.println(strAr1[printIndex]); printIndex++; } processing(); // }

public void condis4() { //FIFO -- first in, first out. Scanner scannerid1 = new Scanner(System.in); System.out.println("Simulate FIFO"); String str = scannerid1.nextLine(); if (str == null) { //Tutor: check if the string is empty System.out.println("Can not be an empty string"); condis4(); } else { //Tutor: convert the string array to queue (or FIFO algorithm). char[] refStr = str.toCharArray(); Queue fifo = new LinkedList(); for (int i = 0; i

public void condis5() { //OPT Scanner scannerid1 = new Scanner(System.in); System.out.println("Simulate OPT"); String str = scannerid1.nextLine(); if (str == null) { //Tutor: check if the string is empty System.out.println("Can not be an empty string"); condis5(); } else } System.out.println("Head of the queue = " + OPT.peek()); //call peek() to view head of queue. System.out.println("Element of the queue = " + OPT); System.out.println("Size of the queue = " + OPT()); } System.out.println(""); processing(); // Tutor: force program to display the menu option }

public void condis6() { //LRU Scanner scannerid1 = new Scanner(System.in); System.out.println("Simulate LRU"); String str = scannerid1.nextLine(); if (str == null) { //Tutor: check if the string is empty System.out.println("Can not be an empty string"); condis6(); } else } System.out.println("Head of the queue = " + LRU.peek()); //call peek() to view head of queue. System.out.println("Element of the queue = " + LRU); System.out.println("Size of the queue = " + LRU()); } System.out.println(""); processing(); // }

public void condis7() { //LFU Scanner scannerid1 = new Scanner(System.in); System.out.println("Simulate LFU"); String str = scannerid1.nextLine(); if (str == null) { //Tutor: check if the string is empty System.out.println("Can not be an empty string"); condis7(); } else } System.out.println("Head of the queue = " + LFU.peek()); //call peek() to view head of queue. System.out.println("Element of the queue = " + LFU); System.out.println("Size of the queue = " + LFU ()); } System.out.println(""); processing(); // Tutor }

public static void main(String[] args) { Direct myideas = new Direct(); myideas.processing(); }

}

answer all que

fix the code import java.util.InputMismatchException; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner;public class
A computer system provides a compare-and-swap (CAS) operation which is used in the following manner: seen = CAS (address, old, new) It loads the contents of address, compares the value against old and if it matches stores the value new at the same address. All of this is performed atomically and the value read from the address is returned as seen. (a) What does it mean for a processor instruction to be atomic? [2 marks] (b) Write pseudocode for a simple spin lock using CAS. [4 marks] Consider a singly-linked list of QNode objects, each with a Boolean field value and a reference next to its successor (holding null at the tail of the queue). A shared location 1 refers to the tail node (or is null if the queue is empty). (c) Define the following concurrent operations using CAS: // Append a new node q to the tail of the list, returning // the previous tail Node pushTail (QNode q) ; // Remove q, the current head of the list, returning // the new head Node popHead (QNode q) ; (8 marks]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!