Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Person.java
- package com.sedc.people;
- public class Person {
- String name;
- int age;
- public Person(String pName, int pAge) {
- this.name = pName;
- this.age = pAge;
- }
- public String identify() {
- return "My name is " + name + ", I'm " + age + " years old. My year of birth is " + getYearOfBirth() + ", I'm " + getAgeGroup() + ".";
- }
- public int getYearOfBirth() {
- return 2014 - this.age;
- }
- public String getAgeGroup() {
- if (this.age <= 12) {
- return "Child";
- }
- else if (this.age <= 19) {
- return "Tenn";
- }
- else if (this.age <= 65) {
- return "Senior";
- }
- else {
- return "Old";
- }
- }
- }
- // PersonsMain.java
- import com.sedc.people.Person;
- public class PersonsMain {
- public static void main(String[] args) {
- Person blagoja = new Person("Blagoja", 12);
- Person john = new Person("John", 100);
- Person name = new Person("Name", 50);
- System.out.println(blagoja.identify());
- System.out.println(john.identify());
- System.out.println(name.identify());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement