-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimal.java
More file actions
158 lines (117 loc) · 2.7 KB
/
Copy pathAnimal.java
File metadata and controls
158 lines (117 loc) · 2.7 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
public class Animal {
public static void main(String[] args) {
String name = "Arcs";
float weight = (float)8.5565;
String nameSlave = "SKKU";
Cat cat = new Cat(name, weight, nameSlave);
cat.getName();
cat.setName("Arcs2");
cat.getName();
cat.getWeight();
cat.setWeight((float)8.556);
cat.getWeight();
cat.getNameSlave();
cat.setNameSlave("SNU");
cat.getNameSlave();
cat.bark();
cat.getFood();
}
}
abstract class Mammal extends Animal{
public abstract void bark();
public abstract void getFood();
}
abstract class Reptile extends Animal{
public abstract void getFood();
}
final class Cat extends Mammal{
private String name;
private float weight;
private String nameSlave;
Cat(String name,float weight,String nameSlave){
this.name=name;
this.weight=weight;
this.nameSlave=nameSlave;
}
public void getName(){
System.out.println("Name: " + name);
}
public void setName(String new_name){
this.name = new_name;
}
public void getWeight(){
System.out.println("Weight: " + weight);
}
public void setWeight(float new_weight){
this.weight = new_weight;
}
public void getNameSlave(){
System.out.println("NameSlave: " + nameSlave);
}
public void setNameSlave(String new_nameSlave){
this.nameSlave = new_nameSlave;
}
public void bark() {
System.out.println("Meow");
}
public void getFood() {
System.out.println("Fish");
}
}
final class Dog extends Mammal{
private String name;
private float weight;
private String nameMaster;
Dog(String name,float weight,String nameMaster){
this.name=name;
this.weight=weight;
this.nameMaster=nameMaster;
}
public void getName(){
System.out.println("Name: " + name);
}
public void setName(String new_name){
this.name = new_name;
}
public void getWeight(){
System.out.println("Weight: " + weight);
}
public void setWeight(float new_weight){
this.weight = new_weight;
}
public void getNameMaster(){
System.out.println("NameMaster: " + nameMaster);
}
public void setNameMaster(String new_nameMaster){
this.nameMaster = new_nameMaster;
}
public void bark() {
System.out.println("Bowbow");
}
public void getFood() {
System.out.println("Apple");
}
}
final class Crocodile extends Reptile{
private String name;
private float weight;
Crocodile(String name,float weight){
this.name=name;
this.weight=weight;
}
public void getName(){
System.out.println("Name: " + name);
}
public void setName(String new_name){
this.name = new_name;
}
public void getWeight(){
System.out.println("Weight: " + weight);
}
public void setWeight(float new_weight){
this.weight = new_weight;
}
public void getFood() {
System.out.println("Meat");
}
}