All pastes #171061 Raw Edit

Courtney

public text v1 · immutable
·published 2006-09-15 00:17 UTC
rendered paste body
/**
 * PigLatin.java
 * 
 * Courtney Miller
 * 
 * This program reads a first and last name, puts the name into Pig Latin,
 * then displays the result.
 * 
 * Certification of Authenticity:
 *  I certify that this lab is entirely my own work.
 * 
 * 
 */

import java.util.*;
import java.text.*;
import javax.swing.*;

public class PigLatin
{
    public static void main(String [] args)
    {
        //Input Dialog Box
        String upperFullName = JOptionPane.showInputDialog(null, "Enter your first and last name seperated by a space: ");
        
        //Pig Latin Ending
        String pig = "ay";
        
        //Lower Case of name
        String lowerFullName = upperFullName.toLowerCase();
        
        int space = lowerFullName.indexOf(" ");
        int length = lowerFullName.length();
        
        String firstLetterFirstName = lowerFullName.substring(0, 1);
        String firstLetterLastName = lowerFullName.substring(space + 1, space + 2);
        
        //First Name if name begins in a consonant
        String middleOfFirstName = lowerFullName.substring(2, space);
        String firstLetterPigFirst = lowerFullName.substring(1,2);
        String capitalLetterFirst = firstLetterPigFirst.toUpperCase();
        
        //Last Name if name begins in a consonant
        String middleOfLastName = lowerFullName.substring(space + 3, length);
        String firstLetterPigLast = lowerFullName.substring(space + 2, space + 3);
        String capitalLetterLast = firstLetterPigLast.toUpperCase();
        
        //First name if name begins in a vowel
        String firstNameIfVowel = upperFullName.substring(0, space);
        
        //Last name if the name begins in a vowel
        String lastNameIfVowel = upperFullName.substring(space + 1, length);
        
        // First and Last names in Pig Latin if the first letters are consonants
        //String pigFirst = capitalLetterFirst + middleOfFirstName + firstLetterFirstName + pig;
        //String pigLast = capitalLetterLast + middleOfLastName + firstLetterLastName + pig;
        
        // First and Last names in Pig Latin if the first letters are vowels
        //String pigFirstVowel = firstNameIfVowel + pig;
        //String pigLastVowel = lastNameIfVowel + pig;

        char consonantOrVowelFirstName, consonantOrVowelLastName;
        consonantOrVowelFirstName = firstLetterFirstName.charAt(0);
        consonantOrVowelLastName = firstLetterLastName.charAt(0);
        
        if(consonantOrVowelFirstName == 'a') {
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirstVowel + ". Please click ok.");
        }
        else if(consonantOrVowelFirstName == 'b'){
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        }
        else if(consonantOrVowelFirstName == 'c'){
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        }
        else if(consonantOrVowelFirstName == 'd')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'e')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirstVowel + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'f')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'g')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'h')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'i')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirstVowel + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'j')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'k')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'l')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'm')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'n')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'o')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirstVowel + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'p')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'q')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'r')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 's')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 't')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'u')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirstVowel);
        else if(consonantOrVowelFirstName == 'v')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'w')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'x')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'y')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelFirstName == 'z')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else
            System.out.println("Enter a name that contains only letters.");
            
            
            
        if(consonantOrVowelLastName == 'a')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirstVowel + ". Please click ok.");
        else if(consonantOrVowelLastName == 'b')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'c')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'd')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'e')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirstVowel + ". Please click ok.");
        else if(consonantOrVowelLastName == 'f')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'g')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'h')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'i')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirstVowel + ". Please click ok.");
        else if(consonantOrVowelLastName == 'j')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'k')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'l')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'm')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'n')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'o')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirstVowel + ". Please click ok.");
        else if(consonantOrVowelLastName == 'p')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'q')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'r')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 's')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 't')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'u')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirstVowel);
        else if(consonantOrVowelLastName == 'v')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'w')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'x')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'y')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else if(consonantOrVowelLastName == 'z')
            JOptionPane.showMessageDialog(null, "Hello, " + upperFullName + ". Please click OK.");
            JOptionPane.showMessageDialog(null, "Your first name in Pig Latin is " + pigFirst + ". Please click ok.");
        else
            System.out.println("Enter a name that contains only letters.");
 
    }
        
}