Skip to content

Commit cff499d

Browse files
committed
vit honors with threads
1 parent 1836114 commit cff499d

File tree

6 files changed

+100
-30
lines changed

6 files changed

+100
-30
lines changed

FAT-Practice/.idea/workspace.xml

Lines changed: 44 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Binary file not shown.

FAT-Practice/src/VITHonors.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import java.util.Vector;
2+
3+
class Attendance{
4+
static int winners = 0;
5+
static Vector<Integer> arr = new Vector<>();
6+
7+
static synchronized void counting(int n){
8+
System.out.println(Thread.currentThread().getName() + " is counting");
9+
for(int i = n-1000; i < n; i++){
10+
if(arr.get(i) == 100)
11+
winners++;
12+
}
13+
}
14+
}
15+
16+
class count extends Thread{
17+
int n;
18+
19+
count(int n){
20+
this.n = n;
21+
}
22+
public void run(){
23+
Attendance.counting(n);
24+
}
25+
}
26+
27+
public class VITHonors {
28+
public static void main(String[] args) {
29+
30+
int max = 100;
31+
int min = 75;
32+
33+
for(int i = 0; i < 2000; i++){
34+
int n = (int)(Math.random() * ((max - min) + 1) + min);
35+
Attendance.arr.add(n);
36+
}
37+
38+
Thread t1 = new count(1000);
39+
Thread t2 = new count(2000);
40+
t1.start();
41+
t2.start();
42+
43+
try{
44+
t1.join();
45+
t2.join();
46+
}catch(InterruptedException e){
47+
System.out.println(e);
48+
}
49+
50+
System.out.println(Attendance.arr);
51+
System.out.println("Winners are = " + Attendance.winners);
52+
53+
}
54+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ previous numbers, i.e., `T(n)=T(n-1)+T(n-2)+T(n-3), T(1)=T(2)=1, and T(3)=2`). [
211211
* Define a package ‘Package1’ with the class ‘NumberManipulation’ which contains an integer array (size 9) as its instance variable and two methods `extractDigits( )` and `findLastDigit( )`. The `extractDigits( )` method must take an integer number as argument and extract the individual digits of the number and store them in the 9-element integer array. The method `findLastDigit( )` should find out the 10th digit using the above formula and return it. [NumberManipulation.java](https://github.com/jacobjohn2016/Java-Programming/blob/master/FAT-Practice/src/Package1/NumberManipulation.java)
212212
* Define a main class outside of the package created above and read the 9-digit number as a String. Throw a user defined exception "InvalidInputException" if the length of the input String is not exactly 9 digits and prompt the user to enter the input again. If valid, convert the input into integer and pass it to the method `extractDigits( )` and also invoke `findLastDigit( )` method which would return the last digit. If the last digit is 10, append ‘X’ to the original string else append the digit itself’ and display the ISBN number. [ISBN.java](https://github.com/jacobjohn2016/Java-Programming/blob/master/FAT-Practice/src/ISBN.java)
213213
214+
19. VIT honors its employees with 100% attendance in an academic year with a certificate of appreciation. Assume there are 2000 employees. Create an array to store their attendance percentage. The array can be populated with random numbers. Create two threads so that thread1 determines the total count of employees eligible for certificate in the first half of the array and thread2 in second half of the array. The main( ) has to wait till both the threads complete their task and arrive at a final count indicating the total number of employees eligible for the certificate of appreciation.
215+
214216
## Contributions
215217
* Initial Author - [jacobjohn2016](github.com/jacobjohn2016)
216218
* [varunreddy24](github.com/varunreddy24)

0 commit comments

Comments
 (0)