Cricketer's Pension ( java program )
Continuing our journey in mastering the conditional statements & our interest with cricket, lets help the Indian cricket's governing body, BCCI to automate its plan of alloting pensions to former players. The rules are given below:
If a player has played more than 10 test matches and 100 ODI's he receives Rs.50,000.
If a player has played more than 10 test matches he receives Rs.25,000.
If a player has played more than 100 ODI's he receives Rs.15,000.
If a player has played for India he receives Rs.10,000.
The amount is incremented by 1/4th for every 'man of the match' award.
If a player has not played for Team India but in IPL, he receives an amount of Rs.8,000.
If a player has not played for Team India[Inter State Twenty,Duleep Trophy,...] nor IPL he receives an amount of Rs.7,000.
Create a main class with the name "Main".
Input and Output Format:
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and the rest corresponds to output]
Sample Input and Output 1:
Has the player represented for India[y or n]?
y
Enter the number of Test matches he has played
15
Enter the number of ODI matches he has played
101
Number of man of the matches he has won
2
Amount received as pension: Rs.75000.0
Sample Input and Output 2:
Has the player represented for India[y or n]?
n
Has he played IPL[y or n]?
y
Amount received as pension: Rs.8000.0
Answers
Here's a Java program that implements the Cricketer's Pension rules based on the given criteria:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Has the player represented for India[y or n]?");
String representedForIndia = scanner.nextLine();
if (representedForIndia.equalsIgnoreCase("y")) {
System.out.println("Enter the number of Test matches he has played");
int testMatches = scanner.nextInt();
System.out.println("Enter the number of ODI matches he has played");
int odiMatches = scanner.nextInt();
System.out.println("Number of man of the matches he has won");
int manOfTheMatches = scanner.nextInt();
int pensionAmount = 10000;
if (testMatches > 10 && odiMatches > 100) {
pensionAmount += 50000;
} else if (testMatches > 10) {
pensionAmount += 25000;
} else if (odiMatches > 100) {
pensionAmount += 15000;
}
pensionAmount += (manOfTheMatches * 2500);
System.out.println("Pension amount: Rs." + pensionAmount);
} else {
System.out.println("Enter the player's playing status [IPL/Other]");
String playingStatus = scanner.next();
int pensionAmount;
if (playingStatus.equalsIgnoreCase("IPL")) {
pensionAmount = 8000;
} else {
pensionAmount = 7000;
}
System.out.println("Pension amount: Rs." + pensionAmount);
}
}
}
```
This program prompts the user for the player's details and calculates the pension amount based on the given rules. The `Scanner` class is used to read the input from the user.
To know more: -
https://brainly.in/question/52952150?referrer=searchResults
https://brainly.in/question/10564501?referrer=searchResults
#SPJ1