From 2f725db7789b2650fe932aeaae49901d1bdcaf57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=A2?= =?UTF-8?q?=D0=B8=D1=85=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Mon, 26 Sep 2022 14:37:48 +0300 Subject: [PATCH 1/2] part 1 --- src/ru/skypro/Car.java | 82 ++++++++++++++++++++++++++++++++++++++++ src/ru/skypro/Human.java | 52 +++++++++++++++++++++++++ src/ru/skypro/Main.java | 20 ++++++++++ 3 files changed, 154 insertions(+) create mode 100644 src/ru/skypro/Car.java create mode 100644 src/ru/skypro/Human.java diff --git a/src/ru/skypro/Car.java b/src/ru/skypro/Car.java new file mode 100644 index 0000000..9e2b3a7 --- /dev/null +++ b/src/ru/skypro/Car.java @@ -0,0 +1,82 @@ +package ru.skypro; + +public class Car { + private String brand; + + public Car(String brand, String model, String engineVolume, String color, Integer productionYear, String productionCountry) { + this.brand = brand; + this.model = model; + this.engineVolume = engineVolume; + this.color = color; + this.productionYear = productionYear; + this.productionCountry = productionCountry; + } + + private String model; + private String engineVolume; + private String color; + + @Override + public String toString() { + return "Car{" + + "brand='" + brand + '\'' + + ", model='" + model + '\'' + + ", engineVolume='" + engineVolume + '\'' + + ", color='" + color + '\'' + + ", productionYear='" + productionYear + '\'' + + ", productionCountry='" + productionCountry + '\'' + + '}'; + } + + private Integer productionYear; + + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public String getEngineVolume() { + return engineVolume; + } + + public void setEngineVolume(String engineVolume) { + this.engineVolume = engineVolume; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + public Integer getProductionYear() { + return productionYear; + } + + public void setProductionYear(Integer productionYear) { + this.productionYear = productionYear; + } + + public String getProductionCountry() { + return productionCountry; + } + + public void setProductionCountry(String productionCountry) { + this.productionCountry = productionCountry; + } + + private String productionCountry; +} diff --git a/src/ru/skypro/Human.java b/src/ru/skypro/Human.java new file mode 100644 index 0000000..9764e8a --- /dev/null +++ b/src/ru/skypro/Human.java @@ -0,0 +1,52 @@ +package ru.skypro; + +public class Human { + @Override + public String toString() { + return "Привет! Меня зовут "+name+". Я из города "+town+". Я родился в "+yearOfBirth+" году. Будем знакомы! Я работаю на должности "+position+" . Будем знакомы!"; + } + + private Integer yearOfBirth; + private String name; + private String position; + private String town; + + public Human(Integer yearOfBirth, String name, String town, String position) { + this.yearOfBirth = yearOfBirth; + this.name = name; + this.town = town; + this.position = position; + } + + public Integer getYearOfBirth() { + return yearOfBirth; + } + + public void setYearOfBirth(Integer yearOfBirth) { + this.yearOfBirth = yearOfBirth; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getTown() { + return town; + } + + public void setTown(String town) { + this.town = town; + } + + public String getPosition() { + return position; + } + + public void setPosition(String position) { + this.position = position; + } +} diff --git a/src/ru/skypro/Main.java b/src/ru/skypro/Main.java index 625884e..3cba65e 100644 --- a/src/ru/skypro/Main.java +++ b/src/ru/skypro/Main.java @@ -2,6 +2,26 @@ public class Main { public static void main(String[] args){ + Human Максим = new Human(1987,"Максим","Минск","бренд-менеджер"); + Human Аня = new Human(1993,"Аня","Москва","методист образовательных программ"); + Human Катя = new Human(1994,"Катя","Калининград","продакт-менеджер"); + Human Артем = new Human(1995,"Артем","Москва","директор по развитию бизнеса"); + System.out.println(Максим); + System.out.println(Аня); + System.out.println(Катя); + System.out.println(Артем); + + Car car1 = new Car("Lada","Grande","1,7л", "желтый", 2015,"Россия"); + Car car2 = new Car("Audi","A8 50 L TDI quattro","3.0л" , "черный",2020, "Германия"); + Car car3 = new Car("BMW","Z8", "3.0л", "черный",2021,"Германия"); + Car car4 = new Car("Kia","Sportage 4 поколение","2,4л" , "красный ", 2018, "Южная Корея"); + Car car5 = new Car("Hyundai","Avante","1,6л", "оранжевый", 2016,"Южная Корея"); + System.out.println(car1); + System.out.println(car2); + System.out.println(car3); + System.out.println(car4); + System.out.println(car5); + } } From 18fa8de57b277b7c27939ad36c17dc142850fc57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=A2?= =?UTF-8?q?=D0=B8=D1=85=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Mon, 26 Sep 2022 14:46:08 +0300 Subject: [PATCH 2/2] part 3 --- src/ru/skypro/Car.java | 18 ++++++++++++------ src/ru/skypro/Human.java | 10 ++++++---- src/ru/skypro/Main.java | 4 +++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/ru/skypro/Car.java b/src/ru/skypro/Car.java index 9e2b3a7..2184706 100644 --- a/src/ru/skypro/Car.java +++ b/src/ru/skypro/Car.java @@ -1,21 +1,27 @@ package ru.skypro; +import java.util.Objects; + public class Car { private String brand; public Car(String brand, String model, String engineVolume, String color, Integer productionYear, String productionCountry) { - this.brand = brand; - this.model = model; - this.engineVolume = engineVolume; - this.color = color; - this.productionYear = productionYear; - this.productionCountry = productionCountry; + this.brand = Objects.requireNonNullElse(brand,"default"); + this.model = Objects.requireNonNullElse(model,"default"); + this.engineVolume = Objects.requireNonNullElse(engineVolume," 1,5 л"); + this.color = Objects.requireNonNullElse(color,"белый"); + this.productionYear = Objects.requireNonNullElse(productionYear,2000); + this.productionCountry = Objects.requireNonNullElse(productionCountry,"default"); } private String model; private String engineVolume; private String color; + public Car() { + this(null,null,null,null,null,null); + } + @Override public String toString() { return "Car{" + diff --git a/src/ru/skypro/Human.java b/src/ru/skypro/Human.java index 9764e8a..f4a640e 100644 --- a/src/ru/skypro/Human.java +++ b/src/ru/skypro/Human.java @@ -1,5 +1,7 @@ package ru.skypro; +import java.util.Objects; + public class Human { @Override public String toString() { @@ -12,10 +14,10 @@ public String toString() { private String town; public Human(Integer yearOfBirth, String name, String town, String position) { - this.yearOfBirth = yearOfBirth; - this.name = name; - this.town = town; - this.position = position; + this.yearOfBirth = Objects.requireNonNullElse(yearOfBirth, 0); + this.name = Objects.requireNonNullElse(name,"Информация не указана"); + this.town = Objects.requireNonNullElse(town,"Информация не указана"); + this.position = Objects.requireNonNullElse(position,"Информация не указана"); } public Integer getYearOfBirth() { diff --git a/src/ru/skypro/Main.java b/src/ru/skypro/Main.java index 3cba65e..6467436 100644 --- a/src/ru/skypro/Main.java +++ b/src/ru/skypro/Main.java @@ -5,7 +5,7 @@ public static void main(String[] args){ Human Максим = new Human(1987,"Максим","Минск","бренд-менеджер"); Human Аня = new Human(1993,"Аня","Москва","методист образовательных программ"); Human Катя = new Human(1994,"Катя","Калининград","продакт-менеджер"); - Human Артем = new Human(1995,"Артем","Москва","директор по развитию бизнеса"); + Human Артем = new Human(1995,"Артем",null,"директор по развитию бизнеса"); System.out.println(Максим); System.out.println(Аня); System.out.println(Катя); @@ -16,11 +16,13 @@ public static void main(String[] args){ Car car3 = new Car("BMW","Z8", "3.0л", "черный",2021,"Германия"); Car car4 = new Car("Kia","Sportage 4 поколение","2,4л" , "красный ", 2018, "Южная Корея"); Car car5 = new Car("Hyundai","Avante","1,6л", "оранжевый", 2016,"Южная Корея"); + Car car6 = new Car(); System.out.println(car1); System.out.println(car2); System.out.println(car3); System.out.println(car4); System.out.println(car5); + System.out.println(car6); }