-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnake.java
53 lines (43 loc) · 1.21 KB
/
Snake.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.artyom.khvediouk.Model;
public class Snake extends Reptile{
private int length;
public Snake(String name, int age, Color color, int length) {
super(name, age, color, 0);
this.length = length;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
@Override
public void eat() {
System.out.println(" I am snake , I eat rats");
}
@Override
public void sleep() {
System.out.println(" I am snake , I never sleep");
}
@Override
public String toString() {
return "I am a snake , my name is : " + super.getName() + " my age is : " + super.getAge() + "\n" +
"my color is : " + super.getColor() + " my length is " + length + " meters";
}
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o == this) {
return true;
}
if (o instanceof Snake) {
Snake other = (Snake) o;
if (super.equals(other) && this.getLength() == other.getLength()) {
return true;
}
}
return false;
}
}