Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/ru/skypro/Flower.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
60 changes: 60 additions & 0 deletions src/ru/skypro/Human.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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) {
if (yearOfBirth != null && yearOfBirth < 0) {
yearOfBirth = 0;
}
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) {
if (town != null && town.length() > 0) {
town = "Информация не указана";
}
this.town = town;
}

public String getPosition() {
return position;
}

public void setPosition(String position) {
this.position = position;
}
}
68 changes: 67 additions & 1 deletion src/ru/skypro/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,73 @@
package ru.skypro;

import ru.skypro.transport.Car;

import java.time.Year;

public class Main {
public static void main(String[] args){
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);

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() < lifeSpan)
lifeSpan = Хризантема.getLifeSpan();
if (numPion > 0 && Пион.getLifeSpan() < lifeSpan)
lifeSpan = Пион.getLifeSpan();
if (numGips > 0 && Гипсофила.getLifeSpan() < lifeSpan)
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);

Car.Key key = new Car.Key(true, true);
Car.Insurance insurance = new Car.Insurance(2012, 2000.2, "asdf22dsa2");
}
}
172 changes: 172 additions & 0 deletions src/ru/skypro/transport/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package ru.skypro.transport;

import java.time.Year;
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;

public static class Key {
private Boolean remoteStart;
private Boolean remoteAccess;

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);
}


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;
}
}