Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Dog {
- private String name, color, breed;
- private int age, weight;
- // CONSTRUCTOR
- public Dog() {
- this("none entered", "none entered", "none entered",1);
- }
- public Dog(String name, String color, String breed, int age) {
- this.name = name;
- this.color = color;
- this.breed = breed;
- if (age < 1) {
- this.age = 1;
- } else {
- this.age = age;
- }
- }
- public Dog(int weight) {
- this();
- this.weight = weight;
- }
- // Setters
- public void setName(String name) {
- this.name = name;
- }
- public void setColor(String color) {
- this.color = color;
- }
- public void setBreed(String breed) {
- this.breed = breed;
- }
- public void setAge(int age) {
- if (age < 1) {
- this.age = 1;
- } else {
- this.age = age;
- }
- }
- public void setWeight(int weight) {
- if (weight < 1) {
- this.weight = 1;
- } else {
- this.weight = weight;
- }
- }
- // GETTERS
- public String getName() {
- return this.name;
- // or return name;
- }
- public String getColor() {
- return this.color;
- }
- public String getBreed() {
- return this.breed;
- }
- public int getAge() {
- return this.age;
- }
- public int getWeight() {
- return this.weight;
- }
- @Override
- public String toString() {
- return "Dog's name: " + this.name + "\n" +
- "Age: " + this.age + "\n" +
- "Breed: " + this.breed + "\n" +
- "Color: " + this.getColor() + "\n";
- }
- @Override
- public boolean equals(Object other) {
- if (other instanceof Dog) {
- Dog otherDog = (Dog) other;
- return this.name.equalsIgnoreCase(otherDog.name) &&
- this.color.equalsIgnoreCase(otherDog.getColor()) &&
- this.breed.equalsIgnoreCase(otherDog.getBreed()) &&
- this.age == otherDog.getAge();
- } else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement