Advertisement
therrontelford

Animalia 2019

Jan 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. public class Animalia {
  2.     // private instance variables, the basis of encapsulation, (hiding our data)
  3.     private String food;
  4.     private int hunger;  // 0 being not at all and 10 being ravenous
  5.     private int xBoundary;
  6.     private int yBoundary;
  7.    
  8.     /* {
  9.      constructors would go here but do we really want them?
  10.     }  */
  11.    
  12.     // methods below
  13.     public int getX(){
  14.         return xBoundary;
  15.     }
  16.  
  17.     public int getY(){
  18.         return yBoundary;
  19.     }
  20.    
  21.     public void setFood(String f){
  22.         food = f;
  23.     }
  24.     public void setHunger(int h){
  25.         hunger = h;
  26.     }
  27.    
  28.     public int getHunger() {
  29.         return hunger;
  30.     }
  31.    
  32.     public String getFood() {
  33.         return food;
  34.     }
  35.    
  36.     public void setLocation(int x, int y) {
  37.         xBoundary = x;
  38.         yBoundary = y;
  39.     }
  40.     public String getLocation(){
  41.         return "( "+ xBoundary + ", "+ yBoundary+ " )";
  42.     }
  43.     public void roam(){
  44.         System.out.println("walking about");
  45.     }
  46.     public void eat(){
  47.         System.out.println("eating");
  48.     }
  49.     public void sleep(){
  50.         System.out.println("do not disturb");
  51.     }
  52.     public void makeNoise(){
  53.         System.out.println("make sounds");
  54.     }
  55.    
  56.     public String toString() {
  57.         return "the instance variables are food as a String, hunger, x, and y boundaries as ints";
  58.     }
  59.     // we could put a toString method here
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement