Close
Close

Ask user to enter age, sex ( M or F ), marital status ( Y or N ) and then using following rules print their place of service.

   rajesh644

Ask user to enter age, sex ( M or F ), marital status ( Y or N ) and then using following rules print their place of service.
if 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 employee is male and age is in between 40 t0 60 then he will work in urban areas only.

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

  • 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? "); char Married = sc.next().charAt(0); System.out.println("Age - " +age); System.out.println("Sex - " +sex); System.out.println("Married - " +Married); if (sex == 'F'){ System.out.println(" Employee will work only urban areas."); } else if (sex == 'M'&& age>=20 && age<40){ System.out.println("Employee may work anywher "); } else if (sex == 'M' && age>=40 && age <60){ System.out.println("Employee will work only urban areas"); } else if (age<20 || age>=60){ System.out.println(" ERROR "); }
    - pranay7052

Answers

  •   

    I am writing the code for the problem below where the conditions are given using if else

    import java.util.*;
    
    class Ideone
    {
    	public static void main (String[] args) {
    		
    		Scanner sc = new Scanner (System.in);
    		
    		// taking input from user 
    		
    		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);
    		
    		// checking if user is female
    		if(sex == 'F') {
    			System.out.println("You will work only in urban areas");
    		}
    		
    		// checking if user is male
    		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");
    			}
    		}
    	}
    }
    

     



  •    111418106018

    //SOLUTION USING C++ LANUAGE

    #include<iostream>

    using namespace std;

    int main() {

    int age;

    char gender,ms;    //ms-marital status

    char m,f,y,n;      //m-male , f-female ,y-yes, n-no

    cout<<"enter age of employee"<<;

    cin>>age;

    cout<<"enter gender of employee"<<;

    cin>>gender;

    cout<<"marital status of employee"<<;

    cin>>ms;

    if(gender=='f') {
    cout<<"employee will only work in urban areas"<<endl;

    }

    if(gender=='m')

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

         cout<<"employee will work any where"<<endl;

         }

    else if(age>40 & age<=60) {

         cout<<"employee will only work in urban areas"<<endl;

         }

    else {

         cout<<"error"<<endl;

          }

    return 0;

    }




  •    Wuzzy

    I'm not married and I'm not even in a relationship because I don't want anything serious and I don't want a girl to control me. I just have a good time with different girls and that suits me. If any of you share my views then read the blog https://www.theyucatantimes.com/2019/05/tips-on-how-to-get-a-girl-hooked/ and you will learn useful tips on how seduce any girl quickly. Enjoy and don't thank me!



  •    seoexpertim

    Customizing a mobile phone with ringtones is important, and that's why I appreciate this info. I want something about https://www.poruninstitutoparatodos.com/ so if you can provide some help, I would greatly appreciate it.



  •    Veloriaos

    Create a personalised gift for someone else or yourself. Boomf https://boomf.com/collections/engagement-cards will make it easy with thousands of images written or drawn just for you. Best part: Boomf is FAST – we can create, deliver and ship any Boomf in less than 48 hours, so there’s no need to wait!



Ask Yours
Post Yours
Write your answer