Advertisement
wingman007

Java2014_PersonNested

Dec 15th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package animals;
  8.  
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. /**
  13.  *
  14.  * @author fmi
  15.  */
  16. public class Person {
  17.     private int age;
  18.     private String name;
  19.     private String sex = "mial";
  20.     private HumanBrain brain= new HumanBrain(1400);
  21.     // Ctr + Shift + I
  22.     private ArrayList<HumanBrain> brains = new ArrayList<HumanBrain>();
  23.    
  24.     public Person(int age, String name) {
  25.         this.age = age;
  26.         this.name = name;
  27.     }
  28.  
  29.     public int getAge() {
  30.         return age;
  31.     }
  32.  
  33.     public String getName() {
  34.         return name;
  35.     }
  36.  
  37.     public void setAge(int age) {
  38.         this.age = age;
  39.     }
  40.  
  41.     public void setName(String name) {
  42.         this.name = name;
  43.     }
  44.    
  45.     // inner class. Doesn't have static modifier
  46.     private class HumanBrain{
  47.         private double weight;
  48.         private String sex = "femail";
  49.        
  50.         public HumanBrain(double weight) {
  51.             this.weight = weight;
  52.         }
  53.        
  54.         public String makeDecision() {          
  55.             if (weight > 1400) return "I am smart " + name + sex;
  56.             else return "Dumm" + name + Person.this.sex;
  57.         }
  58.     }
  59.    
  60.    
  61.     public void introduceYourSelf() {
  62.         System.out.println("I am a person. I am " + age + " old. My name is " + name + "My brain tells me that I am " + brain.makeDecision());
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement