1. Engineering
  2. Computer Science
  3. activity 62 my name part 2 find a partner for...

Question: activity 62 my name part 2 find a partner for...

Question details

Activity 6.2: My Name Part 2

  • Find a partner for pair programming.
  • Open up your MyName project from the last activity, and let's add to it.
  • Don't forget to include your partner's name in the comments at the top of the program.
  • Let's calculate the length of the user's first and last names and output the result to the console

System.out.println("The length of your first name is " + first_name.length() + " letters");

  • Now add a similar System.out.println statement to display the length of the user's last name AND full name (remember the full_name variable)
  • Next, let's return the user's initial's to them.
  • Let's declare a new String variable called initials that you place at the top of your program with the other variable declarations.

String initials;

  • Next, we are going to use the charAt() function to extract the initials from the user's first and last names.
  • A person's initials are composed of the first letters of their first and last names.
  • Therefore, we need the letters at position 0 in the first_name and last_name variables.

initials = "" + first_name.charAt(???) + ?????????;

  • Note that "" is called the empty String.
  • Next, print the results to the console to display for the user.

System.out.println("Your initials are: " + initials);

  • Let's compare their first and last names to see if they are the same using the equals method.
  • Add a statement like the following after the last System.out.println:

System.out.println("Your first and last name are the same: " + first_name.equals(last_name));

  • Finally, let's print out the full name in all upper case and all lower case. Add two System.out.println statements:

System.out.println("Your name in all capitals is: " + full_name.toUpperCase());

//Now add a similar statement to print out the name in all lower case characters

  • When you are finished, the output of your program should look like below.
  • However, look closely and you will see a mistake in my output below.
  • Please correct the mistake before you turn it in (there are a couple of different approaches you can take to this problem).
  • Submit your MyName.java program to Canvas.
  • Remember that both partners need to submit for full credit.


The output of your program should look like this (except user input will vary):

Hi! I want to learn your name.
Please enter your first name:
Please enter your last name:
Nice to meet you
The length of your first name is 8 letters
The length of your last name is 7 letters
The length of your full name is 16 letters
Your initials are:
Your first name and last name are the same: false
Your name in all capitals is:
Your name in all lower case letters is:

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution