209k views
15 votes
Write a method for the Invitation class that accepts a parameter and uses it to update the address for the event.

User Comonad
by
7.3k points

1 Answer

6 votes

Answer:

public class Invitation {

private String hostname;

private String address;

public Invitation(String n, String a) { // constructor that accepts two strings.

hostname = n;

address = a;

}

public String getHostname() {

return hostname;

}

public void setAddress(String a) {

address = a;

}

public String invite(String guest) {

return "Hello" +guest+ ", you are invited to my party at " +address+". "+hostname+".";

}

public Invitation(String host, String address) {

this.address = address;

this.hostname = host;

}

}

Step-by-step explanation:

The Java program defines a class called "Invitation". The class constructor has two string arguments or parameters for the host of the event and the address. The invite method is used to generate the string invite message with the name of the guest as the argument. Use the "setAddress" method to set a new location of the event and the "getHostname" to get the name of the event host.

User Istvan Szasz
by
6.3k points