Answered step by step
Verified Expert Solution
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;
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 PatientString 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 CovidFileString cityName, int arrivalTime
this.cityName cityName;
this.arrivalTime arrivalTime;
Method to add a patient to this Covid file
public void addPatientPatient patient
patients.addpatient;
public double calculateAverageAge
Method to calculate the Average Age of patients in this file
int sum patients.streammapToIntp pagesum;
Here, patients is patient objects.
stream converts the collection into a stream.
Then mapToIntp page 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.streammapToIntp pagesum;
return double sum patients.size;
Method to find the minimum age among the patients
public int findMinimumAge
return patients.streammapToIntp pageminorElse;
Method to find the maximum age among the patients
public int findMaximumAge
return patients.streammapToIntp pagemaxorElse;
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.mergepstatus, Integer::sum;
return statusCount;
public class Scheduler
public static void mainString args throws IOException
List files new ArrayList;
readFilesfiles;
Collections.sortfiles Comparator.comparingIntf farrivalTime;
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 farrivalTime extracts the arrival time of each CovidFile object.
processFilesfiles;
private static void readFilesList 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 srcNewYorkcsvsrcLondoncsvsrcLagoscsvsrcJohannesburgcsvsrcWindhoekcsvsrcShanghaicsvsrcDelhicsv;
int arrivalTimes ;
This section defines simulated file paths fileNames and arrival times arrivalTimes for each city.
Each file corresponds to a city's COVID data, and arrivalTimes indicate when the data for each city arrives.
for int i ; 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started