Created
January 25, 2021 23:11
-
-
Save Dean110/0f2a563aa3e23f809f6fdfe1cb43db70 to your computer and use it in GitHub Desktop.
Class demonstration from lecture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.wecancodeit; | |
public class Cat { | |
private String name; | |
private String furColor; | |
private int age; | |
private int lives; | |
public Cat(String name, String furColor, int age, int lives) { | |
this.name = name; | |
this.furColor = furColor; | |
this.age = age; | |
this.lives = lives; | |
} | |
public void greeting() { | |
System.out.println("My name is " + name + "! I have " | |
+ furColor + " fur." + | |
"I'm " + age + " years old, and I have " | |
+ lives + " lives left!"); | |
} | |
public String getName(){ | |
return name; | |
} | |
public String getFurColor() { | |
return furColor; | |
} | |
public int getAge() { | |
return age; | |
} | |
public int getLives() { | |
return lives; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.wecancodeit; | |
public class Main { | |
static Cat annoying = new Cat("Annoying", "blue", 4, 9); | |
static Cat furBall = new Cat("Furry", "gray", 3, 3); | |
public static void main(String[] args) { | |
System.out.println("Tell us about yourself."); | |
annoying.greeting(); | |
furBall.greeting(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment