Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Cat {
- // instance variables… These are used and visible throughout the class.
- //They are the backbone of our class.
- int age;
- String color;
- String name;
- boolean isHappy;
- // constructors… The construction crew…. how to build the perfect cat
- public Cat() {
- }
- public Cat ( int age, String name, String color, boolean isHappy ) {
- this.age = age;
- this.name = name;
- this.color = color;
- this.isHappy= isHappy;
- }
- // methods… the things our cat does and the place
- //where changes can be made to our cat or information retrieved
- public int getAge() {
- return age;
- }
- public String getName() {
- return name;
- }
- public String getColor() {
- return color;
- }
- // Now you make a get color method…
- public void setAge(int age) {
- this.age = age;
- }
- public void setName(String name) {
- this.name = name;
- }
- public void setColor(String color) {
- this.color = color;
- }
- public void setIsHappy(boolean isHappy) {
- this.isHappy = isHappy;
- }
- // Now how about those other behaviors…
- public void eat(int num) {
- for (int i=0; i< num; i++)
- System.out.println(" Chew, chew, chew ") ;
- }
- public void drink() {
- System.out.println("Drink, drink, drink" );
- }
- public void talk() {
- if (isHappy)
- System.out.println("Meow");
- else
- System.out.println("RAAWWRRR");
- }
- public void sleep() {
- System.out.println("Zzzzzzzzz");
- }
- public void happyBirthday() {
- this.age++;
- System.out.println("Happy Birthday "+ this.name);
- System.out.println(this.age);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement