Class Person has instance data members (all private) String fullName, char gender, int age. has a public static int variable named numFriends with an initial value of zero. has a constructor that will be used to make a Person object and assign values to its data members, and increment numFriends. has getters and setters for all three instance data members. has a toString() method that returns a string displaying the state of a Person instance.
public class Person {
private String fullName;
private char gender;
private int age;
private static int numFriends = 0;
Person(String fullName, char gender, int age){
this.setFullName(fullName);
this.setGender(gender);
this.setAge(age);
setNumFriends(getNumFriends() + 1);
}
public static int getNumFriends() {
return numFriends;
}
public static void setNumFriends(int numFriends) {
Person.numFriends = numFriends;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public char getGender() {
return gender;
}
public void setGender(char gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String toString(){
return "" + fullName + "\t" + gender + "\t" + age + "\t" + numFriends;
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF