Prog. 4
Define a class Employee_Sal described below:
Data members/instance variables:
String name : to store name of the employee
String empno : to store employee number
int basic
: to store basic salary of the employee
Member Methods:
i. A parameterised constructor to initialize the data members
ii. To accept the details of an employee
iii. To compute the gross and net salary as:
da =30%of basic
hra =15%of basic
pf =12%of basic
gross =basic + da + hra
net = gross - pf
iv. To display the name, empno, gross salary, net salary.
Write a main method to create an object of a class and call the above
member methods.
[ICSE Model]
Answers
/*Program to print details
of employee*/
import java.util.Scanner;
class Employee_Sal
{
Scanner sc=new Scanner (System.in);
String name;
String empno;
int basic;
Employee_Sal (String n, String en, int b)
{
name= n;
empno=en;
basic=b;
}
void Input()/*this is actually not required as the parameterised constructor is there, but ill write it anyway*/
{
System.out.println("Enter name,empno and basic salary");
name=sc.next();
empno=sc.next();
basic=sc.nextInt();
}
void Compute()
{
float da= (30/100.0)*basic;
float hra=(15/100.0)*basic;
float pf=(12/100.0)*basic;
double gross= basic+da+hra;
net = gross-pf;
}
void display()
{
System.out.println(name+"\n"+empno+'\n'+gross+"\n"+net);
}
}//class ends
very easy but lenghty question
its annoying tht u cant use tab...pls tell me if it is possible to use tab while writing an answer
pls like and mark as brainliest
/*Program to print details
of employee*/
import java.util.Scanner;
class Employee_Sal
{
Scanner sc=new Scanner (System.in);
String name;
String empno;
int basic;
Employee_Sal (String n, String en, int b)
{
name= n;
empno=en;
basic=b;
}
void Input()/*this is actually not required as the parameterised constructor is there, but ill write it anyway*/
{
System.out.println("Enter name,empno and basic salary");
name=sc.next();
empno=sc.next();
basic=sc.nextInt();
}
void Compute()
{
float da= (30/100.0)*basic;
float hra=(15/100.0)*basic;
float pf=(12/100.0)*basic;
double gross= basic+da+hra;
net = gross-pf;
}
void display()
{
System.out.println(name+"\n"+empno+'\n'+gross+"\n"+net);
}
}//class ends
very easy but lenghty question
its annoying tht u cant use tab...pls tell me if it is possible to use tab while writing an answer
pls like and mark as brainliest