Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

question: I am having trouble understanding this problem. any resources? Descrpition The project name of this exercise is Letter. The purpose of this assignment is

question: I am having trouble understanding this problem. any resources?
Descrpition
The project name of this exercise is Letter.
The purpose of this assignment is to give you some practice problem solving, writing your own classes, and running unit tests.
Problem Description
Provide a class for authoring a simple letter. You need the following constructor:
public Letter(String from, String to) - The constructor sets the name of the sender and the recipient.
You will also need the following two methods:
public void addLine(String line) - add a line of text to the body of the letter.
public String getText() - that returns the entire text of the letter. The text should have the form:
Dear recipient name:
blank line
first line of the body
second line of the body
...
last line of the body
blank line
Sincerely,
blank line
sender name
You do not need any more methods in your Letter.java (don't add other ones). In your Program.java you'll write code that calls the methods in Letter.java. These methods will be called to print the following letter.
Dear Person:
I am sorry we must part.
I wish you all the best.
Sincerely,
Another Person
Hints:
1. Use the concat method to combine strings.
2. The special string " " represents a new line. For example, the statement
body = body.concat("Sincerely,").concat(" ");
adds a line containing the string "Sincerely," to the string body. Notice that you can use the concat method multiple times to keep concatenating.
Getting Started
Like our last exercise, we are going to do this exercise by writing the object that solves the problem first (in a source file called Letter.java) and then testing it using code we write into Program.java. Using the techniques shown on the web page titled "How to Start Every Project in this Class" create a source file called Letter.java as well as a file called Program.java.
Open up the Letter.java file and replace the code with the code contained in the box below:
package edu.sbcc.cs105;
/**
* This class creates letters in an automated fashion.
*
*/
public class Letter {
/**
* Constructor that sets the letter writer and recipient.
*
* @param from
* Person who is writing the letter.
* @param to
* Person to whom the letter is addressed.
*/
public Letter(String from, String to) {
}
/**
* Add a line of text to the body of the letter.
*
* @param line
*/
public void addLine(String line) {
}
/**
* Creates a letter using the designated sender and recipient. The format of
* the letter is:
*
* Dear recipient name: blank line first line of the body second line of the
* body ... last line of the body blank line Sincerely, blank line sender
* name
*
* @return the formatted letter.
*/
public String getText() {
}
}
You'll notice that there is only a skeleton of code. It current doesn't do anything -You will have to add instance variables and code to get this class defined properly. Read the comments (and the problem) to understand what the problem is and how you will solve it.
Program class is where your test code will go. Replace the code in that file with the code in the grey box below:
package edu.sbcc.cs105;
/**
* This class tests the Letter object.
*
*/
public class Program {
/**
* Test this code by creating a letter in the form shown in the problem
* description.
*
* @param args
* command line values. Not used in this example.
*/
public static void main(String[] args) {
}
}
You will also notice that Program.java does not contain any code to test the Letter.java source code. Write some test routines based upon the problem description.
You should only need to construct an object of the Letter class and call addLine twice.
You will know if your class is implemented correctly if the print out of your letter looks like the letter above.
Once you've written your code run the code by single clicking on Program.java in the package explorer and selecting Run->Run from the menu or using the keyboard shortcut. Examine the output. Does it do what you want? Does it look like the letter above? If not, how can you modify the code to do what you want?

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

Step: 3

blur-text-image

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

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions