0% found this document useful (0 votes)
50 views5 pages

COMSATS University Islamabad, Wah Campus Electrical & Computer Engineering Department

This document contains a lab assignment submitted by Taha Yaseen for the subject OOP at COMSATS University Islamabad, Wah Campus. The assignment asks to create a calculator class with functions for sum, multiplication, division, subtraction, modulus, sine, cosine, and tangent. The main method prompts the user to select an operation and inputs values, calling the corresponding method from the Calculator class to perform the calculation and output the result. The Calculator class defines static methods to implement each mathematical operation on input variables.

Uploaded by

taha butt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views5 pages

COMSATS University Islamabad, Wah Campus Electrical & Computer Engineering Department

This document contains a lab assignment submitted by Taha Yaseen for the subject OOP at COMSATS University Islamabad, Wah Campus. The assignment asks to create a calculator class with functions for sum, multiplication, division, subtraction, modulus, sine, cosine, and tangent. The main method prompts the user to select an operation and inputs values, calling the corresponding method from the Calculator class to perform the calculation and output the result. The Calculator class defines static methods to implement each mathematical operation on input variables.

Uploaded by

taha butt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

COMSATS University Islamabad, Wah Campus

Electrical & Computer Engineering Department

Program: BEE Semester Section: 3A


Subject: OOP Instructor: Ma’am Samia Zafar

Lab Asssignment:01

Submitted by:
Name: Taha Yaseen Reg # FA20-BEE-018

Date of Submission:
13th-October-2021

Q1: Create a calculator class with sum , multiplication , division sin , cos ,tan as function.
Main:
public class Quiz2 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);

System.out.println("Enter\n 1 for Sum \n 2 for Multiplication \n 3 for Division \n 4 for


Subtraction \n 5 for Mod \n 6 for Sin \n 7 for Cos \n 8 for Tan");
int z= in.nextInt();
switch (z)
{case 1: // SUM
System.out.print("Enter first digit ");
double x= in.nextDouble();
System.out.print("Enter second digit ");
double y= in.nextDouble();
System.out.println(" Sum : "+Calculator.sum(x, y));
break;
case 2: //MULTIPLICATION
System.out.print("Enter first digit ");
x= in.nextDouble();
System.out.print("Enter second digit ");
y= in.nextDouble();
System.out.println("Prouct : "+Calculator.mul(x, y));
break;
case 3: //DIVISION
System.out.print("Enter first digit ");
x= in.nextDouble();
System.out.print("Enter second digit ");
y= in.nextDouble();
System.out.println( " = "+Calculator.div(x, y));
break;
case 4: //SUBTRACTION
System.out.print("Enter first digit ");
x= in.nextDouble();
System.out.print("Enter second digit ");
y= in.nextDouble();
System.out.println("Difference"+Calculator.diff(x, y));
break;
case 5: //MOD
System.out.print("Enter digit ");
x= in.nextDouble();
System.out.println("Mod : "+Calculator.mod(x));
break;
case 6: //SIN
System.out.print("Enter Degree ");
x= in.nextDouble();

System.out.println("Sin :"+Calculator.sin(x));
break;
case 7: //COS
System.out.print("Enter Degree ");
x= in.nextDouble();
System.out.println("Cos: "+Calculator.cos(x));
break;
case 8: //Tan
System.out.print("Enter Degree ");
x= in.nextDouble();
System.out.println("Tan :"+Calculator.tan(x));
break;
default :
System.out.println("Invalid");
}
}}

Class:
public class Calculator {
static double var1 ;
static double var2;
static double sum(double a , double b)
{
var1= a;
var2=b;
return a+b;
}
static double mul(double a , double b)
{
var1 = a;
var2 = b;
return a*b;
}
static double div(double a , double b)
{
var1 = a;
var2 = b;
return a/b;
}
static double diff(double a , double b)
{
var1 = a;
var2 = b;
return a-b;
}
static double mod(double a )
{
var1 = a;
if (a>=0)
return a;
else
return -a;
}
static double sin(double a )
{
var1 = a;
double p = Math.toRadians(a);
return Math.sin(p);
}
static double cos(double a )
{
var1 = a;
double p =Math.toRadians(a);

return Math.cos(p);
}
static double tan(double a )
{
var1 = a;
double p = Math.toRadians(a);
return Math.tan(p);
}

Result:

You might also like