UpperLowerCase /* * Filename: "UpperLowerCase.java" * Created by 1,000_naymes for ICt 352 * Purpose: to transform a string into all uppercase or all lowercase */ import javax.swing.JOptionPane; import java.util.Scanner;
// for GUIs // for formatting
public class UpperLowerCase { public static void main( String[] args ) { /************************************************************** declare and initialize variables **************************************************************/ String openingMessage = "This program will ask you for a string and then format it to all \n" + "uppercase or all lowercase.", menu, menu2, choiceMessage, choiceString, userString, userMessage = "Okay, please enter your string below: ", inputInputMessage, inputString,info, infoMessage, user, stringInputMessage, stringString, choice2Message, choice2String; int choice, choice2; JOptionPane.showMessageDialog( null, openingMessage ); /************************************************************** input **************************************************************/ menu = "Please enter \n" + "1 to enter a string\n" + "2 to transform your string to all uppercase\n" + "3 to transform your string to all lowercase\n" + "4 to quit. "; choiceString = JOptionPane.showInputDialog( menu ); choice = Integer.parseInt( choiceString ); //converting string to integer do { switch( choice ) { case 1: /************************************************************** input string **************************************************************/ choice2Message = "Please enter\n" + "2 to transform your string to all uppercase or \n" + "3 to transform your string to all lowercase. \n"; choice2String = JOptionPane.showInputDialog( choice2Message ); choice2 = Integer.parseInt( choice2String ); switch( choice2 ) { case 2: /************************************************************** transform to all uppercase **************************************************************/ userString = JOptionPane.showInputDialog( userMessage ); user = (userString); Page 1
UpperLowerCase info = user.toUpperCase(); infoMessage = "You entered '"+ info + "'"; JOptionPane.showMessageDialog( null, infoMessage); choiceString = JOptionPane.showInputDialog( menu ); choice = Integer.parseInt( choiceString ); //converting string to integer if( choice == 4) System.exit(0); break; case 3: /************************************************************** transform to all lowercase **************************************************************/ userString = JOptionPane.showInputDialog( userMessage ); user = (userString); info = user.toLowerCase(); infoMessage = "You entered '"+ info + "'"; JOptionPane.showMessageDialog( null, infoMessage ); choiceString = JOptionPane.showInputDialog( menu ); choice = Integer.parseInt( choiceString ); //converting string to integer if( choice == 4) System.exit(0); break; } // end switch( choice2 ) case 2: /************************************************************** transform to all uppercase **************************************************************/ userString = JOptionPane.showInputDialog( userMessage ); user = (userString); info = user.toUpperCase(); infoMessage = "You entered '"+ info + "'"; JOptionPane.showMessageDialog( null, infoMessage); choiceString = JOptionPane.showInputDialog( menu ); choice = Integer.parseInt( choiceString ); //converting string to integer if( choice == 4) System.exit(0); break; case 3: /************************************************************** transform to all lowercase **************************************************************/ userString = JOptionPane.showInputDialog( userMessage ); user = (userString); info = user.toLowerCase(); infoMessage = "You entered '"+ info + "'"; JOptionPane.showMessageDialog( null, infoMessage ); choiceString = JOptionPane.showInputDialog( menu ); choice = Integer.parseInt( choiceString ); //converting string to integer if( choice == 4) Page 2
UpperLowerCase System.exit(0); break; case 4: /************************************************************** quit **************************************************************/ System.exit(0); } } while(choice != 4); System.exit(0); } }
Page 3