salary app java

 


package salaryapp;


import java.util.Calendar;

import java.util.Scanner;



public class Salaryapps {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);


        // Input employee details

        System.out.print("Enter employee name: ");

        String employeeName = scanner.nextLine();

        System.out.print("Enter year joined: ");

        int yearJoined = scanner.nextInt();

        System.out.print("Enter current salary: ");

        double currentSalary = scanner.nextDouble();


        // Calculate the employee's rank

        int rank = getRank(yearJoined);


        if (rank > 0) {

            // Calculate the increment

            double increment = getIncrement(currentSalary, yearJoined);


            // Display the salary slip

            System.out.println("Employee Name: " + employeeName);

            System.out.println("Year Joined: " + yearJoined);

            System.out.println("Current Salary: $" + currentSalary);

            System.out.println("Rank: " + rank);

            System.out.println("Increment: $" + increment);

            System.out.println("New Salary: $" + (currentSalary + increment));

        } else {

            System.out.println("Employee is not eligible for an increment.");

        }

    }


    // Function to calculate the employee's rank based on years of experience

    public static int getRank(int yearJoined) {

        int currentYear = Calendar.getInstance().get(Calendar.YEAR);

        int experience = currentYear - yearJoined;


        if (experience >= 10) {

            return 1;

        } else if (experience >= 7) {

            return 2;

        } else if (experience >= 5) {

            return 3;

        } else {

            return 0;

        }

    }


    // Function to calculate the increment based on rank and current salary

    public static double getIncrement(double basicSal, int yearJoined) {

        int rank = getRank(yearJoined);

        double incrementPercentage = 0.0;


        // Use a switch statement to determine the increment percentage based on rank

        switch (rank) {

            case 1:

                incrementPercentage = 0.30;

                break;

            case 2:

                incrementPercentage = 0.25;

                break;

            case 3:

                incrementPercentage = 0.15;

                break;

        }


        // Calculate the increment amount

        return basicSal * incrementPercentage;

    }

}

    


0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post