Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that prompts the user first to enter the number of employees and

ID: 3664413 • Letter: W

Question

Write a program that prompts the user first to enter the number of employees and then to enter the name and bonus amount ofr each employee (the name should be a single string with no spaces, the bonus should be a real number). The program should then display the name and bonus amount ofr the employee with the highest bonus. Call your file: Bonus.java. Modify the above program to display two employees with the highest bonus amount. (Do not submit a separate program ofr this, just modify your original code.) You are not allowed to use arrays, ArrayLists, etc.

Explanation / Answer

import java.util.Scanner;


public class EmployeeBonus
{
    static String name[],name2[];
    static float bonus[],maxbonus1,maxbonus2,bonus2[];
    static int NoOfEmp;
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the number of Employees");
        NoOfEmp=sc.nextInt();
        name=new String[NoOfEmp];
        bonus=new float[NoOfEmp];
        bonus2=new float[NoOfEmp-1];
        name2=new String[NoOfEmp-1];

        for(int i=0;i<NoOfEmp;i++)
        {
            System.out.println("Enter the Name");
            name[i]=sc.next();
             System.out.println("Enter the Bonus");
             bonus[i]=sc.nextFloat();

        }
        maxbonus1=maxBonus(bonus);
        for(int k=0;k<bonus.length;k++)
        {
            if(maxbonus1==bonus[k])
            {
                System.out.println("The First Employee Name Wirh Highest Bonus: "+"Name="+name[k]+" "+"Bonus="+bonus[k]);
            }
            else
            {
                bonus2[k]=bonus[k];
                name2[k]=name[k];
            }
        }


        maxbonus2=maxBonus(bonus2);
        for(int k=0;k<bonus2.length;k++)
        {
            if(maxbonus2==bonus2[k])
            {
                System.out.println("The First Employee Name Wirh Highest Bonus: "+"Name="+name2[k]+" "+"Bonus="+bonus2[k]);
            }
            else
            {
                //Nothing
            }
        }


    }

    public static float maxBonus(float bonus[])
    {
        float mxbonus=(float)0;

        mxbonus=bonus[0];

        for(int j=0;j<bonus.length;j++)
        {
            if(bonus[j]>mxbonus)
            {
                mxbonus=bonus[j];
            }
        }


        return mxbonus;
    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote