From 3957b1c51b072995289399a0f6a4dad46b822168 Mon Sep 17 00:00:00 2001 From: Aadit Agrawal Date: Sat, 31 Aug 2024 09:57:00 +0530 Subject: [PATCH] Add OOP/Java/Lab/Week5/Employee.java --- OOP/Java/Lab/Week5/Employee.java | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 OOP/Java/Lab/Week5/Employee.java diff --git a/OOP/Java/Lab/Week5/Employee.java b/OOP/Java/Lab/Week5/Employee.java new file mode 100644 index 0000000..5ad63ae --- /dev/null +++ b/OOP/Java/Lab/Week5/Employee.java @@ -0,0 +1,46 @@ +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(); + } +} \ No newline at end of file