25.7k views
5 votes
In every year there is a salary increment of ksh.2000.Write a java program to read the starting salary of an employee, calculate and output the expected salary for the next 5 years

1 Answer

2 votes

Java program to read the starting salary of an employee, calculate and output the expected salary for the next 5 years, with a salary increment of Ksh.2000 every year:

```java

import java.util.Scanner;

public class SalaryIncrement {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

// Read the starting salary of the employee

System.out.print("Enter the starting salary of the employee: ");

double startingSalary = scanner.nextDouble();

// Calculate the expected salary for the next 5 years

double expectedSalary[] = new double[5];

expectedSalary[0] = startingSalary;

for (int i = 1; i < 5; i++) {

expectedSalary[i] = expectedSalary[i - 1] + 2000;

}

// Output the expected salary for the next 5 years

System.out.println("The expected salary for the next 5 years is:");

for (int i = 0; i < 5; i++) {

System.out.println("Year " + (i + 1) + ": Ksh." + expectedSalary[i]);

}

scanner.close();

}

}

```

Example output:

```

Enter the starting salary of the employee: 20000

The expected salary for the next 5 years is:

Year 1: Ksh.20000.0

Year 2: Ksh.22000.0

Year 3: Ksh.24000.0

Year 4: Ksh.26000.0

Year 5: Ksh.28000.0

```