Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Angjelin Malaj
Angjelin Malaj
5,983 Points

Write a class named Personalizer with 2 instance parameters*, firstName and lastName. The Personalizer class has 4 metho

The Personalizer class has 4 methods: salutation, greeting, lengthOfNames, shortLong

1-The salutation method takes in an input string parameter sirOrMadam and returns the string "Dear [Sir | Madam]" For example, if the input string value is "Sir" than it returns the string "Dear Sir" If the input string value is "Madam" than it returns the string "Dear Madam"

2-The greeting method prints out to the console "Good Day".

3- The lengthOfNames method returns the length of the firstName and lastName combined. For example, If first name is "Hendrix" and last name is "Tavarez" it returns 14 "Hendrix" is 7 characters long and "Tavarez" is also 7 characters long. Hence, 7 + 7 = 14

4-The shortLong method returns the string short if the lengthOfNames method returns an integer less than 8 and it returns the string long if the lengthOfNames method returns an integer equal or greater than 8 write a test function main() that uses the class Personalizer to print out the following:

Dear [Sir | Madam]:

Good Day, [first_name] [last_name] has a very [short | long] name. It has [# of characters] characters.


[Your Name Here]

For example, if the Personalizer's instance input is "Hendrix" and "Tavarez" and the salutation method's input is "Sir"

the test function should print out

Dear Sir:

Good Day, Hendrix Tavarez has a very long name. It has 14 characters.


Your Java Developer

2 Answers

Here's a Personalizer class to get you started. The instance variables really should be private, but there were no getters or setters in the list of methods, so I made them public:

public class Personalizer {
   //these really should be private
   public String firstName;
   public String lastName;

   //they didn't ask for a constructor, but you need one
   //if you are going to create objects with names
   public Personalizer(String firstName, String lastName) {
      this.firstName = firstName;
      this.lastName = lastName;

   public String salutation(String s) {
      return "Dear " + s;

   public void greeting() {
      System.out.print("Good Day");

   public int lengthOfNames() {
      return firstName.length() + lastName.length();

   public String shortLong() {
      if (lengthOfNames() < 8) {
         return "short";
      } else {
         return "long";

And a unfinished program to test it with:

public class PersonalizerMain {
   public static void main(String[] args) {

      Personalizer m = new Personalizer("Hendrix", "Taverez");

      System.out.println(m.salutation("Sir") + ":");
      System.out.println(", " + m.firstName + " " + m.lastName + " has a very " 
         + m.shortLong() + " name.");

      //add your code here


Angjelin Malaj
Angjelin Malaj
5,983 Points

Mr. Jcorum thank you for your help! Its very helpful.


Angjelin Malaj
Angjelin Malaj
5,983 Points

Hello JCorum

I have an assignment in Java language and I was wondering if You could help me with that , since you have been very helpful with previously and I appreciate it. The question is :

Write a programs that given an arrays of coin flips list and count the number of heads or tails as follow:


coinFlips = { "Tail", "Tail", "Head", "Tail", "Tail", "Tail", "Head", "Head", "Tail", "Head" };



  1. index 2

  2. index 6

  3. index 7

  4. index 9

Total heads: 4


  1. index 0

  2. index 1

  3. index 3

  4. index 4

  5. index 5

  6. index 8

Total tails: 6


Add a method that randomly generates and return the array coinFlips