Question

In: Computer Science

Write a complete java program to get input of a person’s age and their years of...

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.

Solutions

Expert Solution

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;
}
}
}


Related Solutions

Write a complete java program to get input of a person’s age and their years of...
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...
Write a complete Java program that does the following: Open an input file named data.txt that...
Write a complete Java program that does the following: Open an input file named data.txt that consists of a series of unknown number of integers. If data.txt does not exist, give an appropriate error message and terminate the program. Define a constant MAX of value 100 and create an array of size MAX to hold items from the input file. Make sure your program will not generate ArrayIndexOutOfBounds exception. Open an output file named result.txt and write the array elements...
(JAVA) Create a program that prompts the user for an age input. The program defines the...
(JAVA) Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program. Age Age Group 0 Baby 1-3 Toddler 4-11 Child 12-17 Teenager 18-21 Young Adult 22-64 Adult 65+ Senior Negative Number Invalid Input Sample Input Enter an age: 18 Sample Output: You are a young adult. Sample Input Enter an age: 29 Sample Output: You are an adult. Sample...
Write a Java program that will add the digits of a person’s birth date to obtain...
Write a Java program that will add the digits of a person’s birth date to obtain a single digit to generate a numerology number. Write one separate method for each of the following tasks (it goes w/o saying that you will have a main() method along with these): date validating date crunching First: Get a Date Numerology has been used since ancient times to shed light on relationships, health, and global events. Each element in a birth date is believed...
Write a complete program in java that will do the following:
Write a complete program in java that will do the following:Sports:             Baseball, Basketball, Football, Hockey, Volleyball, WaterpoloPlayers:           9, 5, 11, 6, 6, 7Store the data in appropriate arraysProvide an output of sports and player numbers. See below:Baseball          9 players.Basketball       5 players.Football           11 players.Hockey            6 players.Volleyball        6 players.Waterpolo       7 players.Use Scanner to provide the number of friends you have for a team sport.Provide an output of suggested sports for your group of friends. If your...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles, and the class of journey (1,2, or 3, for first, second, and third class respectively), for a train journey. The program should then calculate and display the fare of journey based on the following criteria: Note: Use Switch...case and if...else construct First (1) Class Second (1) Class Third (3) Class First 100 mile $ 3 per mile $ 2 per mile $ 1.50...
Write a program in Java that will take as input two sets A and B, and...
Write a program in Java that will take as input two sets A and B, and returns a list of all functions from A to B.
Write a java program that read a line of input as a sentence and display: ...
Write a java program that read a line of input as a sentence and display:  Only the uppercase letters in the sentence.  The sentence, with all lowercase vowels (i.e. “a”, “e”, “i”, “o”, and “u”) replaced by a strike symbol “*”.
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT