OOP Lab 13 Tasks PDF
OOP Lab 13 Tasks PDF
}
Output:
Task 2:
Write a program named MathThreads.java that perform
concurrent mathematical operations like finding Sin, Cos and Tan
of an angle using multiple threads. Although the master thread can
continue its execution, in this case, it needs to make sure that all
operations are completed before combining individual results. z=
sin(45)+cos(60)+tan(30)
Code:
package aqibprectice;
import java.lang.Math;
class MathSin extends Thread
{
public double deg;
public double res;
public MathSin(int degree)
{ deg = degree;
}
public void run()
{
System.out.println("Executing sin of "+deg);
double Deg2Rad = Math.toRadians(deg);
res = Math.sin(Deg2Rad);
System.out.println("Exit from MathSin.Res = "+res);
}
}
class MathCos extends Thread
{
public double deg;
public double res;