Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views3 pages

Assignment 2

The document contains a Java class named 'Teacher' that manages salary calculations for teachers. It includes methods for accepting input, calculating deductions and total salary, and displaying the results. Key attributes include name, basic salary, allowances, deductions, and final income.

Uploaded by

ishanrsjain10
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)
3 views3 pages

Assignment 2

The document contains a Java class named 'Teacher' that manages salary calculations for teachers. It includes methods for accepting input, calculating deductions and total salary, and displaying the results. Key attributes include name, basic salary, allowances, deductions, and final income.

Uploaded by

ishanrsjain10
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/ 3

import java.util.

*;
class Teacher
{
String n;
double basic=1;
double DA,HRA,IT,PF,deduct,totsal,income;
Teacher()
{
n="";
}
Teacher(String s,double b)
{
n=s;
basic=b;
}
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter basic");
basic=sc.nextDouble();
System.out.println("Enter name");
n=sc.next();
}
void display()
{
System.out.println("Name:"+n);
System.out.println("Basic"+basic);
System.out.println("DA="+DA);
System.out.println("HRA="+HRA);
System.out.println("IT="+IT);
System.out.println("PF="+PF);
System.out.println("income="+income);
System.out.println("deduct="+deduct);
System.out.println("total salary="+totsal);
}
void calc()
{
DA=0.15*basic;
HRA=0.13*basic;
income=basic+DA+HRA;
IT=0.08*basic;
PF=0.12*basic;
deduct=IT+PF;
totsal=income-deduct;
}
void main()
{
Teacher obj=new Teacher();
obj.accept();
obj.calc();
obj.display();
Teacher s2 = new Teacher();
s2.accept();
s2.calc();
s2.display();
}
}
Variable Data type Purpose
n String To store name
basic double To store basic salary
DA double To store DA
HRA double To store HRA
IT double To store IT
PF double To store provident
funds
income double To store income
deduct double To calc and store
deduct
totsal double To store final income

You might also like