Define the class teacher with the following specifications:
Private members:
Name. 20 characters
Subject. 10 characters
Basic, DA,HRA. Flot
Salary. Float
Calculate( ) function computes the salary and return it. Salary is sum of basic ,DA and HRA.
Public members:
Read data ( ) function accept the data values and invokes the calculate function.
Displaydata ( ) functions print the data on the screen.
Answers
Answered by
2
Explanation:
import java.util.Scanner;
class teacher
{
Scanner sc = new Scanner(System.in);
String name, subject;
float basic, da, hra, salary;
void readdata()
{
System.out.print("Enter your Name : ");
name = sc.nextLine();
System.out.print("Enter your Subject : ");
subject = sc.nextLine();
System.out.print("Enter your Basic : ");
basic = sc.nextFloat();
System.out.print("Enter DA : ");
da = sc.nextFloat();
System.out.print("Enter HRA : ");
hra = sc.nextFloat();
salary = basic + da + hra;
}
void displaydata()
{
System.out.print("Salary = "+ salary);
}
void main()
{
readdata();
displaydata();
}
}
Similar questions