SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Stuart Reges, Marty Stepp
Chapter:
Introduction To Java Programming
Exercise:
Programming Projects
Question:2 | ISBN:9780136091813 | Edition: 2

Question

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.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

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.

 

0 0

Discussions

Post the discussion to improve the above solution.