In: Computer Science
Develop a java program with a class named friend with data members like name, phno and hobby. Use Parameterized constructor to create two friend objects and invoke checkhobby method which takes only one parameter, to find whether they have same hobby or different hobbies
class Friend{
private String name;
private String phoneNo;
private String hobby;
public Friend(String aName, String aPhoneNo, String
aHobby) {
super();
name = aName;
phoneNo = aPhoneNo;
hobby = aHobby;
}
public String getName() {
return name;
}
public String getPhoneNo() {
return phoneNo;
}
public String getHobby() {
return hobby;
}
public void setName(String aName) {
name = aName;
}
public void setPhoneNo(String aPhoneNo) {
phoneNo = aPhoneNo;
}
public void setHobby(String aHobby) {
hobby = aHobby;
}
public boolean haveSameHobby(Friend f) {
return
f.getHobby().equals(getHobby());
}
}
public class DriverFriend {
public static void main(String[] args) {
Friend f1 = new Friend("Uday",
"12312", "Cricket");
Friend f2 = new Friend("Keerthi",
"12312", "Chess");
System.out.println("has same hobby?
"+f1.haveSameHobby(f2));
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME