Question

CSC1465L: Operating Systems Lab Consider the threads hierarchy below: T2 T1 T3 T1 will ask the user to enter an array of size

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have implemented the three java files required to implement the required task. Please find the Code screenshot, Output, and Code.

ANY CLARIFCATIONS REQUIRED LEAVE A COMMENT

1.CODE SCREENSHOT:

1 MaxOfPassed.java X MaxOfFailed.java X Task Thread Demojava X Şclass MaxofPassed implements Runnable { 2 //To Store the Arra

MaxOfFailed.java X Task ThreadDemojava class MaxofFailed implements Runnable { 2 private int arr[]; //to store the array 3 pu

1 Task Thread Demo java X import java.util.*; 2 Epublic class TaskThreadDemo { 3 public static void main(String[] args) throw

2.OUTPUT:

CS. C:\Windows\System32\cmd.exe D:\javasrc\ThreadMinMax>javac MaxOfPassed.java D:\javasrc\ThreadMinMax>javac MaxOfFailed.java

3.CODE:

MaxOfPassed.java

class MaxOfPassed implements Runnable {
   //To Store the Array
   private int arr[];
   public MaxOfPassed(int []a) {
       arr=a;
   }

   @Override
  
   public void run() {
       int max=0;
       //find the max element in the array
       for (int i = 0; i < arr.length; i++) {
           if(max<arr[i])
               max=arr[i];
       }
       if(max>=60)
           System.out.println("The Maximum Grade of Passed Students is :"+max);
       else
           System.out.println("Sorry No Student has Passed");
   }
}

MaxOfFailed.java

class MaxOfFailed implements Runnable {
   private int arr[]; //to store the array
   public MaxOfFailed(int []a) {
       arr=a;
   }
   @Override
   public void run() {
       int max=0;
       find the max element in the array who have falied
       for (int i = 0; i < arr.length; i++) {
           if(max<arr[i]&&arr[i]<60)
               max=arr[i];
       }
       System.out.println("The Maximum Grade of Failed Students is :"+max);
      
   }
}

TaskThreadDemo.java

import java.util.*;
public class TaskThreadDemo{
   public static void main(String[] args)throws Exception{
       Scanner sc=new Scanner(System.in);
       //read the value of n
       System.out.print("Enter the value for 'n' : ");
       int n=sc.nextInt();
       int arr[]=new int[n];
       //read the array
       System.out.print("Enter "+n+" Integers for Grades");
       for(int i=0;i<n;i++){
           arr[i]=sc.nextInt();
       }
      
       //1.Code to Create threads associated with the given tasks
       Runnable m1=new MaxOfPassed(arr);
       Runnable m2=new MaxOfFailed(arr);
       //2.Code that will initiate the threads and cause the begining of execution.
       Thread t1=new Thread(m1);
       Thread t2=new Thread(m2);
       //start the threads
       t1.start();
       //t1.join();
       t2.start();
       //t2.join();
   }
}
Add a comment
Know the answer?
Add Answer to:
CSC1465L: Operating Systems Lab Consider the threads hierarchy below: T2 T1 T3 T1 will ask the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CSC1465L: Operating Systems Lab Consider the threads hierarchy below: T2 T1 T3 T1 will ask the...

    CSC1465L: Operating Systems Lab Consider the threads hierarchy below: T2 T1 T3 T1 will ask the user to enter an array of size N and will fill the array with student grades. T1 will then send the array to threads T2 and T3. T2 will compute the maximum grade of passed students. T3 will compute the maximum grade of failed students. T1 will print the maximum and minimum grades returned by threads T2 and 13. Note: A student passes an...

  • THE SOLUTION MUST BE SUBMITTED AS 3 JAVA FILES Consider the threads hierarchy below: T2 T1...

    THE SOLUTION MUST BE SUBMITTED AS 3 JAVA FILES Consider the threads hierarchy below: T2 T1 T3 T1 will ask the user to enter an array of size N and will fill the array with student grades. T1 will then send the array to threads T2 and T3. T2 will compute the maximum grade of passed students. T3 will compute the maximum grade of failed students. T1 will print the maximum and minimum grades returned by threads T2 and T3....

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • Need code written for a java eclipse program that will follow the skeleton code. Exams and...

    Need code written for a java eclipse program that will follow the skeleton code. Exams and assignments are weighted You will design a Java grade calculator for this assignment. A user should be able to calculate her/his letter grade in COMS/MIS 207 by inputting their scores obtained on worksheets, assignments and exams into the program. A skeleton code named GradeCompute.java containing the main method and stubs for a few other methods, is provided to you. You must not modify/make changes...

  • Principles of Computer Science

    Question First, you need to design, code in Java, test and document a base class, Student. The Student class will have the following information, and all of these should be defined as Private: A. Title of the student (eg Mr, Miss, Ms, Mrs etc) B. A first name (given name) C. A last name (family name/surname) D. Student number (ID) – an integer number (of type long) E. A date of birth (in day/month/year format – three ints) - (Do NOT use the Date class from...

  • CS 2050 – Programming Project # 1 Due Date: Session 3 (that is, in one week!)....

    CS 2050 – Programming Project # 1 Due Date: Session 3 (that is, in one week!). Can be resubmitted up to two times until Session 6 if your first version is submitted by session 3. In this project, you create two classes for tracking students. One class is the Student class that holds student data; the other is the GradeItem class that holds data about grades that students earned in various courses. Note: the next three projects build on this...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT