62 558
Assignments Done
98,8%
Successfully Done
In June 2018

Answer to Question #62192 in Java | JSP | JSF for Bill DeShields

Question #62192
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.
Expert's answer
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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions