LetterTester.java public class LetterTester { public static void main(String[] args) { Letter dearJohn = new Letter(Sally,John); dearJohn.addLine(I'm
Question:
LetterTester.java
public class LetterTester
{
public static void main(String[] args)
{
Letter dearJohn = new Letter("Sally","John");
dearJohn.addLine("I'm sorry but it's just not going to work out.");
dearJohn.addLine("I'm taking the dog.");
dearJohn.addLine("I'm keeping the ring.");
System.out.println(dearJohn.getText());
System.out.println("Letter length " + dearJohn.getNumberOfLines() + " lines");
System.out.println("Expected: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");
System.out.println("Letter length 3 lines");
dearJohn.removeLine(2);
System.out.println(dearJohn.getText());
System.out.println("Letter length " + dearJohn.getNumberOfLines() + " lines");
System.out.println("Expected:Dear John:I'm sorry but it's just not going to work out.I'm keeping the ring.Sincerely,Sally");
System.out.println("Letter length 2 lines");
dearJohn.removeLine(2);
System.out.println(dearJohn.getText());
System.out.println("Letter length " + dearJohn.getNumberOfLines() + " lines");
System.out.println("Expected:Dear John:I'm sorry but it's just not going to work out.Sincerely,Sally");
System.out.println("Letter length 1 lines");
}
}
Letter.java
import java.util.ArrayList;
public class Letter
{
String sender, recipient;
ArrayList lines;// The actual contents of the letter, each line stored individually
int numLines; // number of lines in the letter
/**
Create a constructor method with 2 parameters, each of type String, one to initialize the
sender and one to initialize the recipient.
initialize lines to a new array list, initially empty
*/
//-----------Start below here. To do: approximate lines of code = 4
//
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
/**
Create a public method void addLine(String line) that adds a new line to the letter.
i.e. adds the new line to the array list
*/
//-----------Start below here. To do: approximate lines of code = 2
//
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
/**
Create a public method String 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. Add a "" to the end of each line in array list lines
*/
//-----------Start below here. To do: approximate lines of code = 7
//
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
/**
* Create a public method getNumberOfLines() that returns the number of lines that were explicitly added to the letter
* using the addLines() method
*/
//-----------Start below here. To do: approximate lines of code = 2
//
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
// Create a public method void removeLine(int index) that removes a line from the array list at location index.
// Make sure to subtract 1 from the parameter variable index before removing the line from arrayList lines.
// Make sure that index-1 is in the range 0 to lines.size()-1
// If it is not in this range, do nothing.
//-----------Start below here. To do: approximate lines of code = 3
//
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
P.S: Please include screenshots of output so it is confirmed all works well and fine. Thank you :)
Accounting for Governmental and Nonprofit Entities
ISBN: ?978-0073379609
15th Edition
Authors: Earl R. Wilson, Jacqueline L Reck, Susan C Kattelus