Class Notes Oop
Class Notes Oop
*;
class Triangle
{
double side1;
double side2;
double side3;
//function to assign values
void setValues(double s1,double s2,double s3)
{
side1=s1;
side2=s2;
side3=s3;
}
//function to check validity of triangle
boolean isValidTriangle()
{
return (side1+side2>side3 && side2+side3>side1 &&
side3+side1>side2);
/* if( side1+side2>side3 && side2+side3>side1 &&
side3+side1>side2)
{
return true;
}
else
{
return false;
}
*/
}
//function to return area
double findArea()
{
double s=(side1+side2+side3)/2;
return Math.sqrt(s*(s-side1)*(s-side2)*(s-side3));
}
//mainfunction
void main()
{
else
{
System.out.println("Invalid input");
}
}
}
EXAMPLE PROGRAM 4:(HOME WORK)
Define a class Employee with the following member variables and
member functions member variables
String name-to store the name of the
employee
int empCode-to store employee code
int basic-to store basic salary
member functions
i)void setValues(String n, int ec, int b)-to assign value to the member variables
ii)double findGS( )-function to return gross salary
gross salary = basic + D.A. + H.R.A.
D.A. = 40% of basic
H.R.A. = 30% of basic
iii)double findTotalDeductions( )-function to calculate total deductions
P.F. deduction = 12% basic
Income tax deduction =if gross salary <=25,000
then 5% of gross salary
else 10 % of gross salary
total deductions = P.F. deduction + Income taxdeduction
iv)void display( )-function to display name, empCode and net salary in a
tabular form. net salary = gross salary – total deductions.