Write a Java application that will ask the user to type in a sentence using a JO
ID: 640762 • Letter: W
Question
Write a Java application that will ask the user to type in a sentence using a JOptionPane input dialog, go through each of the characters in the input and count the number of upper case letters, lower case letters and digits, and then print the counts using a JOptionPane message dialog. The application should then repeat this process until the user types the word STOP (or Stop, or STop, etc.)
Some useful methods in class String are:
charAt(int)
equalsIgnoreCase(String)
Some useful methods in the Character wrapper class are:
isUpperCase(char)
isLowerCase (char)
isDigit(char)
Explanation / Answer
public static void main(String[] args){ int number; //For holding the number String stringInput; //For holding the string values until converted //------------------// //Introducing the user JOptionPane.showMessageDialog(null, "This is a program that will ask " + "you to enter a number in-between " + "1-10, if the number is not within " + "the parameters, the program will repeat."); //---------------------// //Get input from the user stringInput = JOptionPane.showInputDialog("Enter number."); number = Integer.parseInt(stringInput); //-----------------// //Checking the number while (number > 10 || number < 0){ stringInput = JOptionPane.showInputDialog("That number is not within the " + "allowed range! Enter another number."); number = Integer.parseInt(stringInput); } //-------------------// //Displaying the number JOptionPane.showMessageDialog(null, "The number you chose is " + number + "."); //-------------// //Closing it down System.exit(0); }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.