MIT-Curricular/OOP/Java/Lab/Week5/Employee.java

46 lines
1.3 KiB
Java

import java.util.Scanner;
public class Employee {
String name;
String city;
double salary;
double da;
double hra;
double ctc;
public void getData() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Employee Name: ");
name = sc.nextLine();
System.out.print("Enter city: ");
city = sc.nextLine();
System.out.print("Enter salary: ");
salary = sc.nextDouble();
System.out.print("Enter dearness allowance (DA%): ");
da = sc.nextDouble();
System.out.print("Enter house rent allowance (HRA%): ");
hra = sc.nextDouble();
sc.close();
}
public double calculateCTC() {
ctc = salary + (salary * (da+hra) / 100) +;
return ctc;
}
public void display() {
System.out.println("Employee Name: " + name);
System.out.println("Employee City: " + city);
System.out.println("Employee Salary: " + salary);
System.out.println("Employee DA%: " + da);
System.out.println("Employee HRA%: " + hra);
System.out.println("Employee CTC (Total Cost to Company): " + ctc);
}
public static void main(String[] args) {
Employee emp = new Employee();
emp.getData();
emp.calculateCTC();
emp.display();
}
}