In: Computer Science
Write a complete java program to get input of a person’s age and their years of current USA citizenship. Tell them if they are eligible to run for US House of Representatives, US Senate, or President. At first, have the program just run once and give the answer for the given inputs. Give the answer in a nice format and be clear which offices the person can run for. Write good and complete pseudo code. Next, put that program in a function and call if from a loop that gets input’s from main (no input or output in the function itself). Have the loop run until the user enters 0 for their age. Finally, modify the input GUI so that the user enters only one number if years of citizenship is the same as age (two numbers when they are different). The rules for eligibility are: President: 35 years old and natural born citizen (age and year’s citizenship match) US Senate: 30 years old and 9 years citizenship US House of Representatives: 25 years old and 7 years citizenship.
Following is the required code. Paste the code in a notepad file and save it as Eligibility.java and run it.
import java.util.Scanner;
public class Eligibility {
void check()
{
Scanner sc=new Scanner(System.in);
int age=0, years_of_citizenship=0;
System.out.println("Enter your age:");
age = sc.nextInt();
System.out.println("Enter your years of US citizenship:");
years_of_citizenship=sc.nextInt();
if(age == years_of_citizenship)
System.out.println("US President : Eligible");
else
System.out.println("US President : Not Eligible");
if((age >= 30) && (years_of_citizenship >= 9))
System.out.println("US Senate : Eligible");
else
System.out.println("US Senate : Not Eligible");
if((age >= 25) && (years_of_citizenship >= 7))
System.out.println("US House of Representatives : Eligible");
else
System.out.println("US House of Representatives : Not
Eligible");
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Hello User!");
while(true)
{
Eligibility e= new Eligibility();
e.check();
System.out.println("Enter any number to continue or enter 0 to
exit");
int flag = sc.nextInt();
if (flag==0)
break;
}
}
}