Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Letter 1/-----------Start below here. To do: approximate lines of code = 16 Create 3 instance variables of type String. One for * the

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

public class Letter 1/-----------Start below here. To do: approximate lines of code = 16 Create 3 instance variables of type String. One for * the sender of the letter, one for the recipient, one for the * text of the letter. Create a 4th instance variable of type int * representing the number of lines in the text of the letter. private String sender; private String recipient; private String text; private int num_lines; Create a constructor method with 2 parameters, each of type String, one to initialize the sender and one to initialize the recipient. Set the text to the emtpy string. Set the number of lines to public Letter (String sender, String receipient) this.sender= sender; this.recipient= recipient; text= null; num_lines= 0; Create a public method addLine(String line) that concatenates the string " " to the instance variable text you created above, then concatenates the given String parameter line to the instance variable text that you created above. Increment the number of lines variable by 1. " public void addLine(String line) line= " "+ text+" num_lines= num_lines+1; Create a public method getText() that returns a String containing "Dear " followed by the recipient name followed by : " followed by the text of the letter followed by " Sincerely, " followed by the sender name public String getText() return "Dear "+this.recipient+ * Create a public method getNumberOfLines() that returns the value of the number of lines instance variable Letter dear John = new Letter("Sally","John"); dear John.addLine("I'm sorry but it's just not going to work out."); dear John.addLine("I'm taking the dog."); dear John.addLine("I'm keeping the ring."); * Expected Output: * Dear John: * I'm sorry but it's just not going to work out. * I'm taking the dog. * I'm keeping the ring. Sincerely, * Sally Letter length 3 lines

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M Ricardo, Susan D Urban

3rd Edition

1284056945, 9781284056945

Students also viewed these Databases questions

Question

Explain the various job analysis methods.

Answered: 1 week ago

Question

In-person Quiz 1b Question 14 of 15 Answered: 1 week ago

Answered: 1 week ago

Question

1. How will you, as city manager, handle these requests?

Answered: 1 week ago

Question

1. Identify the sources for this conflict.

Answered: 1 week ago

Question

3. How would you address the problems that make up the situation?

Answered: 1 week ago