{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Person - Person.java p public class Person cfw Declare the...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************* // Person.java // // //******************************************************* public class Person { p // Declare the instance variables public static int people = 0; public static int sumOfAges = 0; public static int minAge = 120; public static int maxAge = 0; p private int age; private String name; p public static int avgAge(){ return sumOfAges / people; } public static int minAge(){ return minAge; } public static int maxAge(){ return maxAge; } //---------------------------------------------- // Class Constructor: set the initial values of // the instance variables // for this Person //---------------------------------------------- / public Person(String name, int age) { this.name = name; this.age = age; if( age > maxAge ) maxAge = age; if( age < minAge ) minAge = age; people++; sumOfAges += age; } } //---------------------------------------------- // getAge - returns the age of this Person //---------------------------------------------- public int getAge() { return this.age; } //---------------------------------------------- // getName - returns the name of this Person //---------------------------------------------- public String getName() { return this.name; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
} //---------------------------------------------- // setAge- assigns a new valid age to this Person //---------------------------------------------- public void setAge(int age) { p if( age > 0 && age < 120){ this.age = age; if( age > maxAge ) maxAge = age; if( age < minAge ) minAge = age; sumOfAges -= this.age; sumOfAges += age; } } //---------------------------------------------- // setName - assigns a new name to this Person //---------------------------------------------- public void setName(String name) { if( name != null && !name.equals("")) this.name = name;
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}