103k views
1 vote
SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA.

Assume that the classes listed in the Java Quick Reference have been imported where appropriate.
Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied.
In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.
The following class represents an invitation to an event. The variable hostName represents the name of the host of the event and the variable address represents the location of the event.

public class Invitation

{

private String hostName;

private String address;

public Invitation(String n, String a)

{

hostName = n;

address = a;

}

}

(a) Write a method for the Invitation class that returns the name of the host.

Write the method below.

(b) Write a method for the Invitation class that accepts a parameter and uses it to update the address for the event.

Write the method below.

(c) Write a method for the Invitation class that will accept the name of a person who will be invited as a string parameter and return a string consisting of the name of the person being invited along with name of the host and location of the event.

For example, if the host name is "Karen", the party location is "1234 Walnut Street", and the person invited is "Cheryl", the method should return a string in the following format.

Dear Cheryl, please attend my event at 1234 Walnut Street. See you

then, Karen.

Write the method below. Your implementation must conform to the example above.

(d) A student has written the following one-parameter constructor to be included in the Invitation class. The method is intended to construct a new Invitation object that sets address to the value of the parameter and sets hostName to the default name "Host". The constructor does not work as intended.

public Invitation(String address)

{

address = address;

hostName = "Host";

}

Write a correct implementation of the one-parameter Invitation constructor that avoids the error in the student’s implementation.

Write the method below.

User Shookit
by
7.3k points

1 Answer

6 votes

Answer:

Public String getHostName()

{

Return hostName;

}

Public String setAddress(String ad)

{

address=ad;

}

Public String invite(String nme)

{

Return “Dear “+nme+“, please attend my event at ”+address+“. See you

then, ”+hostName+ “.”

}

Step-by-step explanation:

User Wubin Ouyang
by
6.4k points