Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level14.lesson06.home01;
- /* Куриная фабрика
- Написать Фабрику(Factory) по производству кур(Hen)
- 1. Создать класс Hen
- 1.1. Сделать его абстрактным//done
- 1.2. Добавить в класс абстрактный метод int getCountOfEggsPerMonth()
- 1.3. Добавить в класс метод String getDescription(), который возвращает строку "Я курица."
- 2. Создать класс RussianHen, который наследуется от Hen
- 3. Создать класс UkrainianHen, который наследуется от Hen
- 4. Создать класс MoldovanHen, который наследуется от Hen
- 5. Создать класс BelarusianHen, который наследуется от Hen
- 6. В каждом из четырех последних классов написать свою реализацию метода getCountOfEggsPerMonth.
- Методы должны возвращать количество яиц в месяц от данного типа куриц.
- Откуда берется это число?
- 7. В каждом из четырех последних классов написать свою реализацию метода getDescription.
- Методы должны возвращать строку вида:
- <getDescription() родительского класса> + <" Моя страна - SSSSS. Я несу N яиц в месяц.">
- где SSSSS - название страны
- где N - количество яиц в месяц
- 8. В классе HenFactory реализовать меетод getHen, который возвращает соответствующую стране породу кур
- 9. Все созданные вами классы должны быть в отдельных файлах
- */
- public class Solution
- {
- public static void main(String[] args)
- {
- Hen hen = HenFactory.getHen(Country.BELARUS);
- hen.getCountOfEggsPerMonth();
- }
- static class HenFactory {
- static Hen getHen(String country) {
- Hen hen = null;
- //add your code here
- if (country.equals(Country.RUSSIA)) {
- hen = new RussianHen();
- }
- if (country.equals(Country.MOLDOVA)) {
- hen = new MoldovanHen();
- }
- if (country.equals(Country.UKRAINE)) {
- hen = new UkrainianHen();
- }
- if (country.equals(Country.BELARUS)) {
- hen = new BelarusianHen();
- }
- return hen;
- }
- }
- }
- /*----------------------------------------------------------------*/
- package com.javarush.test.level14.lesson06.home01;
- /**
- * Created by Т-34 on 23.06.2015.
- */
- public abstract class Hen implements Country
- {
- int N;
- String country;
- public abstract int getCountOfEggsPerMonth();
- public String getDescription(){
- return "Я курица.";
- }
- }
- /*----------------------------------------------------------------*/
- package com.javarush.test.level14.lesson06.home01;
- /**
- * Created by Т-34 on 23.06.2015.
- */
- public class RussianHen extends Hen
- {
- String country = RUSSIA;
- public int getCountOfEggsPerMonth(){
- return this.N;
- }
- public String getDescription(){
- return super.getDescription() + " Моя страна - " + this.country + ". Я несу " + getCountOfEggsPerMonth() + " яиц в месяц.";
- }
- }
- /*----------------------------------------------------------------*/
- package com.javarush.test.level14.lesson06.home01;
- /**
- * Created by Т-34 on 23.06.2015.
- */
- public class MoldovanHen extends Hen
- {
- String country = MOLDOVA;
- public int getCountOfEggsPerMonth(){
- return this.N;
- }
- public String getDescription(){
- return super.getDescription() + " Моя страна - " + this.country + ". Я несу " + getCountOfEggsPerMonth() + " яиц в месяц.";
- }
- }
- /*----------------------------------------------------------------*/
- package com.javarush.test.level14.lesson06.home01;
- /**
- * Created by Т-34 on 23.06.2015.
- */
- public class UkrainianHen extends Hen
- {
- String country = UKRAINE;
- public int getCountOfEggsPerMonth(){
- return this.N;
- }
- public String getDescription(){
- return super.getDescription() + " Моя страна - " + this.country + ". Я несу " + getCountOfEggsPerMonth() + " яиц в месяц.";
- }
- }
- /*----------------------------------------------------------------*/
- package com.javarush.test.level14.lesson06.home01;
- /**
- * Created by Т-34 on 23.06.2015.
- */
- public class BelarusianHen extends Hen
- {
- String country = BELARUS;
- public int getCountOfEggsPerMonth(){
- return this.N;
- }
- public String getDescription(){
- return super.getDescription() + " Моя страна - " + this.country + ". Я несу " + getCountOfEggsPerMonth() + " яиц в месяц.";
- }
- }
- /*----------------------------------------------------------------*/
- package com.javarush.test.level14.lesson06.home01;
- public interface Country
- {
- String UKRAINE = "Ukraine";
- String RUSSIA = "Russia";
- String MOLDOVA = "Moldova";
- String BELARUS = "Belarus";
- }
- /*----------------------------------------------------------------*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement