THE SOLUTION MUST BE SUBMITTED AS 3 JAVA FILES
//Main.java
package t1;
import java.util.Scanner; //for taking inputs
import java.util.concurrent.ExecutorService; //for making thread
pools
import java.util.concurrent.Executors;
import java.util.concurrent.Future; //to call the threads
public class Main {
public static void main(String args[]) throws Exception {
Scanner s = new Scanner(System.in);
int n;
int[] array = new int[100];
System.out.print("\nEnter the number of grades:
");
n = s.nextInt(); //taking input for number of
grades
System.out.print("\nEnter the grades: ");
for(int i = 0; i<n ; i++) { //taking input for
grades
array[i] = s.nextInt();
}
ExecutorService service =
Executors.newFixedThreadPool(1); //creating a pool of threads
Future<Integer> m = service.submit(new
MainThread(array, n)); //calling t1 thread calls constructor then
call method
service.shutdown(); //shutting down Executor
Service
}
}
//MainThread.java
package t1;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class MainThread implements Callable<Integer>{
int[] array;
int n;
public MainThread(int[] array,int n) {
this.array= array; //we set the array in
constructor
this.n = n; //set the number of grades
}
public void print() { //print function to see contents of
array
System.out.println("\nIn MainThread");
for(int i = 0; i<n ; i++) {
System.out.print("\t"+array[i]);
}
}
@Override
public Integer call() throws Exception{
ExecutorService service =
Executors.newFixedThreadPool(2); //creating a pool of 2
threads
Future<Integer> max_pass = service.submit(new
t2Thread(array, n)); //sending to t2 thread
Future<Integer> max_fail = service.submit(new
t3Thread(array, n)); //sending to t3 thread
System.out.print("\n\nMax grade of Passed students:
"+max_pass.get()); //value is received from t2.call()
function
System.out.print("\nMax grade of Failed students:
"+max_fail.get()); //value is received from t3.call()
function
service.shutdown();
return 0;
}
}
//t2Thread.java
package t1;
import java.util.concurrent.Callable;
public class t2Thread implements Callable<Integer>{
int[] array = new int[100];
int n;
t2Thread(int[] array,int n) { //constructor to assign
values to array and n
this.array = array;
this.n = n;
}
public void print() { //print function to see the
contents of the array
System.out.println("\nIn t2");
for(int i = 0; i<n ; i++) {
System.out.print("\t"+array[i]);
}
}
@Override
public Integer call() throws Exception {
int max_pass = -1;
//print();
for(int i = 0; i< n; i++) {
//finding out the max grade of passed student
if(max_pass <
array[i] && array[i] >= 60) {
max_pass = array[i];
}
}
return max_pass; //returning the
value
}
}
//t3Thread.java
package t1;
import java.util.concurrent.Callable;
public class t3Thread implements Callable<Integer>{
int[] array = new int[100];
int n;
t3Thread(int[] array,int n) {//constructor to assign
values to array and n
this.array = array;
this.n = n;
}
public void print() { //print function to see the
contents of the array
System.out.println("\nIn t3");
for(int i = 0; i<n ; i++) {
System.out.print("\t"+array[i]);
}
}
@Override
public Integer call() throws Exception {
int max_fail = -1;
//print();
for(int i = 0; i< n; i++) {
//finding out the max grade of failed student
if(max_fail <
array[i] && array[i] < 60) {
max_fail = array[i];
}
}
return max_fail;
}
}
Main.java
MainThread.java
t2Thread.java
t3Thread.java
OUTPUT
THE SOLUTION MUST BE SUBMITTED AS 3 JAVA FILES Consider the threads hierarchy below: T2 T1...
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...
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...
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...
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...
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...