diff --git a/src/ru/skypro/Car.java b/src/ru/skypro/Car.java new file mode 100644 index 0000000..2184706 --- /dev/null +++ b/src/ru/skypro/Car.java @@ -0,0 +1,88 @@ +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 = 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{" + + "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..f4a640e --- /dev/null +++ b/src/ru/skypro/Human.java @@ -0,0 +1,54 @@ +package ru.skypro; + +import java.util.Objects; + +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 = Objects.requireNonNullElse(yearOfBirth, 0); + this.name = Objects.requireNonNullElse(name,"Информация не указана"); + this.town = Objects.requireNonNullElse(town,"Информация не указана"); + this.position = Objects.requireNonNullElse(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..6467436 100644 --- a/src/ru/skypro/Main.java +++ b/src/ru/skypro/Main.java @@ -2,6 +2,28 @@ 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,"Артем",null,"директор по развитию бизнеса"); + 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,"Южная Корея"); + 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); + } }