The pension rule of a certain country states that a man receives Rs.50/- a week if he is over 65 years and an extra Rs.20/- if he is over 70 years. A woman receives Rs.45/- a week if she is over 60 years and extra Rs.25/- if she is over 65 years.WAP which takes the sex(M for male, F for female) and age of the person as input print out the amount of weekly pension they would get. If a person is below the pensionable age,a suitable message must be printed.
import java. util.*;
classPension
{
public static void main()
public static void main()
{
Scanner Sc=new Scanner(System.in);
System.out.println(“Enter the sex of the person and age ”);
String sex=Sc.nextLine(); int pen;
int age=Sc.nextInt(); if(sex.equals”Male”&&age>65&&age<=70)
{p=50;} if(sex.equals”Male”&&age>70)
{pen=70;} if(sex.equals”Female”&&age>60&&age<=65) {pen=45;} if(sex.equals”Female”&&age>65) {pen=70;} if(sex.equals”Male”&&age<65) {System.out.println(“No pension will be given”);
if(sex.equals”Female”&&age<60) {System.out.println(“No pension will be given”);} {System.out.println(“Sex “+sex);} {System.out.println(“Age “+age);}
{System.out.println(“Pension given “+pen);} } }
Output: Enter
the sex MaleScanner Sc=new Scanner(System.in);
System.out.println(“Enter the sex of the person and age ”);
String sex=Sc.nextLine(); int pen;
int age=Sc.nextInt(); if(sex.equals”Male”&&age>65&&age<=70)
{p=50;} if(sex.equals”Male”&&age>70)
{pen=70;} if(sex.equals”Female”&&age>60&&age<=65) {pen=45;} if(sex.equals”Female”&&age>65) {pen=70;} if(sex.equals”Male”&&age<65) {System.out.println(“No pension will be given”);
if(sex.equals”Female”&&age<60) {System.out.println(“No pension will be given”);} {System.out.println(“Sex “+sex);} {System.out.println(“Age “+age);}
{System.out.println(“Pension given “+pen);} } }
Enter your age 68
Sex Male
Age 68
Pension given 65
No comments: