Created
October 25, 2013 03:07
-
-
Save anonymous/7148897 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Author: Christopher Martinez | |
| Date: 10/23/13 | |
| Description: | |
| Write a program that starts with the string variable 'first' set to your first | |
| name and the string variable last set to your last name. Both names should be | |
| all lowercase. Your program should then create a new string that contains your | |
| full name in pig latin with the first letter capitalized for the first and last | |
| name. Use only the pig latin rule of moving the first letter to the end of the | |
| word and adding "ay." Output the pig latin name to the screen. Use 'substring' | |
| and 'toUpperCase' methods to contruct the new name. | |
| For example, given | |
| first = "walt"; | |
| last = "savitch"; | |
| the program should create a new string with the text "Altway Avitchsay" | |
| and print it. | |
| */ | |
| public class PP1_3 | |
| { | |
| public static void main(String[] args) | |
| { | |
| // variable declarations | |
| String first = "walter"; | |
| String last = "savitch"; | |
| String pigLatinFirst; | |
| String pigLatinLast; | |
| String fullPigLatinName; | |
| // function calls that transform the names | |
| pigLatinFirst = latinName(first); | |
| pigLatinLast = latinName(last); | |
| fullPigLatinName = fullName(pigLatinFirst, pigLatinLast); | |
| // display result | |
| System.out.println("---------------------------------------------------"); | |
| System.out.println("Initial first name: " + first); | |
| System.out.println("Initila last name: " + last); | |
| System.out.println(""); | |
| System.out.println("Full pig latin name: " + fullPigLatinName); | |
| System.out.println("---------------------------------------------------"); | |
| } | |
| // changes parameter string into a pig latin name; returns the changed string | |
| public static String latinName(String name) | |
| { | |
| String changedName = (name.substring(1, name.length()) + | |
| name.substring(0, 1) + "ay"); | |
| changedName = changedName.substring(0, 1).toUpperCase() + | |
| changedName.substring(1, changedName.length()); | |
| return changedName; | |
| } | |
| // returns the first and last name strings as a single full name string | |
| public static String fullName(String first, String last) | |
| { | |
| return first + " " + last; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment