
please could you help me with my assignment I have to submit it on Monday 29 October please help me :(
Write a program to test the Person class defined below. Your test program should create
two instances of the class (each to test a different constructor) and test each of the
methods. You are also required to illustrate the error in trying to access private data
members from the client class (for clarity temporarily change the private modifier to public
and test again).
class Person {
// Data Members
private String name; // The name of this person
private int age; // The age of this person
private char gender; // The gender of this person
// Default constructor
public Person() {
this("Not Given", 0, 'U');
}
// Constructs a new Person with passed name, age, and gender.
// example of explicit use of ââ?¬Å?thisââ?¬Â? (only for illustration)
public Person(String name, int age, char gender) {
this.age = age;
this.name = name;
this.gender = gender;
}
// Returns the age of this person.
public int getAge( ) {
return age;
}
// Returns the gender of this person.
public char getGender( ) {
return gender;
}
// Returns the name of this person.
public String getName( ) {
return name;
}
// Sets the age of this person.
public void setAge( int age ) {
this.age = age;
}
// Sets the gender of this person.
public void setGender( char gender ) {
this.gender = gender;
}
// Sets the name of this person.
public void setName( String name ) {
this.name = name;
}
} // end class
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.