In: Computer Science
Write a program that: a. Asks the user for their first name using a JOptionPane. b. Asks the user for their age using a JOptionPane. C. Asks the user for their last name using a JOptionPane. d. Pops up a dialog with the following information: i. Number of characters in the first & last name combined ii. The full name all-in upper-case letters iii. The full name all-in lower-case letters iv. The first letter of the name v. The age and test your code in NetBeans and then on Hackerrank and screenshot of passing all test cases on Hackerrank.
Thanks for the question. Below is the code you will be needing Let me know if you have any doubts or if you need anything to change. Also, sharing all the screenshots of a sample run. Thank You !! =========================================================================== import javax.swing.*; public class Name{ public static void main(String[] args) { String firstName = JOptionPane.showInputDialog("Enter first name: "); String age = JOptionPane.showInputDialog("Enter your age: "); String lastName = JOptionPane.showInputDialog("Enter last name: "); // i. Number of characters in the first & last name combined int totalCharacters = firstName.length() + lastName.length(); JOptionPane.showMessageDialog(null, "Total characters: " + totalCharacters); //ii. The full name all-in upper-case letters String fullNameInU = firstName.toUpperCase() + " " + lastName.toUpperCase(); JOptionPane.showMessageDialog(null, fullNameInU); //iii. The full name all-in lower-case letters String fullNameInL = firstName.toLowerCase() + " " + lastName.toLowerCase(); JOptionPane.showMessageDialog(null, fullNameInL); // iv. The first letter of the name JOptionPane.showMessageDialog(null, "First letter: " + firstName.charAt(0)); //The age JOptionPane.showMessageDialog(null, "Your age: " + age); } }