Advertisement
simov

Java 5 [SEDC]

Apr 2nd, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. // Person.java
  2.  
  3. package com.sedc.people;
  4.  
  5. public class Person {
  6.     String name;
  7.     int age;
  8.    
  9.     public Person(String pName, int pAge) {
  10.         this.name = pName;
  11.         this.age = pAge;
  12.     }
  13.     public String identify() {
  14.         return "My name is " + name + ", I'm " + age + " years old. My year of birth is " + getYearOfBirth() + ", I'm " + getAgeGroup() + ".";
  15.     }
  16.     public int getYearOfBirth() {
  17.         return 2014 - this.age;
  18.     }
  19.     public String getAgeGroup() {
  20.         if (this.age <= 12) {
  21.             return "Child";
  22.         }
  23.         else if (this.age <= 19) {
  24.             return "Tenn";
  25.         }
  26.         else if (this.age <= 65) {
  27.             return "Senior";
  28.         }
  29.         else {
  30.             return "Old";
  31.         }
  32.     }
  33. }
  34.  
  35. // PersonsMain.java
  36.  
  37. import com.sedc.people.Person;
  38.  
  39. public class PersonsMain {
  40.  
  41.     public static void main(String[] args) {
  42.         Person blagoja = new Person("Blagoja", 12);
  43.         Person john = new Person("John", 100);
  44.         Person name = new Person("Name", 50);
  45.        
  46.         System.out.println(blagoja.identify());
  47.         System.out.println(john.identify());
  48.         System.out.println(name.identify());
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement