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

import java.util.Scanner;

//T1 to ask elements of the array and display result
class T1 extends Thread {
   int arr[], n;
   Scanner in = new Scanner(System.in);

   public void run() {
       System.out.println("Enter length of the array : ");
       n = in.nextInt();
       arr = new int[n];
       System.out.println("Enter elements of the array : ");
       for (int i = 0; i < arr.length; i++) {
           arr[i] = in.nextInt();
       }
       T2 thread2 = new T2(arr);
       T3 thread3 = new T3(arr);
       thread2.start();
       thread3.start();
       while (thread2.isAlive()) {
           ;
       }
       System.out.println("Maximum Grade of passed student : " + thread2.max);
       while (thread3.isAlive()) {
           ;
       }
       System.out.println("Maximum Grade of failed student : " + thread3.max);
   }
}

//Thread 2 to get max grade of passed student
class T2 extends Thread {
   int max;
   int arr[];

   T2(int arr[]) {
       this.arr = new int[arr.length];
       for (int i = 0; i < arr.length; i++) {
           this.arr[i] = arr[i];
       }
   }

   public void run() {
       int temp[] = new int[arr.length];
       int count = 0;
       for (int i = 0; i < arr.length; i++) {
           if (arr[i] >= 60) {
               temp[count] = arr[i];
               count++;
           }
       }
       max = temp[0];
       for (int i = 0; i < count; i++) {
           if (max < temp[i]) {
               max = temp[i];
           }
       }
   }
}

//thread 3 to get maximum grade of failed student
class T3 extends Thread {
   int max;
   int arr[];

   T3(int arr[]) {
       this.arr = new int[arr.length];
       for (int i = 0; i < arr.length; i++) {
           this.arr[i] = arr[i];
       }
   }

   public void run() {
       int temp[] = new int[arr.length];
       int count = 0;
       for (int i = 0; i < arr.length; i++) {
           if (arr[i] < 60) {
               temp[count] = arr[i];
               count++;
           }
       }
       max = temp[0];
       for (int i = 0; i < count; i++) {
           if (max < temp[i]) {
               max = temp[i];
           }
       }
   }
}

//test class
public class test {
   public static void main(String[] args) {
       T1 thread = new T1();
       thread.start();
   }
}


//Output

Problems @ Javadoc Console x Debug Diagrams <terminated> test (5) [Java Application] C:\Program Files\Java\jre 1.8.0_261\bin\

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....

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • Java Gradebook

    Requirements:1.     The number of students to enter will be dynamic, minimum of 5.2.     Ask the user for a student's:a.     first nameb.     last namec.      student IDd.     4 exam grades (each out of 100 points)Calculate the student's:e.     final letter grade.3.     For each student, if the user enters invalid data he will be allowed to enter it again.4.     Letter grade calculation will use the standard grading scale.a.     90% - 100% = Ab.     80% - 89% = Bc.      70% - 79% = Cd.     60% - 69% = De.     Below 60% = F5.     The output will consist of:a.     A list of...

  • 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...

  • 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...

  • 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...

  • 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...

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