diff --git a/.gitignore b/.gitignore index a1c2a23..3004d02 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ # Compiled class file -*.class # Log file *.log diff --git a/FamilyOOP/Animal.java b/FamilyOOP/Animal.java new file mode 100644 index 0000000..79cb206 --- /dev/null +++ b/FamilyOOP/Animal.java @@ -0,0 +1,12 @@ +package FamilyOOP; + +abstract class Animal { + protected int type; + protected int height; + protected int weight; + protected int wool; + + abstract void voice(); + + abstract void gogo(); +} \ No newline at end of file diff --git a/FamilyOOP/Cat.java b/FamilyOOP/Cat.java new file mode 100644 index 0000000..f24fc03 --- /dev/null +++ b/FamilyOOP/Cat.java @@ -0,0 +1,12 @@ +package FamilyOOP; + +class Cat extends Animal { + @Override + void voice() { + System.out.println("мяу"); + } + @Override + void gogo() { + System.out.println("Идти"); + } +} diff --git a/FamilyOOP/Children.java b/FamilyOOP/Children.java new file mode 100644 index 0000000..f7fad71 --- /dev/null +++ b/FamilyOOP/Children.java @@ -0,0 +1,35 @@ +package FamilyOOP; + +class Children extends Human implements PetOwner { + private String parents; + private String name; + int hunger() { + return (int)(Math.random() * 9); + } + void goEat() { + System.out.println("Ест..."); + int food = (int)(Math.random() * 3); + int hunger = hunger() - food; + int trueLevelFood = 5; + if (hunger == trueLevelFood) + System.out.println("Ребенок больше не голоден"); + else if (hunger < trueLevelFood) { + goEat(); + } + else { + System.out.println("Ребенок переел"); + } + } + @Override + int go(int start) { + int step = (int)(Math.random() * 7); + int finish = start + step; + return finish; + } + + @Override + public void call() { + System.out.println("Агу Агу"); + } +} + diff --git a/FamilyOOP/Grandma.java b/FamilyOOP/Grandma.java new file mode 100644 index 0000000..43b7748 --- /dev/null +++ b/FamilyOOP/Grandma.java @@ -0,0 +1,5 @@ +package FamilyOOP; + +class Grandma extends Sister { + +} diff --git a/FamilyOOP/Human.java b/FamilyOOP/Human.java new file mode 100644 index 0000000..9d893b4 --- /dev/null +++ b/FamilyOOP/Human.java @@ -0,0 +1,20 @@ +package FamilyOOP; + +/**Абстрактный класс человек*/ +abstract class Human{ + private int age; + private String gender; + private String familyStatus; + private String havingChildren; + private String colorHair; + public int getAge() {return age;} + public String getFamilyStatus() {return familyStatus;} + public String getHavingChildren() {return havingChildren;} + abstract int go(int start); + void showFamilyStatus() { + int age = getAge(); + String status = getFamilyStatus(); + String ch = getHavingChildren(); + System.out.printf("Человек в возрасте: %d лет. Семейное положение: %s. Дети: %s", age, status, ch); + } +} diff --git a/FamilyOOP/Mother.java b/FamilyOOP/Mother.java new file mode 100644 index 0000000..f0d660f --- /dev/null +++ b/FamilyOOP/Mother.java @@ -0,0 +1,8 @@ +package FamilyOOP; + +import java.lang.annotation.Target; + +public interface Mother { + void cleanHome(int time); + void bringUpChildren(); +} diff --git a/FamilyOOP/PetOwner.java b/FamilyOOP/PetOwner.java new file mode 100644 index 0000000..640b2f5 --- /dev/null +++ b/FamilyOOP/PetOwner.java @@ -0,0 +1,5 @@ +package FamilyOOP; + +public interface PetOwner { + void call(); +} diff --git a/FamilyOOP/Program.java b/FamilyOOP/Program.java new file mode 100644 index 0000000..fbf4c62 --- /dev/null +++ b/FamilyOOP/Program.java @@ -0,0 +1,16 @@ +package FamilyOOP; + +public class Program { + public static void main(String[] args) { + Children George = new Children(); + System.out.println(George.go(2)); + George.call(); + George.goEat(); + + Grandma Meg = new Grandma(); + System.out.println(Meg.go(6)); + + + + } +} \ No newline at end of file diff --git a/FamilyOOP/Sister.java b/FamilyOOP/Sister.java new file mode 100644 index 0000000..07d37a3 --- /dev/null +++ b/FamilyOOP/Sister.java @@ -0,0 +1,38 @@ +package FamilyOOP; + +class Sister extends Human implements Mother, PetOwner { + private String SisAndBro; + public String getSisAndBro() {return SisAndBro;} + + @Override + int go(int steps) { + int start = 0; + int move = start + steps; + return move; + } + @Override + void showFamilyStatus() { + int age = getAge(); + String status = getFamilyStatus(); + String ch = getHavingChildren(); + String sandb = getSisAndBro(); + System.out.printf("Человек в возрасте: %d лет. Семейное положение: %s. Дети: %s. Братья/Сестры : %s", age, status, ch, sandb); + } + @Override + public void cleanHome(int effort) { + if (effort < 100 && effort > 50) {System.out.println("Идеальная уборка!");} + else if (effort < 50 && effort > 20) {System.out.println("Хорошо постарались");} + else if (effort < 20 && effort > 0) {System.out.println("Плохо!");} + else System.out.println("Какая-то ошибка..."); + } + @Override + public void bringUpChildren() { + System.out.println("Не балуйся!"); + } + + @Override + public void call() { + System.out.println("Иди сюда!"); + } + +} diff --git a/Human.java b/Human.java new file mode 100644 index 0000000..b5ac5ed --- /dev/null +++ b/Human.java @@ -0,0 +1,125 @@ +package Family; + +class Human{ + private int age; + private String gender; + private String familyStatus; + private String havingChildren; + private String colorHair; + + Human(int age, String familyStatus, String havingChildren) { + this.age = age; + this.familyStatus = familyStatus; + this.havingChildren = havingChildren; + } + + Human(int age, String gender) { + this.age = age; + this.gender = gender; + } + + Human(int age, String familyStatus, String havingChildren, String colorHair) { + this(age,familyStatus, havingChildren); + this.colorHair = colorHair; + + } + + public int getAge() {return age;} + public String getGender() {return gender;} + public String getFamilyStatus() {return familyStatus;} + public String getHavingChildren() {return havingChildren;} + public String getColorHair() {return colorHair;} + public void setAge(int age) {this.age = age;} + public void setGender(String gender) {this.gender = gender;} + public void setFamilyStatus(String familyStatus) {this.familyStatus = familyStatus;} + public void setHavingChildren(String havingChildren) {this.havingChildren = havingChildren;} + public void setColorHair(String colorHair) {this.colorHair = colorHair;} + void showFamilyStatus() { + int age = getAge(); + String status = getFamilyStatus(); + String ch = getHavingChildren(); + System.out.printf("Человек в возрасте: %d лет. Семейное положение: %s. Дети: %s", age, status, ch); + } +} + +class Father extends Human { + Father(int age, String familyStatus, String colorEye, String havingChildren, String havingBrothersAndSisters) { + super(age, familyStatus, havingChildren); + setColorEye(colorEye); + setHavingBrothersAndSisters(havingBrothersAndSisters); + } + private String colorEye; + private String havingBrothersAndSisters; + + public void setColorEye(String colorEye) {this.colorEye = colorEye;} + public void setHavingBrothersAndSisters(String havingBrothersAndSisters) {this.havingBrothersAndSisters = havingBrothersAndSisters;} + + public String getColorEye() {return colorEye;} + public String getHavingBrothersAndSisters() {return havingBrothersAndSisters;} +} + +class Mother extends Human { + Mother(int age, String familyStatus, String havingChildren, String colorHair, String education){ + super(age, familyStatus, havingChildren, colorHair); + this.education = education; + } + Mother(int age, String gender) { + super(age, gender); + } + private String education; + + public void setEducation(String education) {this.education = education;} + public String getEducation() {return education;} + + void voice(String name) { + System.out.println(name + " иди есть суп"); + } + +} + +class Children extends Mother { + Children(String name, int age, String gender, String parents) { + super(age, gender); + this.parents = parents; + this.name = name; + } + private String parents; + private String name; + int hunger() { + return (int)(Math.random() * 9); + } + void goEat() { + System.out.println("Ест..."); + int food = (int)(Math.random() * 3); + int hunger = hunger() - food; + int trueLevelFood = 5; + if (hunger == trueLevelFood) + System.out.println("Ребенок больше не голоден"); + else if (hunger < trueLevelFood) { + goEat(); + } + else { + System.out.println("Ребенок переел"); + } + } + public void setParents(String parents) {this.parents = parents;} + public String getParents() {return parents;} + +} + + +class Family { + public static void main(String[] args) { + Father father = new Father(45, "не женат", "голубые глаза", "1 ребенок", "нет сестер"); + Mother mother = new Mother(34, "не замужем", "1 ребенок", "рыжые волосы", "высшее"); + Children children1 = new Children("Степан", 12, "мужской", "Лев и Марина"); + Children children2 = new Children("Дмитрий", 18, "мужской", "Леонид и Марина"); + + mother.setHavingChildren("2 ребенка"); + + mother.voice("Степан,"); + children1.goEat(); + father.showFamilyStatus(); + } + +} \ No newline at end of file