Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Animalia {
- // private instance variables, the basis of encapsulation, (hiding our data)
- private String food;
- private int hunger; // 0 being not at all and 10 being ravenous
- private int xBoundary;
- private int yBoundary;
- /* {
- constructors would go here but do we really want them?
- } */
- // methods below
- public int getX(){
- return xBoundary;
- }
- public int getY(){
- return yBoundary;
- }
- public void setFood(String f){
- food = f;
- }
- public void setHunger(int h){
- hunger = h;
- }
- public int getHunger() {
- return hunger;
- }
- public String getFood() {
- return food;
- }
- public void setLocation(int x, int y) {
- xBoundary = x;
- yBoundary = y;
- }
- public String getLocation(){
- return "( "+ xBoundary + ", "+ yBoundary+ " )";
- }
- public void roam(){
- System.out.println("walking about");
- }
- public void eat(){
- System.out.println("eating");
- }
- public void sleep(){
- System.out.println("do not disturb");
- }
- public void makeNoise(){
- System.out.println("make sounds");
- }
- public String toString() {
- return "the instance variables are food as a String, hunger, x, and y boundaries as ints";
- }
- // we could put a toString method here
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement