From f4edc9ca6187283b4a381c707e5314ebf4ec3203 Mon Sep 17 00:00:00 2001 From: NikitaDr Date: Sat, 22 Nov 2025 21:44:06 +0400 Subject: [PATCH] push --- src/main/java/Application.java | 23 ++++ src/main/java/animals/Kotik.java | 179 +++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 src/main/java/Application.java create mode 100644 src/main/java/animals/Kotik.java diff --git a/src/main/java/Application.java b/src/main/java/Application.java new file mode 100644 index 0000000..b2cdf33 --- /dev/null +++ b/src/main/java/Application.java @@ -0,0 +1,23 @@ +import animals.Kotik; + +public class Application { + public static void main(String[] args) { + Kotik firstKot = new Kotik("Petr", "hi", 10, 5); + Kotik secondKot = new Kotik(); + secondKot.setName("Barsik"); + secondKot.setVoice("hello"); + secondKot.setSatiety(5); + secondKot.setWeight(3); + for(String str : firstKot.liveAnotherDay()){ + System.out.println(str); + } + System.out.println(secondKot.getName()); + System.out.println(secondKot.getWeight()); + System.out.println(Application.compareVoice(firstKot, secondKot)); + System.out.println(Kotik.getCount()); + } + + public static boolean compareVoice(Kotik firstKot, Kotik secondKot){ + return firstKot.getVoice().equals(secondKot.getVoice()); + } +} \ No newline at end of file diff --git a/src/main/java/animals/Kotik.java b/src/main/java/animals/Kotik.java new file mode 100644 index 0000000..3be400a --- /dev/null +++ b/src/main/java/animals/Kotik.java @@ -0,0 +1,179 @@ +package animals; + +import java.util.ArrayList; + +public class Kotik { + + private static final int METHODS = 5; + + private static int count = 0; + + private String name; + private String voice; + private int satiety; + private int weight; + + public Kotik(String name, String voice, int satiety, int weight) { + this.name = name; + this.voice = voice; + this.satiety = satiety; + this.weight = weight; + count++; + } + + public Kotik() { + count++; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVoice() { + return voice; + } + + public void setVoice(String voice) { + this.voice = voice; + } + + public int getSatiety() { + return satiety; + } + + public void setSatiety(int satiety) { + this.satiety = satiety; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public static int getCount() { + return count; + } + + public void eat(int units) { + System.out.println("Kotik is eating"); + this.satiety += units; + } + + public void eat(int units, String food) { + System.out.println("Kotik is eating " + food); + this.satiety += units; + } + + public void eat() { + eat(2, "fish"); + } + + public boolean play() { + if (satiety > 0) { + System.out.println("Kotik is playing"); + satiety--; + return true; + } else { + System.out.println("kotik wanna eat"); + eat(); + return false; + } + } + + public boolean sleep() { + if (satiety > 0) { + System.out.println("Kotik is sleeping"); + satiety--; + return true; + } else { + System.out.println("kotik wanna eat"); + eat(); + return false; + } + } + + public boolean wash() { + if (satiety > 0) { + System.out.println("Kotik is washing"); + satiety--; + return true; + } else { + System.out.println("kotik wanna eat"); + eat(); + return false; + } + } + + public boolean walk() { + if (satiety > 0) { + System.out.println("Kotik is walking"); + satiety--; + return true; + } else { + System.out.println("kotik wanna eat"); + eat(); + return false; + } + } + + public boolean hunt() { + if (satiety > 0) { + System.out.println("Kotik is hunting"); + satiety--; + return true; + } else { + System.out.println("kotik wanna eat"); + eat(); + return false; + } + } + + public ArrayList liveAnotherDay() { + ArrayList kotikToDoList = new ArrayList<>(); + for (int i = 0; i < 24; i++) { + switch ((int) (Math.random() * METHODS) + 1) { + case (1): + if (play()) + kotikToDoList.add(i + " - play"); + else + kotikToDoList.add(i + " - eat"); + break; + case (2): + if (sleep()) + kotikToDoList.add(i + " - sleep"); + else + kotikToDoList.add(i + " - eat"); + break; + case (3): + if (wash()) + kotikToDoList.add(i + " - wash"); + else + kotikToDoList.add(i + " - eat"); + break; + case (4): + if (walk()) + kotikToDoList.add(i + " - walk"); + else + kotikToDoList.add(i + " - eat"); + break; + case (5): + if (hunt()) + kotikToDoList.add(i + " - hunt"); + else + kotikToDoList.add(i + " - eat"); + break; + default: + System.out.println("something wrong"); + break; + } + } + return kotikToDoList; + } +}