Question

In: Computer Science

Write a Java program to do the following with your name. This can all be done...

Write a Java program to do the following with your name. This can all be done in the main() method.

1. Create a String variable called myName and assign your personal name to it. Use proper capitalization for a legal name. I.e. String myName = "Billy Bob";

2. Load myName with the upper case version of itself and display the result.

3. Load myName with the lower case version of itself and display the result.

4. Capitalize the first letter of each given name in the lowercased name and display the result. Load the result into myName. Hint: This is not a single method call. You will need a loop to perform this. Hint: The substring method will be very helpful as you should likely build a new string result. Avoid magic number references. This solution should work with any proper name.

5. Using the value of the variable myName from step 4:

a.Display the Initials of the name. ( This may require a Loop)
b.Use the trim methd on myName and store the results into myName.
c.Display the size of the name
// Using Billy Bob as the name - here are the expected results:

My name in upper case is BILLY BOB.

My name in lower case is billy bob.

My name capitalized is Billy Bob.

My initials are BB.

The length of my name is 9.

Solutions

Expert Solution

if you have any doubts, please give me comment...

public class NameExercise{

    public static void main(String[] args) {

        String myName = "Billy Bob";

        myName = myName.toUpperCase();

        System.out.println("My name in upper case is "+myName+".");

        myName = myName.toLowerCase();

        System.out.println("My name in lower case is "+myName+".");

        String result = "";

        for(String temp: myName.split(" ")){

            result += (temp.charAt(0)+"").toUpperCase()+temp.substring(1)+" ";

        }

        myName = result.trim();

        System.out.println("My name capitalized is "+myName+".");

        result = "";

        for(String n: myName.split(" ")){

            result += (myName.charAt(0)+"");

        }

        System.out.println("My initials are "+result+".");

        System.out.println("The length of my name is "+myName.length()+".");

    }

}


Related Solutions

Write a program in Java Swing that can Display all the name list then will generate...
Write a program in Java Swing that can Display all the name list then will generate and display the longest name out of a list of names. Thank you...
TreeSetDemo IN JAVA PLEASE The following program can be done all in the main method. It...
TreeSetDemo IN JAVA PLEASE The following program can be done all in the main method. It demonstrates that a TreeSet eliminates duplicates and is ordered. Create a Random object with a seed of 5. Create an ArrayList numAL of type Integer Populate numAL with 10 numbers randomly selected from 0 to 6 Print out numAL Create a TreeSet numTS of type Integer Create an Iterator alIter from numAl and use it to add all the elements of numAL in numTS....
Create a Java Program to calculate compound interest. This can all be done in the main()...
Create a Java Program to calculate compound interest. This can all be done in the main() method. Create a double variable named currentBalance. Create a double variable named newBalance. Create a final double variable named INTEREST_RATE and assign 1.05 to it. Create a int variable named yearCount. Prompt for the "Number of years to invest" and store the input into the yearCount variable. Prompt for the "Amount to Invest" and store this in the currentBalance variable. Assign currentBalance to newBalance....
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name, that does the following: Create two arrays that will hold related information. You can choose any information to store, but here are some examples: an array that holds a person's name and an array that hold's their phone number an array that holds a pet's name and an array that holds what type of animal that pet is an array that holds a student's...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name, that does the following: Declare an array reference variable called myFavoriteSnacks for an array of String type. Create the array so that it is able to hold 10 elements - no more, no less. Fill the array by having each array element contain a string stating one of your favorite foods/snacks. Note: Only write the name of the snack, NO numbers (i.e. Do not...
Using jGRASP, write a Java program named LastnameFirstname11.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname11.java, using your last name and your first name, that does the following: Defines a method called generateNums. This method will create an array of size x, fill it with random numbers between y and z, then return the array. When you call the method, you must specify the size of the array (x), the beginning of your random number range (y), and the ending of your random number range (z). Defines a...
This program must be done in JAVA. Write a program to monitor the flow of an...
This program must be done in JAVA. Write a program to monitor the flow of an item into an out of a warehouse. The warehouse has numerous deliveries and shipments for this item (a widget) during the time period covered. A shipment out (an order) is billed at a profit of 50% over the cost of the widget. Unfortunately each incoming shipment may have a different cost associated with it. The accountants of the firm have instituted a last-in, first...
Specifications: Write a Java program called LifeRaft.java that will do all of the following: Display a...
Specifications: Write a Java program called LifeRaft.java that will do all of the following: Display a title Ask the user to enter the following values: The type of plane(Boeing 747 or Airbus A300) The number of passengers on board the Plane The number of crew aboard the plane The maximum number of people that can be carried by one liferaft assuming all the liferafts on the plane are the same size The actual number of liferafts that are available on...
Write a complete program in java that will do the following:
Write a complete program in java that will do the following:Sports:             Baseball, Basketball, Football, Hockey, Volleyball, WaterpoloPlayers:           9, 5, 11, 6, 6, 7Store the data in appropriate arraysProvide an output of sports and player numbers. See below:Baseball          9 players.Basketball       5 players.Football           11 players.Hockey            6 players.Volleyball        6 players.Waterpolo       7 players.Use Scanner to provide the number of friends you have for a team sport.Provide an output of suggested sports for your group of friends. If your...
For each problem below, write a java program to solve it, name your programs as PA2_1.java...
For each problem below, write a java program to solve it, name your programs as PA2_1.java and PA2_2.java. 1. We have a steam heating boiler whose bursting pressure is known, but we of course want to use it only at pressures well below this limit. Our engineers recommend a safety factor of 3; that is, we should never exceed a pressure that is one-third of the rated bursting pressure. Write a java program that reads in the rated bursting pressure...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT