Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class CircularlyLinkedList { private static class Node { private E element; private Node next; public Node(E e, Node n) { element = e; next

image text in transcribedimage text in transcribedimage text in transcribed

public class CircularlyLinkedList {

private static class Node {

private E element;

private Node next;

public Node(E e, Node n) {

element = e;

next = n;

}

public E getElement() {

return element;

}

public Node getNext() {

return next;

}

public void setNext(Node n) {

next = n;

}

}

private Node tail;

private int size;

public CircularlyLinkedList() {

tail = null;

size = 0;

}

public int length() {

return size;

}

public boolean isEmpty() {

return size == 0;

}

public E getFirst() {

if (isEmpty()) {

return null;

}

return tail.getNext().getElement();

}

public E getLast() {

if (isEmpty()) {

return null;

}

return tail.getElement();

}

public void rotate() {

if (!isEmpty()) {

tail = tail.getNext();

}

}

public void addFirst(E e) {

if (isEmpty()) {

tail = new Node(e, null);

tail.setNext(tail);

} else {

Node newest = new Node(e, tail.getNext());

tail.setNext(newest);

}

size++;

}

public void addLast(E e) {

addFirst(e);

rotate();

}

public E removeFirst() {

if (isEmpty()) {

return null;

}

Node head = tail.getNext();

if (length() == 1) {

tail = null;

} else {

tail.setNext(head.getNext());

}

size--;

return head.getElement();

}

public String toString() {

String result = length() + ":[";

if (!isEmpty()) {

Node p = tail.getNext();

for (int count = 0; count

result += p.getElement();

if (count

result += ", ";

}

}

}

result += "]";

return result;

}

}

public class Process {

private String name;

private int duration;

public Process(String n, int d) {

name = n;

duration = d > 0 ? d : 0;

}

public int execute(int slice) {

duration -= slice;

if (duration

duration = 0;

}

return duration;

}

public String toString() {

return "{" + name + ": " + duration + "}";

}

}

import java.util.ArrayList; //importing the java arraylist to use an array list

import java.util.Scanner;

//This is my main class

public class waitProcess {

//Create 3 objects to hold the numbers for process, start time, and duration

private String name;

private int startTime;

private int duration;

//Create a constructor to be able to use the variables name, duration, and startime.

public waitProcess(int s, String n, int d) {

this.name = n;

this.duration = d;

this.startTime = s;

}

}

import java.util.Scanner;

import java.util.ArrayList;

public class RoundRobinSimulation {

private final static int NUM_PROCESSES_INIT = 10;

private final static int MAX_PROCESS_DURATION = 250;

private final static int TIME_SLICE = 10;

private final static double ADD_PROCESS_THRESHOLD = 0.03;

private final static boolean VERBOSE_MODE = true;

/*

public Time_ProcessNumber {

// compare simulation time compared to process number, So when times up then we need to take out 4 from the waiting list. Then at Time 12 we compare P2 to SinglyLinkedList

//String check = input.next("AT")??

//Consum**DD" .next("P1");

int processNum = 1;

int simulationTime = 0;

int time = key.next();

if(time = simulationTime){

//time.equals(.getFirst() *= 34);

}

}

*/

public static void main(String[] args) {

CircularlyLinkedList processList = new CircularlyLinkedList();

int processNum = 1;

int simulationTime = 0;

int sliceCount = 0;

int count = 0;

//Take care of user input from the terminal and putting it inside a variable to cut that variable apart and place inside array list

ArrayList cry = new ArrayList;

//Use substring to remove AT and ADD and index of and lastindex of

String subString(int 0);

Scanner key = new Scanner(System.in);

String input = key.nextLine();

//If __ is

//cry here

while (!input.equals("DONE")) {

//waitingList.addFirst(E time = key.nextline());

//Make multiple scanner inputs for At, time, add, process, duration

String At = key.next();

int time = key.nextInt();

String Add = key.next();

String process = key.next();

int Duration = key.nextInt();

waitingList.addFirst(sliceCount, );

//These will have to be added into a for loop

count++;

waitProcess.addFirst();

//These will have to be added into a for loop

count++;

input = key.nextLine();

}

System.out.println("done");

}

}

/*When reading times, when certain amount of time passes */

//for (int i = 0; i

// processList.addLast(new Process("P" + processNum++, (int) (/*time?? */ * MAX_PROCESS_DURATION) + 1));

// }

// while (!processList.isEmpty()) {

// if (VERBOSE_MODE) System.out.printf("@%05d %s ", simulationTime, processList);

// Process p = processList.getFirst();

// int time = p.execute(TIME_SLICE);

// if (time == 0) {

// processList.removeFirst();

// } else {

// processList.rotate();

// }

// if (Math.random()

// if (VERBOSE_MODE) System.out.println(" *** Added new Process P" + processNum + " *** ");

// processList.addLast(new Process("P" + processNum++, (int) (/*time?? */ * MAX_PROCESS_DURATION) + 1));

// }

// simulationTime += TIME_SLICE;

// sliceCount++;

// }

// System.out.printf(" Simulation ended at %05d. %d Processes were completed in %d time slices. ", simulationTime, processNum-1, sliceCount);

// }

//}

/* for (int i = 0; i

processList.addLast(new Process("P" + processNum++, (int) (Math.random() * MAX_PROCESS_DURATION) + 1));

}

while (!processList.isEmpty()) {

if (VERBOSE_MODE) System.out.printf("@%05d %s ", simulationTime, processList);

Process p = processList.getFirst();

int time = p.execute(TIME_SLICE);

if (time == 0) {

processList.removeFirst();

} else {

processList.rotate();

}

if (Math.random()

if (VERBOSE_MODE) System.out.println(" *** Added new Process P" + processNum + " *** ");

processList.addLast(new Process("P" + processNum++, (int) (Math.random() * MAX_PROCESS_DURATION) + 1));

}

simulationTime += TIME_SLICE;

sliceCount++;

}

System.out.printf(" Simulation ended at %05d. %d Processes were completed in %d time slices. ", simulationTime, processNum-1, sliceCount);

*/

//}

//}

2. Round-Robin Simulation 2.1. Problem Description We reviewed a Round-Robin strategy for effectively sharing processes on a single CPU. In the starting code, the number of initial processes was fixed and additional processes were added randomly. You are to enhance this program to read a series of instructions for the introduction of processes at specific launch times. The instruction format follows: AT

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago

Question

2. Describe how technology can impact intercultural interaction.

Answered: 1 week ago