0% found this document useful (0 votes)
269 views

Selection - Nested If

The document describes rules for determining an employee's place of work based on their gender, age, and marital status. If the employee is female, she will work only in urban areas. If the employee is male between ages 20-40, he may work anywhere. If the employee is male between ages 40-60, he will work only in urban areas. Any other age input will print an error message. The document then provides pseudocode and Java code implementations of these rules.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
269 views

Selection - Nested If

The document describes rules for determining an employee's place of work based on their gender, age, and marital status. If the employee is female, she will work only in urban areas. If the employee is male between ages 20-40, he may work anywhere. If the employee is male between ages 40-60, he will work only in urban areas. Any other age input will print an error message. The document then provides pseudocode and Java code implementations of these rules.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

3.

Ask users to enter age, gender ( M or F ), marital status ( Y or N ) and then using

following rules print their place of service.

If the employee is female, then she will work only in urban areas.

If employee is a male and age is in between 20 to 40 then he may work in

anywhere

If the employee is male and age is between 40 t0 60 then he will work in urban

areas only.

And any other input of age should print "ERROR".

1)IPO

I : age , gender ( M or F) , marital status (Y or N)

P Determine work areas based on age , gender ( M or F) , marital status (Y or N)

O: work areas

2) PSEUDOCODE

Start

Input age , gender , marital status

If (gender = F)

Print “ work areas = urban “

Else if (gender =M)

if (age >= 20 && <=40)

Print “work areas = anywhere “

Else if ( age >= 40 && <=60)

Print “work areas =urban “

Else

Print “ Error”

End if

End if

Stop
3) FLOWCHART
4)JAVA CODING

i) NORMAL CODING
//Author ili
//nested if question 3

import java.util.*;
class Area{
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);

System.out.println("Enter age");
int age = sc.nextInt();

System.out.println("Enter sex: M/F");


int sex = sc.next().charAt(0);

System.out.println("Are you married? Y/N");


int married = sc.next().charAt(0);

if(sex == 'F') {
System.out.println("you will work area only in urban
areas");
}

if(sex == 'M') {
if((age >= 20) && (age < 40)) {
System.out.println("You may work anywhere");
}
else if((age >= 40) && (age < 60)) {
System.out.println("You will work only in urban
areas");
}
else {
System.out.println("ERROR");
}
}
}
}
ii) USING METHOD

//Author ili
//nested if question 3

import java.util.*;
class WorkArea{
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);

System.out.println("Enter age");
int age = sc.nextInt();

System.out.println("Enter sex: M/F");


char sex = sc.next().charAt(0);

System.out.println("Are you married? Y/N");


int married = sc.next().charAt(0);

WorkArea obj = new WorkArea();


obj.placesofwork(sex, age);

void placesofwork(char sex, int age ) {

if(sex == 'F') {
System.out.println("you will work area only in urban areas");
}

if(sex == 'M') {
if((age >= 20) && (age < 40)) {
System.out.println("You may work anywhere");
}
else if((age >= 40) && (age < 60)) {
System.out.println("You will work only in urban areas");
}
else {
System.out.println("ERROR");
}
}
}
}

You might also like