Advertisement
therrontelford

Cat class

Mar 6th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. public class Cat {
  2.  
  3. // instance variables… These are used and visible throughout the class.  They are the backbone of our class.
  4.  
  5.     private int age;
  6.     private String color;
  7.     private String name;
  8.  
  9.  
  10. // constructors…  The construction crew…. how to build the perfect cat
  11.  
  12. // default Cat
  13. public Cat() {     
  14.    
  15. }
  16.  
  17. // a better Cat
  18. public Cat ( int age, String name, String color ) {  
  19.     this.age = age;        
  20.     this.name = name;              
  21.     this.color = color;            
  22.  
  23. }
  24.  
  25. // methods…  the things our cat does and the place where changes can be made to our cat or information retrieved
  26.  
  27. public int getAge() {      
  28.     return age;  
  29. }
  30.  
  31. public String getName() {  
  32.     return name;
  33. }
  34.  
  35. // Now you make a get color method…
  36. public String getColor(String color) {
  37.     return color;
  38. }
  39.  
  40. public void setAge(int age) {  
  41.                
  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. // Now how about those other behaviors…
  54.  
  55. public void eat() {        
  56.     System.out.println("Chew, chew, chew" ) ;
  57.  
  58. }
  59. public void drink() {      
  60.     System.out.println("Drink, drink, drink" );
  61. }
  62.  
  63. public void talk() {
  64.     System.out.println("Meow");
  65. }
  66.  
  67. public void sleep() {
  68.     System.out.println("Zzzzzzzzzzzzzzzz");
  69. }
  70.  
  71. public void happyBirthday() {
  72.     this.age++;
  73.     System.out.println("Happy Birthday, " + this.name);
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement