Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level10.lesson11.home06;
- /* Конструкторы класса Human
- Напиши класс Human с 6 полями. Придумай и реализуй 10 различных конструкторов для него.
- Каждый конструктор должен иметь смысл.
- */
- public class Solution
- {
- public static void main(String[] args)
- {
- Human num1 = new Human("Danila",33, true);
- Human num2 = new Human("Danila",40, false, num1,num1);
- Human num3 = new Human("Vita", 18, false, 1);
- Human num4 = new Human("Roma", 19, true, "PFU");
- Human num5 = new Human ("Sofia", 5, false, num3);
- Human num6 = new Human("Somename", 60, false, num2, "Upfu");
- Human num7 = new Human("vova", 4004);
- Human num8 = new Human("Roma", "java");
- Human num9 = new Human("Vera ivan", false, 150);
- Human num10 = new Human("Ziga");
- }
- public static class Human
- {
- //напишите тут ваши переменные и конструкторы
- int age;
- String name;
- boolean sex;
- int children;
- String job;
- Human parentFather;
- Human parentMother;
- //1. For grandParents
- Human(String name, int age, boolean sex) {
- this.name = name;
- this.age = age;
- this.sex = sex;
- }
- //2.For children
- Human(String name, int age, boolean sex, Human parentFather, Human parentMother ) {
- this.name = name;
- this.age = age;
- this.sex = sex;
- this.parentFather = parentFather;
- this.parentMother = parentMother;
- }
- //3. For parents
- Human(String name, int age, boolean sex, int children) {
- this.name = name;
- this.age = age;
- this.sex = sex;
- this.children = children;
- }
- //4. For parents withs job
- Human(String name, int age, boolean sex, String job) {
- this.name = name;
- this.age = age;
- this.sex = sex;
- this.job = job;
- }
- //5.
- Human(String name, int age, boolean sex, Human parentMother) {
- this.name = name;
- this.age = age;
- this.sex = sex;
- }
- //6.
- Human(String name, int age, boolean sex, Human parentMother, String job) {
- this.name = name;
- this.age = age;
- this.sex = sex;
- this.parentMother = parentMother;
- this.job = job;
- }
- //7.
- Human(String name, int age) {
- this.name = name;
- this.age = age;
- }
- //8.
- Human (String name, String job) {
- this.name = name;
- this.job = job;
- }
- //9.
- Human (String name, boolean sex, int children) {
- this.name = name;
- this.sex = sex;
- this.children = children;
- }
- Human(String name) {
- this.name = name;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement