Created
January 10, 2020 20:11
-
-
Save Khuzha/9d5d592625c2d73a76c833cff2cef71b to your computer and use it in GitHub Desktop.
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
| public class GoodDog { | |
| private String name = "Default"; | |
| private byte count = 0; | |
| private byte weight = 0; | |
| void play () { | |
| System.out.println(name + " с радостью, виляя хвостом: "); | |
| if (weight > 30) { | |
| bark("Гав-гав! Вуф-вуф!"); | |
| } else { | |
| bark("Тяв-тяв-тяв!"); | |
| } | |
| } | |
| void bark (String sound) { | |
| for (int i = 0; i < count; i++) { | |
| System.out.println(sound); | |
| } | |
| } | |
| public String getName () { | |
| return name; | |
| } | |
| public void setName (String n) { | |
| name = n; | |
| } | |
| public byte getCount () { | |
| return count; | |
| } | |
| public void setCount (byte c) { | |
| count = c; | |
| } | |
| public byte getWeight () { | |
| return getWeight(); | |
| } | |
| public void setWeight (byte w) { | |
| weight = w; | |
| } | |
| } |
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
| import java.util.Scanner; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Scanner scanner = new Scanner(System.in); | |
| GoodDog myGoodDog = new GoodDog(); | |
| System.out.println("Введите, как зовут Вашу собаку:"); | |
| myGoodDog.setName(scanner.nextLine()); | |
| System.out.println("Введите, сколько килограм весит Ваша собака:"); | |
| myGoodDog.setWeight(scanner.nextByte()); | |
| System.out.println("Введите, сколько раз она должна пролаять:"); | |
| myGoodDog.setCount(scanner.nextByte()); | |
| System.out.println("Спасибо. Собака бежит к Вам:"); | |
| myGoodDog.play(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment