Advertisement
therrontelford

Cat class slightly more interesting

Mar 7th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1. public class Cat {
  2.  
  3. // instance variables… These are used and visible throughout the class.  
  4. //They are the backbone of our class.
  5. int age;
  6. String color;
  7. String name;
  8. boolean isHappy;
  9.  
  10.  
  11. // constructors…  The construction crew…. how to build the perfect cat
  12.  
  13. public Cat() {       
  14.    
  15. }
  16.  
  17. public Cat ( int age, String name, String color, boolean isHappy ) {  
  18.     this.age = age;            
  19.     this.name = name;              
  20.     this.color = color;
  21.     this.isHappy= isHappy;
  22.  
  23. }
  24.  
  25. // methods…  the things our cat does and the place
  26. //where changes can be made to our cat or information retrieved
  27.  
  28. public int getAge() {        
  29.     return age;  
  30. }
  31.  
  32. public String getName() {  
  33.     return name;
  34. }
  35.  
  36. public String getColor() {
  37.     return color;
  38. }
  39. // Now you make a get color method…
  40.  
  41. public void setAge(int age) {  
  42. this.age = age;    
  43. }
  44.  
  45. public void setName(String name) { 
  46.     this.name = name;          
  47. }
  48.  
  49. public void setColor(String color) {
  50.     this.color = color;
  51. }
  52.  
  53. public void setIsHappy(boolean isHappy) {
  54.     this.isHappy = isHappy;
  55. }
  56. // Now how about those other behaviors…
  57.  
  58. public void eat(int num) {
  59.     for (int i=0; i< num; i++)
  60.     System.out.println(" Chew, chew, chew ") ;
  61.  
  62. }
  63.  
  64. public void drink() {            
  65.     System.out.println("Drink, drink, drink" );
  66. }
  67.  
  68. public void talk() {
  69.     if (isHappy)
  70.         System.out.println("Meow");
  71.     else
  72.         System.out.println("RAAWWRRR");
  73. }
  74.  
  75. public void sleep() {
  76.     System.out.println("Zzzzzzzzz");
  77. }
  78. public void happyBirthday() {
  79.     this.age++;
  80.     System.out.println("Happy Birthday "+ this.name);
  81.     System.out.println(this.age);
  82. }
  83.  
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement