gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
Write a class emplyee which displays employee's name, id, gross salary and next salary…
- User
Write a class emplyee which displays employee's name, id, gross salary and next salary tax is 5% of the gross salary. net salary =gross salary-tax in java
- Assistant
Below is the implementation of the Employee class in Java:
public class Employee { private String name; private int id; private double grossSalary; private double tax; public Employee(String name, int id, double grossSalary) { this.name = name; this.id = id; this.grossSalary = grossSalary; this.tax = 0.05 * grossSalary; // 5% tax on gross salary } // Method to calculate net salary public double calculateNetSalary() { return grossSalary - tax; } // Method to display employee details public void displayDetails() { System.out.println("Name: " + name); System.out.println("ID: " + id); System.out.println("Gross Salary: $" + grossSalary); System.out.println("Tax: $" + tax); System.out.println("Net Salary: $" + calculateNetSalary()); } public static void main(String[] args) { // Create employee object Employee employee = new Employee("John Doe", 12345, 5000.00); // Display employee details employee.displayDetails(); } }