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 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
