Question
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
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 notnulland 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 variablehostNamerepresents the name of the host of the event and the variableaddressrepresents 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 theInvitationclass that returns the name of the host.
(b)Write a method for theInvitationclass that accepts a parameter and uses it to update the address for the event.
(c)Write a method for theInvitationclass 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.
Your implementation must conform to the example above.
(d)A student has written the following one-parameter constructor to be included in theInvitationclass. The method is intended to construct a newInvitationobject that setsaddressto the value of the parameter and setshostNameto 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-parameterInvitationconstructor that avoids the error in the student's implementation.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started