Java Programming | Bonus in salary

Introduction

This is a program for bonus in salary in java. The program is given below that takes input from user and calculates bonus and prints it. The program is extendable. Go enjoy the program. Lets begin……

Program for bonus in salary in java.

//import Scanner as we require it.
import java.util.Scanner;

// the name of our class its public
public class Bonus {
	//void main
		public static void main (String[] args)
		{
			//declare int and char
			int a,b;
			char c;

			//Declare input as scanner
			Scanner input = new Scanner(System.in);

			//Take inputs
			 System.out.println("Enter Salary");
			 a = input.nextInt();
			 System.out.println("Enter Gender:");
		     String g = input.next();
		     char d[] = g.toCharArray();
		     c = d[0];
		     //if-else statement
		     if(c=='f')
		   	 {
		        b=(a*10)/100;
		        System.out.println("Bonus Applicable :"+b);
		     }
		     else
		     {
		    	if(c=='m')
		    	{
		    		 b=(a*5)/100;
		    		 System.out.println("Bonus Applicable :"+b);
		    	}
		    	else
		    		System.out.println("Invalid gender");
		     }

		}
}

Output

Enter Salary
120000
Enter Gender:
m
Bonus Applicable :6000

How it works

  1. The program prints the message to enter salary and gender.
  2. The user enters values.
  3. The bonus is calculated and printed.

Extending it

The program is extendable. Create the program using your own bonus system OR changing the formula of calculating bonus.

Explanation.

  1. Import the Scanner.
  2. Declare the class as public
  3. Add the void main function
  4. Add system.out.println() function with the message to enter salary and gender.
  5. Declare input as Scanner.
  6. Take the inputs and save it in variables.
  7. Add a if-else statement.
  8. Calculate the bonus and save it in variable.
  9. Add system.out.println() function to print the bonus.

At the end.

You learnt creating the Java program for Bonus in salary. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s