Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/practices/practice_11/task/task_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package practices.practice_11.task;

public class task_1 {

public static void main(String[] args) {
Penguin penguin = new Penguin(PenguinType.EMPEROR);
penguin.printInfo();
}
}

//Перечисление enum
enum PenguinType {

EMPEROR(120, "Антарктида"),
KING(100, "Южные острова"),
ADELIE(70, "Антарктическое побережье");

//Поля перечисления
private final int heightCm;
private final String habitat;

//Конструктор
PenguinType(int heightCm, String habitat) {
this.heightCm = heightCm;
this.habitat = habitat;
}

public int getHeightCm() {
return heightCm;
}

public String getHabitat() {
return habitat;
}
}

//Класс c enum
class Penguin {

private final PenguinType type;

public Penguin(PenguinType type) {
this.type = type;
}

public void printInfo() {
System.out.println(
"Тип пингвина: " + type +
", рост: " + type.getHeightCm() + " см" +
", среда обитания: " + type.getHabitat()
);
}
}
33 changes: 33 additions & 0 deletions src/practices/practice_11/task/task_2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package practices.practice_11.task;

//Перечисление enum
enum PenguinActivity {

SLEEPING(false),
WALKING(true),
SWIMMING(true);


private final boolean active;

//Конструктор перечисления
PenguinActivity(boolean active) {
this.active = active;
}

//Доп метод
public boolean isActive() {
return active;
}
}

public class task_2 {

public static void main(String[] args) {

PenguinActivity activity = PenguinActivity.SWIMMING;

System.out.println("Активность: " + activity);
System.out.println("Активен ли пингвин: " + activity.isActive());
}
}