Last active
October 12, 2018 00:40
-
-
Save harrisonmalone/227a998e37955098fa1d50d4dbf164ea to your computer and use it in GitHub Desktop.
java class that uses a constructor but also sets instance variables to an instance later on, content taken from the a ruby challenge
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 Dog { | |
public static int walks = 0; | |
public String location = null; | |
public Dog(String name, int age) { | |
name = name; | |
age = age; | |
} | |
public void bark() { | |
String bark = "woof"; | |
System.out.println(bark); | |
} | |
public Dog walk() { | |
walks ++; | |
return this; | |
} | |
public void setLocation(String location) { | |
this.location = location; | |
} | |
public void display_walks() { | |
System.out.println("I have been for " + walks + " walks"); | |
} | |
public void display_walks_and_location() { | |
System.out.println("I have been for " + walks + " walks in " + location); | |
} | |
public static void main(String s[]) { | |
Dog tilly = new Dog("tilly", 3); | |
tilly.bark(); | |
tilly.walk().walk().display_walks(); | |
tilly.setLocation("brighton"); | |
tilly.display_walks_and_location(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment