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;
}
}
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.
Answer:
total = 0
for i in range(4):
bill = float(input("Enter bill for quarter " + str(i+1) + ": "))
total += bill
average = total / (4 * 3)
if average > 75:
print("Average monthly bill is $" + str(average) + ". Too much water is being used")
if 25 <= average < 75:
print("Average monthly bill is $" + str(average) + ". A typical amount of water is being used")
if average < 25:
print("Average monthly bill is $" + str(average) + ". Thank you for conserving water")
Explanation:
*The code is in Python.
Create a for loop that asks the user to enter the bill for 4 quarters and calculate the total of the bills
Calculate the average monthly bill, divide the total by 12
Check the average for the given conditions. Depending on its value print the required message along with the average monthly bill
Answer:
The output is attached below
Explanation:
d = {}
while True:
line = input("Enter line: ")
if len(line)==0:
break
token = line.split(' ')
for var in token:
try:
if len(var)==0:
continue
count = d[var]
d[var] = count + 1
except KeyError:
d[var] = 1
pass
for word in sorted(d):
print(word , d[word])
------------------
function is the right answer because function is a block of code designed to perform a particular task