0% found this document useful (0 votes)
7 views

Class Notes Oop

Computer oops class10
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Class Notes Oop

Computer oops class10
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

*;
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()
{

Scanner sc=new Scanner(System.in);


System.out.println("Enter the length of first side");
side1=sc.nextDouble();
System.out.println("Enter the length of second side");
side2=sc.nextDouble();
System.out.println("Enter the length of third side");
side3=sc.nextDouble();
//boolean b=isvalidTriangle();
// if(b==true)
if(isValidTriangle()) //if(isValidTriangle()==true)
{
System.out.println("Area ="+findArea());
}

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.

EXAMPLE PROGRAM 5:(HOME WORK)


Define a class Student with the following member variables and member methods.
member variables – name, rno, maths, phy and che to store the name, roll number, marks
in maths, physics and chemistry respectively. (use appropriate data types )
member methods
- a method to assign values of all the member variables
- A method to return the percentage of mark. (Assume that subject marks are out of 100)
- A method to display the stream
- A main method in which assign values to the member variables and display name,
percentage of mark and whether selected or not. If selected, then display the stream.
Stream is assigned based on the following criteria.

Percentage of marks Stream

90 to 100 Science with computers

80 to 89 Science without computers

70 to 79 Commerce with Maths

60 to 69 Commerce without Maths

Less than 60 Not selected

You might also like