Created
June 18, 2020 11:41
-
-
Save olegrewko/4df5cd36a46f6debd4c4e90ff8e2d040 to your computer and use it in GitHub Desktop.
Кошки ООП-7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package IgorDolgov.cats; | |
| //class Cat { | |
| // int consumed; // храним кол-во съеденной пищи | |
| // void eatFrom(Plate plate) { | |
| // // int portion = получите из тарелки порцию еды (так чтобы и в тарелке еда тоже уменьшилась) | |
| // // увеличьте consumed на размер этой порции | |
| // System.out.println("Кошка съела из тарелки " + portion); | |
| // System.out.println("Кошка всего съела " + consumed); | |
| // } | |
| //} | |
| // | |
| // | |
| //class Plate { | |
| // int amount = 100; // сколько еды в тарелке осталось | |
| // int portion = 10; // размер порции | |
| // void feed(Cat cat) { | |
| // // уменьшите размер amount на размер порции (сделайте проверку, чтобы было нельзя съесть больше, чем в тарелке осталось) | |
| // // увеличьте у кошки кол-во потребленной ей еды на размер этой порции | |
| // System.out.println("Тарелка покормила кошку на " + portion); | |
| // System.out.println("В тарелке осталось " + amount); | |
| // System.out.println("Кошка всего съела " + cat.consumed); | |
| // } | |
| // int getPortion() { | |
| // // уменьшите размер оставшейся в тарелке еды на размер порции | |
| // // (сделайте проверку, чтобы было нельзя съесть больше, чем в тарелке осталось) | |
| // // (если еды мало – то всю ее и съесть) | |
| // System.out.println("В тарелке осталось " + amount); | |
| // // верните потребленный размер порции с помощью return | |
| // } | |
| //} | |
| // | |
| // | |
| //public static void main(String[] args) { | |
| // Plate plate = new Plate(); // Общая на всех тарелка | |
| // Cat cat = new Cat(); // Кошка | |
| // cat.eatFrom(plate); // кошка кушает из тарелки, которую передали ей в параметрах | |
| // plate.feed(cat); // тарелка "кормит" кошку, которую ей передали в параметры | |
| // } | |
| //-------------------------------------------------------------------------------------------- | |
| class Count { | |
| static int count; | |
| int setCount(int count) { | |
| this.count = count; | |
| return count; | |
| } | |
| public static void main(String[] args) { | |
| count = getNextCount(); | |
| } | |
| static int getNextCount() { | |
| count++; | |
| return count; | |
| } | |
| } | |
| //-------------------------------------------------------------------------------------------- | |
| public class Main { | |
| public static Count count; | |
| public static void main(String[] args) { | |
| count = new Count(); | |
| count.setCount(0); | |
| Cat masha = new Cat("Маша", count); | |
| Cat misha = new Cat("Миша", count); | |
| Cat gala = new Cat("Галя", count); | |
| Cat kate = new Cat("Kate", count); | |
| Cat petr = new Cat("Petr", count); | |
| Cat boris = new Cat("Boris", count); | |
| System.out.println("Маша номер " + masha.id); | |
| System.out.println("Миша номер " + misha.id); | |
| System.out.println("Галя номер " + gala.id); | |
| System.out.println("Kate номер " + kate.id); | |
| System.out.println("Petr номер " + petr.id); | |
| System.out.println("Boris номер " + boris.id); | |
| //Создали 6 кошек | |
| Bowl bowl = new Bowl();//Общая на всех чаша | |
| Plate plate = new Plate();// Общая на всех тарелка | |
| Cat cat = new Cat(count); // Кошка абстрактная первая | |
| System.out.println("Создали абстрактную кошку " + cat.id); | |
| Cat cat02 = new Cat("Barsic"); | |
| System.out.println("Нашли еще кота на улице и назвали Барсик его номер стал: " + cat02.id); | |
| int amountCats = cat.showCount(); | |
| System.out.println("Общее кол-во созданных кошек: " + amountCats); | |
| System.out.println("Общее количество сначала воды " + bowl.voda); | |
| System.out.println("Общее количество еды сначала еды " + plate.eda); | |
| Plate.portion = Plate.setPortion(100); | |
| Bowl.portionVoda = Bowl.setPortionVoda(200); | |
| System.out.println("Установленный размер стандартной порции еды " + Plate.portion); | |
| System.out.println("Установленный размер стандартной порции воды " + Bowl.portionVoda); | |
| System.out.println("Чаша будет неизвестно кого поить 3 раза: 500, 400, 500"); | |
| bowl.drink(500); | |
| bowl.drink(400); | |
| bowl.drink(500); | |
| System.out.println(kate.name + " " + boris.name + " " + cat02.name + " Выпьют по 3 стандартные порции (200 * 3 = 600) воды"); | |
| kate.drink(bowl, Bowl.portionVoda); | |
| boris.drink(bowl, Bowl.portionVoda); | |
| cat02.drink(bowl, Bowl.portionVoda); | |
| System.out.println("Кто-то пошел и поел 2 * 100 = 200 порции "); | |
| plate.feed(200); | |
| System.out.println("Кто-то поел стандартную порцию"); | |
| plate.feed(); | |
| System.out.println("Кто-то пошел и поел 10 * 100 = 1000 порций "); | |
| plate.feed(1000); | |
| System.out.println("Миша пошел есть первый раз " + misha.id + " Мишин идентификатор"); | |
| misha.eat(plate, plate.getPortion()); | |
| System.out.println("Миша пошел есть второй раз " + misha.id + " Мишин идентификатор"); | |
| misha.eat(plate, Plate.getPortion()); | |
| System.out.println("Кошка " + masha.name + " пошла есть " + " # " + masha.id); | |
| masha.eat(plate, Plate.portion); | |
| System.out.println("Гала пошла есть " + gala.id); | |
| gala.eat(plate, Plate.portion); | |
| System.out.println("Петр пошел есть " + petr.id); | |
| petr.eat(plate, Plate.portion); | |
| System.out.println("Абстрактная кошка " + cat.id + " пошла есть -100"); | |
| cat.eat(plate, Plate.portion); // кошка кушает из тарелки, которую передали ей в параметрах | |
| System.out.println("Тарелка покормила абстрактную кошку стандартной порцией: plate.feed(cat, Plate.portion) -100"); | |
| plate.feed(cat, Plate.portion); // тарелка "кормит" кошку, которую ей передали в параметры | |
| System.out.println("Миша пошел есть третий раз " + misha.id + " Мишин идентификатор"); | |
| misha.eat(plate, Plate.getPortion()); | |
| System.out.println("Проверяем номера кошек"); | |
| System.out.println("Маша номер " + masha.id); | |
| System.out.println("Миша номер " + misha.id); | |
| System.out.println("Галя номер " + gala.id); | |
| System.out.println("Kate номер " + kate.id); | |
| System.out.println("Petr номер " + petr.id); | |
| System.out.println("Boris номер " + boris.id); | |
| System.out.println("Абстрактная кошка номер " + cat.id); | |
| System.out.println("Barsic номер " + cat02.id); | |
| System.out.println("Общее кол-во еды потреблённой всеми кошками"); | |
| System.out.println("Кошка " + masha.name + " номер " + masha.id + " всего употребила еды " + masha.consumed); | |
| System.out.println("Кошка " + misha.name + " номер " + misha.id + " всего употребила еды " + misha.consumed); | |
| System.out.println("Кошка " + gala.name + " номер " + gala.id + " всего употребила еды " + gala.consumed); | |
| System.out.println("Кошка " + kate.name + " номер " + kate.id + " всего употребила еды " + kate.consumed); | |
| System.out.println("Кошка " + petr.name + " номер " + petr.id + " всего употребила еды " + petr.consumed); | |
| System.out.println("Кошка " + boris.name + " номер " + boris.id + " всего употребила еды " + boris.consumed); | |
| System.out.println("Абстрактная кошка номер " + cat.id + " всего употребила еды " + cat.consumed); | |
| System.out.println("Barsic номер " + cat02.id + " всего употребила еды " + cat02.consumed); | |
| System.out.println("Тарелка покормила абстрактную кошку стандартной порцией: plate.feed(cat, Plate.portion) " + cat.consumed); | |
| System.out.println("Общее кол-во воды потреблённой всеми кошками"); | |
| System.out.println("Кошка " + kate.name + " номер " + kate.id + " всего употребила воды " + kate.consumedVoda); | |
| System.out.println("Кошка " + boris.name + " номер " + boris.id + " всего употребила воды " + boris.consumedVoda); | |
| System.out.println("Barsic номер " + cat02.id + " всего употребила воды " + cat02.consumedVoda); | |
| System.out.println("-------------------------------------------------------"); | |
| System.out.println("-------------------------------------------------------"); | |
| System.out.println("Общее количество осталось еды " + plate.eda); | |
| System.out.println("Общее количество сьеденной еды " + plate.consumed); | |
| System.out.println("А было сначала еды 3000 = " +( plate.eda + plate.consumed)); | |
| System.out.println("Общее количество осталось воды " + bowl.voda); | |
| System.out.println("Общее количество выпитой воды " + bowl.consumedVoda); | |
| System.out.println("А было сначала воды 2000 = " + (bowl.voda + bowl.consumedVoda)); | |
| } | |
| } | |
| class Cat { | |
| public int consumedVoda; | |
| String name;//this.name | |
| Count count; | |
| int id; | |
| int consumed; | |
| static int portion = Plate.getPortion(); | |
| static int portionVoda = Bowl.getPortionVoda(); | |
| public Cat() { | |
| id = count.getNextCount(); | |
| consumed = consumed + portion; | |
| } | |
| public Cat(String name) { | |
| this.name = name; | |
| id = count.getNextCount(); | |
| consumed = consumed + portion; | |
| } | |
| public Cat(String name, Count count) { | |
| this.name = name; | |
| id = count.getNextCount(); | |
| consumed = consumed + portion; | |
| } | |
| public Cat(Count count) { | |
| id = count.getNextCount(); | |
| consumed = consumed + portion; | |
| } | |
| static int showCount() { | |
| Count count = null; | |
| int amountC = count.getNextCount() - 1; | |
| System.out.println("Кошек всего создано: " + amountC); | |
| return amountC; | |
| } | |
| public int eat(Plate plate, int portion) { | |
| Plate.eda = Plate.eda - portion; | |
| consumed = consumed + portion; | |
| System.out.println("--------------------------------------------------eat method begin"); | |
| if (Plate.eda <= 0) { | |
| Plate.eda = 0; | |
| System.out.println("Еда закончилась"); | |
| } else { | |
| System.out.println(name + " сьел " + portion + " а общее кол-во сьеденной им еды " + consumed); | |
| System.out.println(Plate.eda + " остаток еды в тарелке"); | |
| System.out.println("Кошка " + name + " " + id + " съела из тарелки " + portion); | |
| System.out.println("Кошка " + name + " " + id + " всего употребила еды " + consumed); | |
| System.out.println("--------------------------------------------------eat method end"); | |
| } | |
| return Plate.eda; | |
| } | |
| public int drink(Bowl bowl, int portionVoda) { | |
| Bowl.voda = Bowl.voda - portionVoda; | |
| consumedVoda = consumedVoda + portionVoda; | |
| System.out.println("..............................................................drink method begin"); | |
| if (Bowl.voda <= 0) { | |
| Bowl.voda = 0; | |
| System.out.println("Вода закончилась"); | |
| } else { | |
| System.out.println(name + " выпил" + portionVoda + " а общее кол-во выпитой им воды " + consumedVoda); | |
| System.out.println(Bowl.voda + " остаток воды в чашке"); | |
| System.out.println("Кошка " + name + "# " + id + " выпила " + portionVoda); | |
| System.out.println("Кошка " + name + "# " + id + " всего выпила воды " + consumedVoda); | |
| System.out.println("............................................................drink method end"); | |
| } | |
| return Bowl.voda; | |
| } | |
| } | |
| class Bowl { | |
| static int voda = 2000; | |
| public static int consumedVoda; | |
| public static int portionVoda; | |
| public static int setPortionVoda(int amountVoda) { | |
| int portionVoda = amountVoda; | |
| return portionVoda; | |
| } | |
| public static int drink(Cat cat, int portionVoda) { | |
| consumedVoda = consumedVoda + portionVoda; | |
| Bowl.voda = Bowl.voda - portionVoda; | |
| if (Bowl.voda <= 0) { | |
| Bowl.voda = 0; | |
| System.out.println("Вода закончилась"); | |
| } else { | |
| System.out.println("Воды осталось " + Bowl.voda); | |
| } | |
| return Bowl.voda; | |
| } | |
| public static int getPortionVoda() { | |
| Bowl.voda = Bowl.voda - Bowl.portionVoda; | |
| if (Bowl.voda <= 0) { | |
| Bowl.voda = 0; | |
| System.out.println("Вода закончилась"); | |
| } else { | |
| System.out.println("Воды осталось " + Bowl.voda); | |
| } | |
| return portionVoda; | |
| } | |
| public int drink(int portionVoda) { | |
| consumedVoda = consumedVoda + portionVoda; | |
| Bowl.voda = Bowl.voda - portionVoda; | |
| if (Bowl.voda <= 0) { | |
| Bowl.voda = 0; | |
| System.out.println("Вода закончилась"); | |
| } else { | |
| System.out.println("Воды осталось " + Bowl.voda); | |
| } | |
| return Bowl.voda; | |
| } | |
| } | |
| class Plate { | |
| static int eda = 3000; | |
| public static int consumed; | |
| public static int portion; | |
| public static int feed(Cat cat, int portion) { | |
| consumed = consumed + portion; | |
| Plate.eda = Plate.eda - portion; | |
| if (Plate.eda <= 0) { | |
| Plate.eda = 0; | |
| System.out.println("Еда закончилась"); | |
| } else { | |
| System.out.println("Еды осталось " + Plate.eda); | |
| } | |
| return Plate.eda; | |
| } | |
| public int feed(int portion) { | |
| consumed = consumed + portion; | |
| Plate.eda = Plate.eda - portion; | |
| if (Plate.eda <= 0) { | |
| Plate.eda = 0; | |
| System.out.println("Еда закончилась"); | |
| } else { | |
| System.out.println("Еды осталось " + Plate.eda); | |
| } | |
| return Plate.eda; | |
| } | |
| public int feed() { | |
| consumed = consumed + portion; | |
| Plate.eda = Plate.eda - portion; | |
| if (Plate.eda <= 0) { | |
| Plate.eda = 0; | |
| System.out.println("Еда закончилась"); | |
| } else { | |
| System.out.println("Еды осталось " + Plate.eda); | |
| } | |
| return Plate.eda; | |
| } | |
| public static int setPortion(int amount) { | |
| int portion = amount; | |
| return portion; | |
| } | |
| public static int getPortion() { | |
| Plate.eda = Plate.eda - Plate.portion; | |
| if (Plate.eda <= 0) { | |
| Plate.eda = 0; | |
| System.out.println("Еда закончилась"); | |
| } else { | |
| System.out.println("Еды осталось " + Plate.eda); | |
| } | |
| return portion; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment