Advertisement
Guest User

var2

a guest
Jan 16th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. public class Cat {
  2.  
  3.     private String name;
  4.     private int satiety; // сытость
  5.     private boolean isAlive; // живой?
  6.  
  7.     public Cat(String name) {
  8.         this.name = name;
  9.         this.satiety = 100;
  10.         this.isAlive = true;
  11.     }
  12.  
  13.     public void liveDay() {
  14.         this.satiety -= 50;
  15.         if (this.satiety <= 0) {
  16.             isAlive = false;
  17.         }
  18.     }
  19.  
  20.     public void feed(Feed feed) {
  21.         if (isAlive) {
  22.             this.satiety += feed.satietyOfGramm * feed.portion;
  23.         } else {
  24.             System.out.println("Кот помер");
  25.         }
  26.     }
  27.  
  28.     public String getName() {
  29.         return this.name;
  30.     }
  31.  
  32.     public void setName(String name) {
  33.         this.name = name;
  34.     }
  35. }
  36.  
  37. public class Feed {
  38.  
  39.     int portion;
  40.     int satietyOfGramm;
  41.  
  42.     public Feed(int portion, int satietyOfGramm) {
  43.         this.portion = portion;
  44.         this.satietyOfGramm = satietyOfGramm;
  45.     }
  46.  
  47.     public int getPortion() {
  48.         return portion;
  49.     }
  50.  
  51.     public void setPortion(int portion) {
  52.         this.portion = portion;
  53.     }
  54.  
  55.     public int getSatietyOfGramm() {
  56.         return satietyOfGramm;
  57.     }
  58.  
  59.     public void setSatietyOfGramm(int satietyOfGramm) {
  60.         this.satietyOfGramm = satietyOfGramm;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement