Created
May 28, 2020 06:37
-
-
Save olegrewko/3a2739dd40764f32598ac1ad9eca2ace to your computer and use it in GitHub Desktop.
CatsOOP-28
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; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Cat masha = new Cat("Маша"); | |
| Cat misha = new Cat("Миша"); | |
| Cat gala = new Cat("Галя"); | |
| Cat kate = new Cat("Kate"); | |
| Cat petr = new Cat("Petr"); | |
| petr.showCount(); | |
| masha.showCount(); | |
| Bowl bowl = new Bowl(); | |
| Plate plate = new Plate(); | |
| System.out.println("Маша номер " + masha.id); | |
| System.out.println("Галя номер " + gala.id); | |
| System.out.println("Kate номер " + kate.id); | |
| System.out.println("Маша номер " + masha.id); | |
| System.out.println("Petr номер " + petr.id); | |
| System.out.println("Общее количество сначала воды " + bowl.voda); | |
| System.out.println("Общее количество еды сначала еды " + plate.eda); | |
| bowl.drink(500); | |
| bowl.drink(550); | |
| bowl.drink(100); | |
| plate.eat(500); | |
| plate.eat(300); | |
| misha.eat(plate); | |
| masha.eat(plate); | |
| gala.eat(plate); | |
| petr.eat(plate); | |
| System.out.println("--------------------------------"); | |
| System.out.println("Общее количество осталось еды " + plate.eda); | |
| } | |
| } | |
| class Cat { | |
| int consumed;//сколько всего сьела кошка | |
| String name;//this.name | |
| static int count; | |
| int id; | |
| public Cat(String name) { | |
| this(); | |
| this.name = name; | |
| } | |
| public Cat() { | |
| count++; | |
| id = count; | |
| } | |
| static int showCount() { | |
| System.out.println("Кошек всего " + count); | |
| return count; | |
| } | |
| public void eat(Plate plate) { | |
| int portion = 10; | |
| consumed = consumed + portion; | |
| plate.eda = plate.eda - portion; | |
| System.out.println(name + " сьел " + portion + " а общее кол-во сьеденной еды " + consumed); | |
| System.out.println(plate.eda + "остаток еды"); | |
| System.out.println("Кошка съела из тарелки " + portion); | |
| System.out.println("Кошка всего съела " + consumed); | |
| } | |
| } | |
| class Bowl { | |
| int voda = 1800; | |
| public int drink(int portionV) { | |
| int ostV = voda - portionV; | |
| voda = voda - portionV; | |
| if (ostV <= 0) { | |
| System.out.println("Вода закончилась"); | |
| } else { | |
| System.out.println("Воды осталось " + ostV); | |
| } | |
| return ostV; | |
| } | |
| } | |
| class Plate { | |
| int eda = 1500; | |
| public int eat(int portion) { | |
| int ostatok = eda - portion; | |
| eda = eda - portion; | |
| if (ostatok <= 0) { | |
| System.out.println("Еда закончилась"); | |
| } else { | |
| System.out.println("Еды осталось " + ostatok); | |
| } | |
| return ostatok; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment