Created
March 23, 2014 17:00
-
-
Save edolopez/9726086 to your computer and use it in GitHub Desktop.
Puppy class and PuppyTest (with the main method), an example of Objects
This file contains hidden or 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
| public class Puppy { | |
| // Instance Variables | |
| int age; | |
| String color; | |
| String breed; | |
| double weight; | |
| String name; | |
| public Puppy() { | |
| name = "Default"; | |
| weight = 20.0; | |
| age = 0; | |
| color = "Red"; | |
| } | |
| public Puppy(int puppyAge, String puppyBreed, String puppyName) { | |
| name = puppyName; | |
| age = puppyAge; | |
| breed = puppyBreed; | |
| } | |
| public int getAge() { | |
| return age; | |
| } | |
| public void setAge(int puppyAge) { | |
| age = puppyAge; | |
| } | |
| public String getColor() { | |
| return color; | |
| } | |
| public void setColor(String puppyColor) { | |
| color = puppyColor; | |
| } | |
| public void bark() { | |
| System.out.println("GUAF, such code"); | |
| } | |
| } |
This file contains hidden or 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
| // http://www.tutorialspoint.com/java/java_object_classes.htm | |
| import java.util.Scanner; | |
| public class PuppyTest { | |
| public static void main(String [] args) { | |
| Scanner input = new Scanner(System.in); | |
| Puppy dog = new Puppy(); | |
| dog.bark(); | |
| System.out.println(dog.getColor()); | |
| Puppy doge = new Puppy(2, "shiba", "Charles"); | |
| doge.setColor("Yellow"); | |
| System.out.println(doge.getColor()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment