Sometimes we write similar letters to different people. For example, you might write to your parents to tell them about your classes and your friends and to ask for money; you might write to a friend about your love life, your classes, and your hobbies; and you might write to your brother about your hobbies and your friends and to ask for money. Write a program that prints similar letters such as these to three people of your choice. Each letter should have at least one paragraph in common with each of the other letters. Your main program should have three method calls, one for each of the people to whom you are writing. Try to isolate repeated tasks into methods.
Program:
public class Ch01PP02
{
public static void main(String[] args)
{
writeToParents();
writeToFriend();
writeToBrother();
}
public static void writeToParents()
{
System.out.println("Hi my dear parents,");
aboutClasses();
aboutFriends();
aboutToAskForMoney();
System.out.println();
}
public static void writeToFriend()
{
System.out.println("Hi my dear friend,");
aboutLoveLife();
aboutClasses();
aboutHobbies();
System.out.println();
}
public static void writeToBrother()
{
System.out.println("Hi my dear brother,");
aboutHobbies();
aboutFriends();
aboutToAskForMoney();
System.out.println();
}
public static void aboutClasses()
{
System.out.println("My classes are going well and");
System.out.println(" may be completed by the end of the next month.");
}
public static void aboutFriends()
{
System.out.println("I have three friends and they help be in any point of time.");
}
public static void aboutHobbies()
{
System.out.println("My hobbies are playing cricket and watching TV.");
}
public static void aboutToAskForMoney()
{
System.out.println("Please send the amount of $100 for my needs.");
}
public static void aboutLoveLife()
{
System.out.println("My lover is a good and kind hearted person.");
}
}
Output:
Hi my dear parents,
My classes are going well and
may be completed by the end of the next month.
I have three friends and they help be in any point of time.
Please send the amount of $100 for my needs.
Hi my dear friend,
My lover is a good and kind hearted person.
My classes are going well and
may be completed by the end of the next month.
My hobbies are playing cricket and watching TV.
Hi my dear brother,
My hobbies are playing cricket and watching TV.
I have three friends and they help be in any point of time.
Please send the amount of $100 for my needs.