Question is in the attachment.
Don't spam please
Answers
The given problem is solved using language - Java.
import java.util.*;
public class Brainly{
public static void main(String s[]){
double BS,DA,SA,GS;
Scanner sc=new Scanner(System.in);
System.out.print("Enter basic salary: ");
BS=sc.nextDouble();
if(BS<0){
System.out.println("Invalid Input.");
}
else{
if(BS<=10000){
DA=15.0/100.0*BS;
SA=5.0/100.0*BS;
}
else if(BS<=20000){
DA=20.0/100.0*BS;
SA=8.0/100.0*BS;
}
else if(BS<=30000){
DA=25.0/100.0*BS;
SA=10.0/100.0*BS;
}
else{
DA=30.0/100.0*BS;
SA=12.0/100.0*BS;
}
GS=BS+DA+SA;
System.out.println("Basic\tDA\tSpl. Allowance\tGross Salary");
System.out.println(BS+"\t"+DA+"\t"+SA+"\t\t"+GS);
sc.close();
}
}
}
- Accept the basic salary as input.
- Check if the basic salary is valid or not.
- If valid, calculate DA and SA as per the conditions given.
- Add basic, DA and SA and store them in variable GS.
- Display the result in tabular form.
See attachment for output.
Answer:
Program:-
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int bp;
double da=0,sa=0,gs=0;
System.out.println("Enter the basic pay of the employee:");
bp=in.nextInt();
if(bp<=10000)
{
da=15.0/100.0*bp;
sa=5.0/100.0*bp;
gs=bp+da+sa;
}
else if(bp>10000&&bp<=20000)
{
da=20.0/100.0*bp;
sa=8.0/100.0*bp;
gs=bp+da+sa;
}
else if(bp>20000&&bp<=30000)
{
da=25.0/100.0*bp;
sa=10.0/100.0*bp;
gs=bp+da+sa;
}
else if(bp>30000)//The statements after else are optional even you don't place any condition the compiler will treat it as it is.
{
da=30.0/100.0*bp;
sa=12.0/100.0*bp;
gs=bp+da+sa;
}
System.out.println("Basic\t\t"+"DA\t\t\t"+"Spl. Allowance\t"+"Gross Salary"); System.out.println(bp+"\t"+da+"\t\t\t"+sa+"\t\t\t\t\t\t\t"+gs);
in.close();
}
}
Output is attached.
Logic:-
- Declare basic pay and declare and initialize variables da,sa and gs.
- See the conditions and use nested if else statement
- Finally print and display the output as per the given format given in the question.
- For formatting use escape sequence "\t" which must be enclosed within double quotes.