Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Cat {
- private String name;
- private int satiety; // сытость
- private boolean isAlive; // живой?
- public Cat(String name) {
- this.name = name;
- this.satiety = 100;
- this.isAlive = true;
- }
- public void liveDay() {
- this.satiety -= 50;
- if (this.satiety <= 0) {
- isAlive = false;
- }
- }
- public void feed(Feed feed) {
- if (isAlive) {
- this.satiety += feed.satietyOfGramm * feed.portion;
- } else {
- System.out.println("Кот помер");
- }
- }
- public String getName() {
- return this.name;
- }
- public void setName(String name) {
- this.name = name;
- }
- }
- public class Feed {
- int portion;
- int satietyOfGramm;
- public Feed(int portion, int satietyOfGramm) {
- this.portion = portion;
- this.satietyOfGramm = satietyOfGramm;
- }
- public int getPortion() {
- return portion;
- }
- public void setPortion(int portion) {
- this.portion = portion;
- }
- public int getSatietyOfGramm() {
- return satietyOfGramm;
- }
- public void setSatietyOfGramm(int satietyOfGramm) {
- this.satietyOfGramm = satietyOfGramm;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement