You are on page 1of 5

LAB REPORT # 13

SUBMITTED TO:

OBJECT ENGR. SIDRA SHAFI

SUBMITTED BY:
ORIENTED ALEEZA ZAMAN

REG NO:
PROGRAMMING
21-SE-31

LAB

DATE: 13-12-2022
Task:
Write a program named MathThreads.java that perform 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
threads class:
package lab13;
import java.lang.Math;
public class threads extends Thread{
public double a;
public static double z;
threads(double a)
{
this.a=Math.toRadians(a);
}
public void run()
{

z=Math.sin(a);
}
}
thread1 Class:
package lab13;
import java.lang.Math;
public class thread1 extends Thread{
public double a;
public static double p;
thread1(double a)
{
this.a=Math.toRadians(a);
}
public void run()
{

p=Math.cos(a);
}
}

thread2 Class:
package lab13;
import java.lang.Math;
public class thread2 extends Thread{
public double a;
public static double q;
thread2(double a)
{
this.a=Math.toRadians(a);
}
public void run()
{

q=Math.tan(a);
}
}
ThreadMain Class:
package lab13;
import java.util.Scanner;
public class MainThread {

public static void main(String[] args) {


double result;
Scanner sc=new Scanner (System.in);
System.out.println("Enter the angles one on each
line:");
double a=sc.nextDouble();
double b=sc.nextDouble();
double c=sc.nextDouble();
threads t=new threads(a);
thread1 t1=new thread1(b);
thread2 t2=new thread2(c);
t.start();
try
{
t.join();
}
catch(InterruptedException e)
{

}
t1.start();
try
{
t1.join();
}
catch(InterruptedException e)
{

}
t2.start();
try
{
t2.join();
}
catch(InterruptedException e)
{

}
result=threads.z+thread1.p+thread2.q;
System.out.println("The Result = "+result);
sc.close();
}

}
OUTPUT:

THE END

You might also like