Input name, salary and sales amount of a sales executive. Find his incentive and gross income.
Incentive rate is 5% of the sales amount that exceeds 500000 (Consider that the sales amount is above 500000).
Print all details. Gross income=salary+incentive.
import java.util.*;
public class Number
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter name, salary and sales amount");
String na=sc.nextLine();
double sal=sc.nextDouble();
double amt=sc.nextDouble();
double incentive=5/100.0*amt;
double gross=amt+sal+incentive;
System.out.println("Name: "+na);
System.out.println("Salary: "+sal);
System.out.println("Sales Amount: "+amt);
System.out.println("Incentive: "+incentive);
System.out.println("Gross income: "+gross);
}
}
2.1.
Input salary and sales amount of a sales executive. Find his incentive and gross salary.
If the sales amount is above 500000 then incentive is 8% of the sales amount that exceeds 500000.
Print salary, sales amount, incentive and gross salary.
import java.util.*;
public class Number
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter salary and sales amount");
double sal=sc.nextDouble();
double amt=sc.nextDouble();
double incentive=0.0;
if(amt>=500000)
incentive=8/100.0*(amt-500000);
double gross=amt+sal+incentive;
System.out.println("Salary: "+sal);
System.out.println("Sales Amount: "+amt);
System.out.println("Incentive: "+incentive);
System.out.println("Gross income: "+gross);
}
}
2.2.
Input salary and sales amount of a sales executive. Find his incentive and gross salary.
If the sales amount is above 500000 then incentive is 10000 + 8% of the sales amount that
exceeds 500000, otherwise 2% of the sales amount. Print salary, sales amount, incentive and gross salary.
import java.util.*;
public class Number
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter salary and sales amount");
double sal=sc.nextDouble();
double amt=sc.nextDouble();
double incentive;
if(amt>=500000)
incentive=10000+8/100.0*(amt-500000);
else
incentive=2/100.0*amt;
double gross=amt+sal+incentive;
System.out.println("Salary: "+sal);
System.out.println("Sales Amount: "+amt);
System.out.println("Incentive: "+incentive);
System.out.println("Gross income: "+gross);
}
}
2.3.
Input salary and sales amount. Find incentive and gross salary; print them along with salary and sales amount.
If sales amount is above 1000000 then incentive is 50000 + 10% of the amount that exceeds 1000000.
If sales amount is above 500000 then 10000 + 8% of the amount that exceeds 500000, else 2%.
import java.util.*;
public class Number
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter salary and sales amount");
double sal=sc.nextDouble();
double amt=sc.nextDouble();
double incentive;
if(amt>1000000)
incentive=5000+10/100.0*(amt-1000000);
else if(amt>500000)
incentive=10000+8/100.0*(amt-500000);
else
incentive=2/100.0*amt;
double gross=amt+sal+incentive;
System.out.println("Salary: "+sal);
System.out.println("Sales Amount: "+amt);
System.out.println("Incentive: "+incentive);
System.out.println("Gross income: "+gross);
}
}
2.4.
Input salary, sales amount and years of service. Find incentive and gross salary. The incentive is calculated
on sales amount. The rate is given below:
Amount Service above 5 yrs Service 5 yrs or below
1000000 or above 11% 10%
500000 or above 9% 8%
Below 500000 3% 2%
import java.util.*;
public class Salary
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter salary, sales amount and years of service");
double sal=sc.nextDouble();
double amt=sc.nextDouble();
int service=sc.nextInt();
double inc;
if(service>5)
{
if(amt>=1000000)
inc=amt*11/100.0;
else if(amt>=500000)
inc=amt*9/100.0;
else
inc=amt*3/100.0;
}
else if(service<=5)
{
if(amt>=1000000)
inc=amt*10/100.0;
else if(amt>=500000)
inc=amt*8/100.0;
else
inc=amt*2/100.0;
}
double gross=sal+inc;
System.out.println("Salary: "+ sal);
System.out.println("Sales Amount: "+ amt);
System.out.println("Incentive: "+inc);
System.out.println("Gross salary: "+gross);
}
}
2.5.
Write a menu-driven program:
1) Calculate incentive and total salary. Rate is 10% on the sales amount
2) Calculate Life Insurance deduction and Remaining salary. Rate is 12% on the salary.
import java.util.*;
public class Salary
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("1 Incentive");
System.out.println("2 Life Insurance");
System.out.println("Enter your choice");
int ch=sc.nextInt();
double salary,amt,incentive,insurance,tot,net;
switch(ch)
{
case 1: System.out.println("Enter salary and sales amount");
salary=sc.nextDouble();
amt=sc.nextDouble();
incentive=amt*10/100.0;
tot=salary+incentive;
System.out.println("Incentive: "+incentive);
System.out.println("Total salary: "+tot);
break;
case 2: System.out.println("Enter salary");
sal=sc.nextDouble();
insurance=salary*12/100.0;
net=salary-insurance;
System.out.println("Insurance: "+insurance);
System.out.println("Net Salary: "+net);
break;
default: System.out.println("Wrong input");
)
}
}
3.1.
Input name, salary and sales amount of n sales executives. Find their incentive and gross salary.
If the sales amount is above 500000 then incentive is 8% of the sales amount that exceeds 500000. Otherwise 2%.
Print salary, sales amount, incentive and gross salary for each employee. Also find grand total of salaries. Format is given below:
Sl.No.NameSalaryAmountIncentiveGross salary
1xxxxxxxxxxxxxxx
Grand total of salaries: xxx
import java.util.*;
public class salary
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of sales executives");
int n=sc.nextInt();
double gtot=0.0;
for(int i=1;i<=n;i++)
{
System.out.println("Enter name, salary and sales amount");
System.out.println("Grand total of salaries: "+gtot);
}
}
4.1.
Input name and salary of n salesmen. Sort both arrays simultaneously name in alphabetical order using bubble sort.
Display both arrays as a list.
import java.util.*;
public class Salary
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of salesmen");
int n=sc.nextInt();
String name[]=new String[n];
double sal[]=new double[n];
int i,j;
for(i=0;i<n;i++)
{
System.out.println("Enter name and salary");
name[i]=sc.next();
sal[i]=sc.nextDouble();
}
String temp1;
double temp2;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(a[j].compareTo(a[j+1])>0)
{
temp1=a[j];
name[j]=name[j+1];
name[j+1]=temp;
temp2=sal[j];
sal[j]=sal[j+1];
sal[j+1]=temp;
}
}
}
System.out.println("Sorted List");
System.out.println("Name\tSalary”);
for(int i=0;i<n;i++)
{
System.out.println((name[i]+“\t”+sal[i]);
}
}
}
4.2.
Initialize integers to a 3 x 3 matrix. Display the left and right diagonals and find some of them separately.
public class Marks
{
public static void main()
{
int a[][]={{1,2,3},{4,5,6},{7,8,9}};
//To display left diagonal and find sum
int i,j,s=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
{
System.out.print(a[i][j]+"\t");
s=s+a[i][j];
}
else
System.out.print("\t");
}
System.out.println();
}
System.out.println("Sum of left diagonal : "+s);
//To display right diagonal and find sum
s=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i+j==2)
{
System.out.print(a[i][j]+"\t");
s=s+a[i][j];
}
else
System.out.print("\t");
}
System.out.println();
}
System.out.println("Sum of right diagonal : "+s);
}
}
5.1.
W a p using overloaded methods void salCalc() to find followings:
1) Calculate incentive and total salary. Rate is 10% on the sales amount
2) Calculate Life Insurance deduction and Remaining salary. Rate is 12% on the salary.
import java.util.*;
public class Allowances
{
static Scanner sc=new Scanner(System.in);
public static void void salCalc(double sal, double amt)
{
double incentive=amt*10/100.0;
double tot=salary+incentive;
System.out.println("Incentive: "+incentive);
System.out.println("Total salary: "+tot);
}
public static void void salCalc(double sal)
{
double deduction=sal*12/100.0;
double net=sal-deduction;
System.out.println("Salary: "+sal);
System.out.println("LIC deduction: "+deduction);
System.out.println("Net salary: "+net);
}
public static void main()
{
System.out.println("Enter salary and sales amount");
double sal=sc.nextDouble();
double amt=sc.nextDouble();
salCalc(sal,amt);
System.out.println("Enter salary");
double salary=sc.nextDouble();
salCalc(salary);
}
}
6.1.
Define a class Salary. Data members / Instance variables: name, salary, incentive and gross.
Member methods: 1) Salary() - parameterized constructor to initialize null values to data members.
2) input() - to input name and salary.
3) salCalc() – to find incentive and gross salary. If annual salary is above 600000 then rate is 8% of the salary else 2%.
4) display() – to display details. Write main() also.