92.6k views
0 votes
1. The US Constitution establishes that only a natural born citizen who is at least thirty-five years of age is eligible to be President of the US (Article 2/section 1). Create a Java program to help a user determine if s/he is eligible to be President. (Use Dialog boxes for input/output).

User Mgarey
by
8.0k points

1 Answer

2 votes

Answer:

import javax.swing.JOptionPane;

public class PresidentEligibility {

public static void main(String[] args) {

String ageInput = JOptionPane.showInputDialog("Please enter your age:");

int age = Integer.parseInt(ageInput);

String citizenshipInput = JOptionPane.showInputDialog("Please enter your citizenship status:");

String citizenship = citizenshipInput.toLowerCase();

if(age >= 35 && citizenship.equals("natural born citizen")) {

JOptionPane.showMessageDialog(null, "You are eligible to be President!");

} else {

JOptionPane.showMessageDialog(null, "Sorry, you are not eligible to be President.");

}

}

}

User Thibault Falise
by
8.1k points