Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

change the non preemptive scheduling processor to preemptive scheduling package covid.file; / * 2 1 4 0 7 6 7 8 4 - Keenan Husselmann

change the non preemptive scheduling processor to preemptive scheduling
package covid.file;
/*214076784- Keenan Husselmann
*/
import java.io.*;
import java.util.*;
//********************************************************************************************************************//
class Patient {
public String name;
public int age;
public String status;
// Constructor to initialize the patient object with name, age, and status
public Patient(String name, int age, String status){
this.name = name;
this.age = age;
this.status = status;
}
}
class CovidFile {
public String cityName;
public int arrivalTime;
List patients = new ArrayList<>();
// Constructor to initialize the CovidFile object with the city name and arrival time
public CovidFile(String cityName, int arrivalTime){
this.cityName = cityName;
this.arrivalTime = arrivalTime;
}
// Method to add a patient to this Covid file
public void addPatient(Patient patient){
patients.add(patient);
}
public double calculateAverageAge(){
/* Method to calculate the Average Age of patients in this file
int sum = patients.stream().mapToInt(p -> p.age).sum();
Here, patients is patient objects.
.stream() converts the collection into a stream.
Then mapToInt(p -> p.age) maps each patient object to its age, creating an IntStream of ages.
Finally, .sum() calculates the sum of all ages in the stream and assigns it to the variable sum
*/
int sum = patients.stream().mapToInt(p -> p.age).sum();
return (double) sum / patients.size();
}
//Method to find the minimum age among the patients
public int findMinimumAge(){
return patients.stream().mapToInt(p -> p.age).min().orElse(-1);
}
//Method to find the maximum age among the patients
public int findMaximumAge(){
return patients.stream().mapToInt(p -> p.age).max().orElse(-1);
}
//Method to count the number of patients per status category
public Map countPatientsByStatus(){
/*This line initializes a HashMap named statusCount where the keys are strings (representing statuses)
and the values are integers (representing counts).*/
Map statusCount = new HashMap<>();
for (Patient p : patients){
/*This line starts a loop that iterates over each Patient object in the patients collection
Inside the loop, this line merges the information of the patient's status into the statusCount map.
The merge method is used to combine the value (count) associated with a given status in the map*/
statusCount.merge(p.status, 1, Integer::sum);
}
return statusCount;
}
}
public class Scheduler {
public static void main(String[] args) throws IOException {
List files = new ArrayList<>();
readFiles(files);
Collections.sort(files, Comparator.comparingInt(f -> f.arrivalTime));
/*Sort files by arrival time for processing (First Come, First Served Scheduling)
The next line sorts the files list based on the arrivalTime property of CovidFile objects.
It uses the Collections.sort method along with an expression f ->,to specify the sorting criteria.
The expression f -> f.arrivalTime extracts the arrival time of each CovidFile object.*/
processFiles(files);
}
private static void readFiles(List files) throws IOException {
/*Simulated file paths and arrival times for each city
This method takes a List of CovidFile objects as input and reads data from CSV files into these objects.
It may throw an IOException if there's an issue with file reading
*/
String[] fileNames ={"src\\NewYork.csv","src\\London.csv","src\\Lagos.csv","src\\Johannesburg.csv","src\\Windhoek.csv","src\\Shanghai.csv","src\\Delhi.csv"};
int[] arrivalTimes ={0,20,25,30,35,50,55};
/*This section defines simulated file paths (fileNames) and arrival times (arrivalTimes) for each city.
Each file corresponds to a city's COVID-19 data, and arrivalTimes indicate when the data for each city arrives.
*/
for (int i =0; i < fileNames.length; i++){
/*The code iterates over each file in the fileNames array.
For each file, it creates a new CovidFile object, initializing it with the city name and arrival time.
It then creates a File object from the file path and initializes a BufferedReader to read the CSV file.
It reads each line of the CSV file, splits it by commas, and checks if it contains at least six elements.
If the line has enough data, it creates a Patient object with relevant data (name, age, and other information from the CSV) and adds it to the CovidFile object.

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

8. Set goals that relate to practice as well as competition.

Answered: 1 week ago

Question

6. Conclude with the same strength as in the introduction

Answered: 1 week ago

Question

7. Prepare an effective outline

Answered: 1 week ago