I need to write a simple nickname creation GUI using JFrame and/or JSwing. When the user enters their name the program takes the string length and assigns a nickname based on that length. For example if the name entered has 3 or less characters the nickname is “Boy”, but if the name has 4 characters then the nickname is “Baby”, but if the name has 5 characters then the nickname is “Sugar”, but if the name has at least 6 characters or more then the nickname is “Sweety”. There must be at least four different nicknames for four different string lengths.
Explanation / Answer
package nickname; import javax.swing.JOptionPane; public class inputbox { public static void main (String[] args) { String name; String nickname; int slen; name= JOptionPane.showInputDialog("Enter your name to create a nickname"); slen=name.length(); if (slen