10.8k views
4 votes
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;

}

}
(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.

User KotAPI
by
8.5k points

1 Answer

2 votes

Final answer:

The correct answer is option C. To solve this problem, you need to implement a method in the Invitation class that takes in the name of a person as a parameter and returns a string consisting of the person's name, the host's name, and the event location.

Step-by-step explanation:

The correct answer is option C.

To solve this problem, you need to implement a method in the Invitation class that takes in the name of a person as a parameter and returns a string consisting of the person's name, the host's name, and the event location.

public String invitePerson(String name) {
return name + " is invited by " + hostName + " to the event at " + address;}

In this method, you concatenate the input name, hostName, and address using the '+' operator to form the desired string.

For example, if the hostName is "John", the address is "123 Main St", and the input name is "Alice", the method will return "Alice is invited by John to the event at 123 Main St".

User Ian Vaughan
by
7.8k points