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/5] 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/5] 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); } From 3987d22a6d9247627bedbc09cb0b5c48a5f7978d 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: Sat, 8 Oct 2022 02:33:47 +0300 Subject: [PATCH 3/5] part 1 --- src/ru/skypro/Flower.java | 55 +++++++++++++++++++++++++++++++++++++++ src/ru/skypro/Human.java | 7 ++++- src/ru/skypro/Main.java | 35 +++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/ru/skypro/Flower.java diff --git a/src/ru/skypro/Flower.java b/src/ru/skypro/Flower.java new file mode 100644 index 0000000..c340b4e --- /dev/null +++ b/src/ru/skypro/Flower.java @@ -0,0 +1,55 @@ +package ru.skypro; + +import java.util.Objects; + +public class Flower { + + private String name; + private String flowerColor; + private String country; + private Double cost; + private Integer lifeSpan; + + public Flower(String name, String flowerColor, String country, Double cost, Integer lifeSpan) { + this.name = name; + this.flowerColor = flowerColor == null || flowerColor.equals("") ?"Белый":flowerColor; + this.country = country == null || country.equals("") ?"Россия":country; + this.cost = cost == null || cost < 0 ? 1 : Math.round(cost*100)/100d ; + this.lifeSpan = lifeSpan == null || lifeSpan <=0 ? 3 : lifeSpan; + } + + @Override + public String toString() { + return "Flower{" + + "name='" + name + '\'' + + ", flowerColor='" + flowerColor + '\'' + + ", country='" + country + '\'' + + ", cost=" + cost + + ", lifeSpan=" + lifeSpan + + '}'; + } + + public void setLifeSpan(Integer lifeSpan) { + this.lifeSpan = lifeSpan; + } + + public String getFlowerColor() { + return flowerColor; + } + + public String getCountry() { + return country; + } + + public Double getCost() { + return cost; + } + + public Integer getLifeSpan() { + return lifeSpan; + } + + public String getName() { + return name; + } +} diff --git a/src/ru/skypro/Human.java b/src/ru/skypro/Human.java index f4a640e..4f0b818 100644 --- a/src/ru/skypro/Human.java +++ b/src/ru/skypro/Human.java @@ -25,7 +25,9 @@ public Integer getYearOfBirth() { } public void setYearOfBirth(Integer yearOfBirth) { - this.yearOfBirth = yearOfBirth; + if (yearOfBirth != null && yearOfBirth<0) { + yearOfBirth = 0; + }this.yearOfBirth = yearOfBirth; } public String getName() { @@ -41,6 +43,9 @@ public String getTown() { } public void setTown(String town) { + if (town != null && town.length()>0) { + town = "Информация не указана"; + } this.town = town; } diff --git a/src/ru/skypro/Main.java b/src/ru/skypro/Main.java index 6467436..c961360 100644 --- a/src/ru/skypro/Main.java +++ b/src/ru/skypro/Main.java @@ -1,5 +1,7 @@ package ru.skypro; +import java.time.Year; + public class Main { public static void main(String[] args){ Human Максим = new Human(1987,"Максим","Минск","бренд-менеджер"); @@ -24,6 +26,39 @@ public static void main(String[] args){ System.out.println(car5); System.out.println(car6); + Human Владимир = new Human(Year.now().getValue()-21,"Владимир","Казань",null); + System.out.println(Владимир); + + Flower РозаОбыкновенная = new Flower("Роза обыкновенная",null,"Голландия",35.59,null); + Flower Хризантема = new Flower("Хризантема",null,null,15.0,5); + Flower Пион = new Flower("Пион",null,"Англия",69.9,1); + Flower Гипсофила = new Flower("Гипсофила",null,"Турция",19.5,10); + System.out.println(РозаОбыкновенная); + System.out.println(Хризантема); + System.out.println(Пион); + System.out.println(Гипсофила); + int numRose = 3; + int numChris = 5; + int numPion = 0; + int numGips = 1; + Double flowerPrice = + Math.round( + 1.1* //+10% + (numRose* РозаОбыкновенная.getCost()+ + numChris* Хризантема.getCost()+ + numPion* Пион.getCost()+ + numGips* Гипсофила.getCost()) //getCost + *100)/100d; //Todo: Загуглить другую функцию округления + int lifeSpan = 0; + if (numRose > 0) + lifeSpan = РозаОбыкновенная.getLifeSpan(); + if (numChris > 0 && Хризантема.getLifeSpan() 0 && Пион.getLifeSpan() 0 && Гипсофила.getLifeSpan() Date: Sat, 8 Oct 2022 03:06:04 +0300 Subject: [PATCH 4/5] part 2 --- src/ru/skypro/Car.java | 88 -------------------- src/ru/skypro/Main.java | 7 ++ src/ru/skypro/transport/Car.java | 134 +++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 88 deletions(-) delete mode 100644 src/ru/skypro/Car.java create mode 100644 src/ru/skypro/transport/Car.java diff --git a/src/ru/skypro/Car.java b/src/ru/skypro/Car.java deleted file mode 100644 index 2184706..0000000 --- a/src/ru/skypro/Car.java +++ /dev/null @@ -1,88 +0,0 @@ -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/Main.java b/src/ru/skypro/Main.java index c961360..4b08ff6 100644 --- a/src/ru/skypro/Main.java +++ b/src/ru/skypro/Main.java @@ -1,5 +1,7 @@ package ru.skypro; +import ru.skypro.transport.Car; + import java.time.Year; public class Main { @@ -60,5 +62,10 @@ public static void main(String[] args){ lifeSpan = Гипсофила.getLifeSpan(); System.out.println("будет стоить "+flowerPrice+" рублей и простоит "+lifeSpan+" суток. "); + + Car car7 = new Car("Lada","Grande","1,7л", "желтый", 2015,"Россия" + , null, null, "A000XX000", null, null); + System.out.println(car7); + } } diff --git a/src/ru/skypro/transport/Car.java b/src/ru/skypro/transport/Car.java new file mode 100644 index 0000000..cca00e3 --- /dev/null +++ b/src/ru/skypro/transport/Car.java @@ -0,0 +1,134 @@ +package ru.skypro.transport; + +import java.util.Objects; +import java.util.regex.Pattern; + +public class Car { + private String brand; + private String model; + private String engineVolume; + private String color; + private Integer productionYear; + private String productionCountry; + private String transmission; + private String bodyType; + private String registrationNumber; + private Integer numberOfSeats; + private Boolean isSummerTiers; + + + private Boolean checkRegistrationNumber(String registrationNumber){ + if (registrationNumber == null || registrationNumber.length() == 0) + return false; + return Pattern.matches("\\D\\d\\d\\d\\D\\D\\d\\d\\d",registrationNumber); + } + + + public Car(String brand, String model, String engineVolume, String color, Integer productionYear, String productionCountry, + String transmission, String bodyType, String registrationNumber, Integer numberOfSeats, Boolean isSummerTiers) { + this.brand = brand == null || brand.equals("") ?"default":brand; + this.model = model == null || model.equals("") ?"default":model; + this.engineVolume = engineVolume == null || engineVolume.equals("") ?" 1,5 л":engineVolume; + this.color = color == null || color.equals("") ?"белый":color; + this.productionYear = productionYear == null || productionYear<=0 ?2000:productionYear; + this.productionCountry = productionCountry == null || productionCountry.equals("") ?"default":productionCountry; + this.transmission = transmission == null || transmission.equals("") ?"default":transmission; + this.bodyType = bodyType == null || bodyType.equals("") ?"default":bodyType; + this.registrationNumber = !checkRegistrationNumber(registrationNumber) ?"X000XX000":registrationNumber; + this.numberOfSeats = numberOfSeats == null || numberOfSeats<=0 ?4:numberOfSeats; + this.isSummerTiers = isSummerTiers == null || isSummerTiers; + } + + public Car(String brand, String model, String engineVolume, String color, Integer productionYear, String productionCountry) { + this(brand,model,engineVolume,color,productionYear,productionCountry,null,null,null,null,null); + } + + public Car() { + this(null,null,null,null,null,null); + } + + public void swapTiers(){ + this.isSummerTiers = !this.isSummerTiers; + } + + @Override + public String toString() { + return "Car{" + + "brand='" + brand + '\'' + + ", model='" + model + '\'' + + ", engineVolume='" + engineVolume + '\'' + + ", color='" + color + '\'' + + ", productionYear=" + productionYear + + ", productionCountry='" + productionCountry + '\'' + + ", transmission='" + transmission + '\'' + + ", bodyType='" + bodyType + '\'' + + ", registrationNumber='" + registrationNumber + '\'' + + ", numberOfSeats=" + numberOfSeats + + ", isSummerTiers=" + isSummerTiers + + '}'; + } + + public String getBrand() { + return brand; + } + + public String getModel() { + return model; + } + + public String getEngineVolume() { + return engineVolume; + } + + public String getColor() { + return color; + } + + public Integer getProductionYear() { + return productionYear; + } + + public String getProductionCountry() { + return productionCountry; + } + + public String getTransmission() { + return transmission; + } + + public String getBodyType() { + return bodyType; + } + + public String getRegistrationNumber() { + return registrationNumber; + } + + public Integer getNumberOfSeats() { + return numberOfSeats; + } + + public Boolean getSummerTiers() { + return isSummerTiers; + } + + public void setEngineVolume(String engineVolume) { + this.engineVolume = engineVolume; + } + + public void setColor(String color) { + this.color = color; + } + + public void setTransmission(String transmission) { + this.transmission = transmission; + } + + public void setRegistrationNumber(String registrationNumber) { + this.registrationNumber = registrationNumber; + } + + public void setSummerTiers(Boolean summerTiers) { + isSummerTiers = summerTiers; + } +} From 1e2c276d1ee964294670e7aad34b2e990a7c0b38 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: Sat, 8 Oct 2022 03:31:20 +0300 Subject: [PATCH 5/5] part 3 --- src/ru/skypro/Flower.java | 8 ++-- src/ru/skypro/Human.java | 15 +++---- src/ru/skypro/Main.java | 56 +++++++++++++------------ src/ru/skypro/transport/Car.java | 70 ++++++++++++++++++++++++-------- 4 files changed, 95 insertions(+), 54 deletions(-) diff --git a/src/ru/skypro/Flower.java b/src/ru/skypro/Flower.java index c340b4e..d9abaa6 100644 --- a/src/ru/skypro/Flower.java +++ b/src/ru/skypro/Flower.java @@ -12,10 +12,10 @@ public class Flower { public Flower(String name, String flowerColor, String country, Double cost, Integer lifeSpan) { this.name = name; - this.flowerColor = flowerColor == null || flowerColor.equals("") ?"Белый":flowerColor; - this.country = country == null || country.equals("") ?"Россия":country; - this.cost = cost == null || cost < 0 ? 1 : Math.round(cost*100)/100d ; - this.lifeSpan = lifeSpan == null || lifeSpan <=0 ? 3 : lifeSpan; + this.flowerColor = flowerColor == null || flowerColor.equals("") ? "Белый" : flowerColor; + this.country = country == null || country.equals("") ? "Россия" : country; + this.cost = cost == null || cost < 0 ? 1 : Math.round(cost * 100) / 100d; + this.lifeSpan = lifeSpan == null || lifeSpan <= 0 ? 3 : lifeSpan; } @Override diff --git a/src/ru/skypro/Human.java b/src/ru/skypro/Human.java index 4f0b818..bf0dc82 100644 --- a/src/ru/skypro/Human.java +++ b/src/ru/skypro/Human.java @@ -5,7 +5,7 @@ public class Human { @Override public String toString() { - return "Привет! Меня зовут "+name+". Я из города "+town+". Я родился в "+yearOfBirth+" году. Будем знакомы! Я работаю на должности "+position+" . Будем знакомы!"; + return "Привет! Меня зовут " + name + ". Я из города " + town + ". Я родился в " + yearOfBirth + " году. Будем знакомы! Я работаю на должности " + position + " . Будем знакомы!"; } private Integer yearOfBirth; @@ -15,9 +15,9 @@ public String toString() { 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,"Информация не указана"); + this.name = Objects.requireNonNullElse(name, "Информация не указана"); + this.town = Objects.requireNonNullElse(town, "Информация не указана"); + this.position = Objects.requireNonNullElse(position, "Информация не указана"); } public Integer getYearOfBirth() { @@ -25,9 +25,10 @@ public Integer getYearOfBirth() { } public void setYearOfBirth(Integer yearOfBirth) { - if (yearOfBirth != null && yearOfBirth<0) { + if (yearOfBirth != null && yearOfBirth < 0) { yearOfBirth = 0; - }this.yearOfBirth = yearOfBirth; + } + this.yearOfBirth = yearOfBirth; } public String getName() { @@ -43,7 +44,7 @@ public String getTown() { } public void setTown(String town) { - if (town != null && town.length()>0) { + if (town != null && town.length() > 0) { town = "Информация не указана"; } this.town = town; diff --git a/src/ru/skypro/Main.java b/src/ru/skypro/Main.java index 4b08ff6..14f8ce3 100644 --- a/src/ru/skypro/Main.java +++ b/src/ru/skypro/Main.java @@ -5,21 +5,21 @@ import java.time.Year; 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,"директор по развитию бизнеса"); + 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 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); @@ -28,13 +28,13 @@ public static void main(String[] args){ System.out.println(car5); System.out.println(car6); - Human Владимир = new Human(Year.now().getValue()-21,"Владимир","Казань",null); + Human Владимир = new Human(Year.now().getValue() - 21, "Владимир", "Казань", null); System.out.println(Владимир); - Flower РозаОбыкновенная = new Flower("Роза обыкновенная",null,"Голландия",35.59,null); - Flower Хризантема = new Flower("Хризантема",null,null,15.0,5); - Flower Пион = new Flower("Пион",null,"Англия",69.9,1); - Flower Гипсофила = new Flower("Гипсофила",null,"Турция",19.5,10); + Flower РозаОбыкновенная = new Flower("Роза обыкновенная", null, "Голландия", 35.59, null); + Flower Хризантема = new Flower("Хризантема", null, null, 15.0, 5); + Flower Пион = new Flower("Пион", null, "Англия", 69.9, 1); + Flower Гипсофила = new Flower("Гипсофила", null, "Турция", 19.5, 10); System.out.println(РозаОбыкновенная); System.out.println(Хризантема); System.out.println(Пион); @@ -45,27 +45,29 @@ public static void main(String[] args){ int numGips = 1; Double flowerPrice = Math.round( - 1.1* //+10% - (numRose* РозаОбыкновенная.getCost()+ - numChris* Хризантема.getCost()+ - numPion* Пион.getCost()+ - numGips* Гипсофила.getCost()) //getCost - *100)/100d; //Todo: Загуглить другую функцию округления + 1.1 * //+10% + (numRose * РозаОбыкновенная.getCost() + + numChris * Хризантема.getCost() + + numPion * Пион.getCost() + + numGips * Гипсофила.getCost()) //getCost + * 100) / 100d; //Todo: Загуглить другую функцию округления int lifeSpan = 0; if (numRose > 0) lifeSpan = РозаОбыкновенная.getLifeSpan(); - if (numChris > 0 && Хризантема.getLifeSpan() 0 && Хризантема.getLifeSpan() < lifeSpan) lifeSpan = Хризантема.getLifeSpan(); - if (numPion > 0 && Пион.getLifeSpan() 0 && Пион.getLifeSpan() < lifeSpan) lifeSpan = Пион.getLifeSpan(); - if (numGips > 0 && Гипсофила.getLifeSpan() 0 && Гипсофила.getLifeSpan() < lifeSpan) lifeSpan = Гипсофила.getLifeSpan(); - System.out.println("будет стоить "+flowerPrice+" рублей и простоит "+lifeSpan+" суток. "); + System.out.println("будет стоить " + flowerPrice + " рублей и простоит " + lifeSpan + " суток. "); - Car car7 = new Car("Lada","Grande","1,7л", "желтый", 2015,"Россия" - , null, null, "A000XX000", null, null); + Car car7 = new Car("Lada", "Grande", "1,7л", "желтый", 2015, "Россия" + , null, null, "A000XX000", null, null); System.out.println(car7); + Car.Key key = new Car.Key(true, true); + Car.Insurance insurance = new Car.Insurance(2012, 2000.2, "asdf22dsa2"); } } diff --git a/src/ru/skypro/transport/Car.java b/src/ru/skypro/transport/Car.java index cca00e3..7f34cf6 100644 --- a/src/ru/skypro/transport/Car.java +++ b/src/ru/skypro/transport/Car.java @@ -1,5 +1,6 @@ package ru.skypro.transport; +import java.time.Year; import java.util.Objects; import java.util.regex.Pattern; @@ -16,38 +17,75 @@ public class Car { private Integer numberOfSeats; private Boolean isSummerTiers; + public static class Key { + private Boolean remoteStart; + private Boolean remoteAccess; - private Boolean checkRegistrationNumber(String registrationNumber){ + public Key(Boolean remoteStart, Boolean remoteAccess) { + this.remoteStart = remoteStart != null && remoteStart; + this.remoteAccess = remoteAccess != null && remoteAccess; + } + } + + public static class Insurance { + private Integer period; + private Double cost; + private String number; + + public Boolean isExpired() { + return this.period < Year.now().getValue(); + } + + private Boolean checkNumber(String number) { + if (number == null || number.length() == 0) { + return false; + } + return Pattern.matches("^.{9}$", number); + } + + public Insurance(Integer period, Double cost, String number) { + this.period = period == null ? 0 : period; + this.cost = cost == null ? 1.0 : cost; + this.number = number; + if (this.isExpired()) + System.out.println("нужно срочно ехать оформлять новую страховку."); + if (!checkNumber(number)) + System.out.println("Номер страховки некорректный!"); + } + + } + + private Boolean checkRegistrationNumber(String registrationNumber) { if (registrationNumber == null || registrationNumber.length() == 0) return false; - return Pattern.matches("\\D\\d\\d\\d\\D\\D\\d\\d\\d",registrationNumber); + return Pattern.matches("\\D\\d\\d\\d\\D\\D\\d\\d\\d", registrationNumber); } public Car(String brand, String model, String engineVolume, String color, Integer productionYear, String productionCountry, - String transmission, String bodyType, String registrationNumber, Integer numberOfSeats, Boolean isSummerTiers) { - this.brand = brand == null || brand.equals("") ?"default":brand; - this.model = model == null || model.equals("") ?"default":model; - this.engineVolume = engineVolume == null || engineVolume.equals("") ?" 1,5 л":engineVolume; - this.color = color == null || color.equals("") ?"белый":color; - this.productionYear = productionYear == null || productionYear<=0 ?2000:productionYear; - this.productionCountry = productionCountry == null || productionCountry.equals("") ?"default":productionCountry; - this.transmission = transmission == null || transmission.equals("") ?"default":transmission; - this.bodyType = bodyType == null || bodyType.equals("") ?"default":bodyType; - this.registrationNumber = !checkRegistrationNumber(registrationNumber) ?"X000XX000":registrationNumber; - this.numberOfSeats = numberOfSeats == null || numberOfSeats<=0 ?4:numberOfSeats; + String transmission, String bodyType, String registrationNumber, Integer numberOfSeats, Boolean isSummerTiers) { + this.brand = brand == null || brand.equals("") ? "default" : brand; + this.model = model == null || model.equals("") ? "default" : model; + this.engineVolume = engineVolume == null || engineVolume.equals("") ? " 1,5 л" : engineVolume; + this.color = color == null || color.equals("") ? "белый" : color; + this.productionYear = productionYear == null || productionYear <= 0 ? 2000 : productionYear; + this.productionCountry = productionCountry == null || productionCountry.equals("") ? "default" : productionCountry; + this.transmission = transmission == null || transmission.equals("") ? "default" : transmission; + this.bodyType = bodyType == null || bodyType.equals("") ? "default" : bodyType; + this.registrationNumber = !checkRegistrationNumber(registrationNumber) ? "X000XX000" : registrationNumber; + this.numberOfSeats = numberOfSeats == null || numberOfSeats <= 0 ? 4 : numberOfSeats; this.isSummerTiers = isSummerTiers == null || isSummerTiers; } public Car(String brand, String model, String engineVolume, String color, Integer productionYear, String productionCountry) { - this(brand,model,engineVolume,color,productionYear,productionCountry,null,null,null,null,null); + this(brand, model, engineVolume, color, productionYear, productionCountry, null, null, null, null, null); } public Car() { - this(null,null,null,null,null,null); + this(null, null, null, null, null, null); } - public void swapTiers(){ + public void swapTiers() { this.isSummerTiers = !this.isSummerTiers; }