diff --git a/src/ru/skypro/Flower.java b/src/ru/skypro/Flower.java new file mode 100644 index 0000000..d9abaa6 --- /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 new file mode 100644 index 0000000..bf0dc82 --- /dev/null +++ b/src/ru/skypro/Human.java @@ -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; + } +} diff --git a/src/ru/skypro/Main.java b/src/ru/skypro/Main.java index 625884e..da4b40e 100644 --- a/src/ru/skypro/Main.java +++ b/src/ru/skypro/Main.java @@ -1,7 +1,141 @@ package ru.skypro; +import ru.skypro.transport.Bus; +import ru.skypro.transport.Car; +import ru.skypro.transport.Train; + +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"); + + Train train1 = new Train( + "Ласточка", + " B-901", + 2011, + "России", + null, + 301, + 3500d, + null, + "Белорусского вокзала", + "Минск-Пассажирский", + 11 + ); + Train train2 = new Train( + "Ленинград", + "D-125", + 2019, + "России", + null, + 270, + 1700d, + null, + "Ленинградского вокзала", + "Ленинград-Пассажирский", + 8 + ); + System.out.println(train1); + System.out.println(train2); + Bus bus1 = new Bus( + null, + null, + null, + null, + null, + null, + 1, + 2, + 3 + ); + Bus bus2 = new Bus( + null, + null, + null, + null, + null, + null, + 4, + 5, + 6 + ); + Bus bus3 = new Bus( + null, + null, + null, + null, + null, + null, + 7, + 8, + 9 + ); + System.out.println(bus1); + System.out.println(bus2); + System.out.println(bus3); } } diff --git a/src/ru/skypro/animals/Main.java b/src/ru/skypro/animals/Main.java new file mode 100644 index 0000000..28abd7c --- /dev/null +++ b/src/ru/skypro/animals/Main.java @@ -0,0 +1,34 @@ +package ru.skypro.animals; + +import ru.skypro.animals.hierarchy.*; + +//Main class for test Part3 +public class Main { + public static void main(String[] args) { + var Albotros = new Flying("Albotros",4,"asd","walk"); + var Chaika = new Flying("Chaika",4,"asd","walk"); + var Sokol = new Flying("Sokol",4,"asd","walk"); + var Hiena = new Hischniki("Hiena",4,"asd",20,"asd"); + var Medved = new Hischniki("Medved",4,"asd",20,"asd"); + var Tigr = new Hischniki("Tigr",4,"asd",20,"asd"); + var Dodo = new NoFlying("Dodo",4,"asd","walk"); + var Pavlin = new NoFlying("Pavlin",4,"asd","walk"); + var Pingvin = new NoFlying("Pingvin",4,"asd","walk"); + var Gazel = new Travoyadnie("Gazel",4,"asd",12,"asd"); + var Loshad = new Travoyadnie("Loshad",4,"asd",13,"asd"); + var Zhiraf = new Travoyadnie("Zhiraf",4,"asd",14,"asd"); + var Fog = new Zemnovodnie("Fog",4,"asd"); + var Uzh = new Zemnovodnie("Uzh",4,"asd"); + System.out.println(Albotros); + } + + public static class CheckUtil { + + public static String checkString (String string, String elseString) { + return string == null || string.length() == 0 ? elseString: string; + } + public static Integer checkInteger (Integer integer, Integer elseInt) { + return integer == null || integer<0 ? elseInt: integer; + } + } +} diff --git a/src/ru/skypro/animals/hierarchy/Animal.java b/src/ru/skypro/animals/hierarchy/Animal.java new file mode 100644 index 0000000..04061d2 --- /dev/null +++ b/src/ru/skypro/animals/hierarchy/Animal.java @@ -0,0 +1,54 @@ +package ru.skypro.animals.hierarchy; + +import ru.skypro.animals.Main; + +import java.util.Objects; + +abstract class Animal { + private String klichka; + private Integer numYears; + protected abstract void eat(); + protected abstract void sleep(); + protected abstract void go(); + + public Animal(String klichka, Integer numYears) { + this.klichka = Main.CheckUtil.checkString(klichka,"klichka"); + this.numYears = Main.CheckUtil.checkInteger(numYears,5); + } + + @Override + public String toString() { + return "Animal{" + + "klichka='" + klichka + '\'' + + ", numYears=" + numYears + + '}'; + } + + public String getKlichka() { + return klichka; + } + + public void setKlichka(String klichka) { + this.klichka = Main.CheckUtil.checkString(klichka,"klichka"); + } + + public Integer getNumYears() { + return numYears; + } + + public void setNumYears(Integer numYears) { + this.numYears = numYears; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Animal animal)) return false; + return getKlichka().equals(animal.getKlichka()) && getNumYears().equals(animal.getNumYears()); + } + + @Override + public int hashCode() { + return Objects.hash(getKlichka(), getNumYears()); + } +} diff --git a/src/ru/skypro/animals/hierarchy/Birds.java b/src/ru/skypro/animals/hierarchy/Birds.java new file mode 100644 index 0000000..78bd990 --- /dev/null +++ b/src/ru/skypro/animals/hierarchy/Birds.java @@ -0,0 +1,58 @@ +package ru.skypro.animals.hierarchy; + +import ru.skypro.animals.Main; + +import java.util.Objects; + +abstract class Birds extends Animal{ + + private String area; + protected void hunt() {}; + + public Birds(String klichka, Integer numYears, String area) { + super(klichka,numYears); + this.area = Main.CheckUtil.checkString(area,"area"); + } + + @Override + public String toString() { + return "Birds{" + super.toString() + + "area='" + area + '\'' + + '}'; + } + + public String getArea() { + return area; + } + + public void setArea(String area) { + this.area = Main.CheckUtil.checkString(area,"area"); + } + @Override + protected void eat() { + + } + + @Override + protected void go() { + + } + + @Override + protected void sleep() { + + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Birds birds)) return false; + if (!super.equals(o)) return false; + return Objects.equals(getArea(), birds.getArea()); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), getArea()); + } +} diff --git a/src/ru/skypro/animals/hierarchy/Flying.java b/src/ru/skypro/animals/hierarchy/Flying.java new file mode 100644 index 0000000..45b41b8 --- /dev/null +++ b/src/ru/skypro/animals/hierarchy/Flying.java @@ -0,0 +1,55 @@ +package ru.skypro.animals.hierarchy; + +import ru.skypro.animals.Main; + +import java.util.Objects; + +public class Flying extends Birds{ + private String moveType; + protected void fly(){ + + }; + + public Flying(String klichka, Integer numYears, String area, String moveType) { + super(klichka, numYears, area); + this.moveType = Main.CheckUtil.checkString(moveType,"moveType"); + } + + @Override + public String toString() { + return "Flying{" + super.toString() + + "moveType='" + moveType + '\'' + + '}'; + } + + public String getMoveType() { + return moveType; + } + + public void setMoveType(String moveType) { + this.moveType = Main.CheckUtil.checkString(moveType,"moveType"); + } + + @Override + protected void go() { + super.go(); + } + + @Override + protected void eat() { + super.eat(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Flying flying)) return false; + if (!super.equals(o)) return false; + return Objects.equals(getMoveType(), flying.getMoveType()); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), getMoveType()); + } +} diff --git a/src/ru/skypro/animals/hierarchy/Hischniki.java b/src/ru/skypro/animals/hierarchy/Hischniki.java new file mode 100644 index 0000000..42319cf --- /dev/null +++ b/src/ru/skypro/animals/hierarchy/Hischniki.java @@ -0,0 +1,53 @@ +package ru.skypro.animals.hierarchy; + +import ru.skypro.animals.Main; + +import java.util.Objects; + +public class Hischniki extends Mlekopitaushie{ + private String typeOfPisha; + protected void hunt(){}; + + public Hischniki(String klichka, Integer numYears, String area, Integer speed, String typeOfPisha) { + super(klichka,numYears, area, speed); + this.typeOfPisha = Main.CheckUtil.checkString(typeOfPisha,"typeOfPisha"); + } + + @Override + public String toString() { + return "Hischniki{" + super.toString() + + "typeOfPisha='" + typeOfPisha + '\'' + + '}'; + } + + public String getTypeOfPisha() { + return typeOfPisha; + } + + public void setTypeOfPisha(String typeOfPisha) { + this.typeOfPisha = Main.CheckUtil.checkString(typeOfPisha,"typeOfPisha"); + } + + @Override + protected void go() { + super.go(); + } + + @Override + protected void eat() { + super.eat(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Hischniki hischniki)) return false; + if (!super.equals(o)) return false; + return Objects.equals(getTypeOfPisha(), hischniki.getTypeOfPisha()); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), getTypeOfPisha()); + } +} diff --git a/src/ru/skypro/animals/hierarchy/Mlekopitaushie.java b/src/ru/skypro/animals/hierarchy/Mlekopitaushie.java new file mode 100644 index 0000000..f978727 --- /dev/null +++ b/src/ru/skypro/animals/hierarchy/Mlekopitaushie.java @@ -0,0 +1,70 @@ +package ru.skypro.animals.hierarchy; + +import ru.skypro.animals.Main; + +import java.util.Objects; + +abstract class Mlekopitaushie extends Animal{ + private String area; + private Integer speed; + protected void walk(){ + + }; + + public Mlekopitaushie(String klichka, Integer numYears, String area, Integer speed) { + super(klichka, numYears); + this.area = Main.CheckUtil.checkString(area,"area"); + this.speed = Main.CheckUtil.checkInteger(speed,10); + } + + @Override + public String toString() { + return "Mlekopitaushie{" + super.toString() + + "area='" + area + '\'' + + ", speed=" + speed + + '}'; + } + + public String getArea() { + return area; + } + + public void setArea(String area) { + this.area = Main.CheckUtil.checkString(area,"area"); + } + + public Integer getSpeed() { + return speed; + } + + public void setSpeed(Integer speed) { + this.speed = Main.CheckUtil.checkInteger(speed,10); + } + @Override + protected void eat() { + + } + + @Override + protected void sleep() { + + } + + @Override + protected void go() { + + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Mlekopitaushie that)) return false; + if (!super.equals(o)) return false; + return Objects.equals(getArea(), that.getArea()) && Objects.equals(getSpeed(), that.getSpeed()); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), getArea(), getSpeed()); + } +} diff --git a/src/ru/skypro/animals/hierarchy/NoFlying.java b/src/ru/skypro/animals/hierarchy/NoFlying.java new file mode 100644 index 0000000..1263a0f --- /dev/null +++ b/src/ru/skypro/animals/hierarchy/NoFlying.java @@ -0,0 +1,53 @@ +package ru.skypro.animals.hierarchy; + +import ru.skypro.animals.Main; + +import java.util.Objects; + +public class NoFlying extends Birds { + private String moveType; + protected void walk(){}; + + public NoFlying(String klichka, Integer numYears, String area, String moveType) { + super(klichka,numYears, area); + this.moveType = Main.CheckUtil.checkString(moveType,"moveType"); + } + + @Override + public String toString() { + return "NoFlying{" + super.toString() + + "moveType='" + moveType + '\'' + + '}'; + } + + public String getMoveType() { + return moveType; + } + + public void setMoveType(String moveType) { + this.moveType = Main.CheckUtil.checkString(moveType,"moveType"); + } + + @Override + protected void go() { + super.go(); + } + + @Override + protected void eat() { + super.eat(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof NoFlying noFlying)) return false; + if (!super.equals(o)) return false; + return Objects.equals(getMoveType(), noFlying.getMoveType()); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), getMoveType()); + } +} diff --git a/src/ru/skypro/animals/hierarchy/Travoyadnie.java b/src/ru/skypro/animals/hierarchy/Travoyadnie.java new file mode 100644 index 0000000..b07948b --- /dev/null +++ b/src/ru/skypro/animals/hierarchy/Travoyadnie.java @@ -0,0 +1,53 @@ +package ru.skypro.animals.hierarchy; + +import ru.skypro.animals.Main; + +import java.util.Objects; + +public class Travoyadnie extends Mlekopitaushie { + private String typeOfPisha; + protected void pastis(){}; + + public Travoyadnie(String klichka, Integer numYears, String area, Integer speed, String typeOfPisha) { + super(klichka,numYears, area, speed); + this.typeOfPisha = Main.CheckUtil.checkString(typeOfPisha,"typeOfPisha"); + } + + @Override + public String toString() { + return "Travoyadnie{" + super.toString() + + "typeOfPisha='" + typeOfPisha + '\'' + + '}'; + } + + public String getTypeOfPisha() { + return typeOfPisha; + } + + public void setTypeOfPisha(String typeOfPisha) { + this.typeOfPisha = Main.CheckUtil.checkString(typeOfPisha,"typeOfPisha"); + } + + @Override + protected void go() { + super.go(); + } + + @Override + protected void eat() { + super.eat(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Travoyadnie that)) return false; + if (!super.equals(o)) return false; + return Objects.equals(getTypeOfPisha(), that.getTypeOfPisha()); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), getTypeOfPisha()); + } +} diff --git a/src/ru/skypro/animals/hierarchy/Zemnovodnie.java b/src/ru/skypro/animals/hierarchy/Zemnovodnie.java new file mode 100644 index 0000000..c50b97a --- /dev/null +++ b/src/ru/skypro/animals/hierarchy/Zemnovodnie.java @@ -0,0 +1,57 @@ +package ru.skypro.animals.hierarchy; + +import ru.skypro.animals.Main; + +import java.util.Objects; + +public class Zemnovodnie extends Animal{ + private String area; + protected void hunt(){}; + + public Zemnovodnie(String klichka, Integer numYears, String area) { + super(klichka,numYears); + this.area = Main.CheckUtil.checkString(area,"area"); + } + + @Override + public String toString() { + return "Zemnovodnie{" + super.toString() + + "area='" + area + '\'' + + '}'; + } + + public String getArea() { + return area; + } + + public void setArea(String area) { + this.area = Main.CheckUtil.checkString(area,"area"); + } + @Override + protected void eat() { + + } + + @Override + protected void go() { + + } + + @Override + protected void sleep() { + + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Zemnovodnie that)) return false; + if (!super.equals(o)) return false; + return Objects.equals(getArea(), that.getArea()); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), getArea()); + } +} diff --git a/src/ru/skypro/transport/Bus.java b/src/ru/skypro/transport/Bus.java new file mode 100644 index 0000000..e5135e6 --- /dev/null +++ b/src/ru/skypro/transport/Bus.java @@ -0,0 +1,54 @@ +package ru.skypro.transport; + +public class Bus extends Transport { + private Integer var1; + private Integer var2; + private Integer var3; + + public Bus(String brand, String model, Integer productionYear, String productionCountry, String color, Integer maxSpeed, Integer var1, Integer var2, Integer var3) { + super(brand, model, productionYear, productionCountry, color, maxSpeed); + this.var1 = var1; + this.var2 = var2; + this.var3 = var3; + } + + @Override + String refill() { + return "Объекты класса bus можно заправлять бензином или дизелем на заправк"; + } + + @Override + public String toString() { + return "Bus{" + + super.toString() + + "var1=" + var1 + + ", var2=" + var2 + + ", var3=" + var3 + + '}'+ + refill(); + } + + public Integer getVar1() { + return var1; + } + + public void setVar1(Integer var1) { + this.var1 = var1; + } + + public Integer getVar2() { + return var2; + } + + public void setVar2(Integer var2) { + this.var2 = var2; + } + + public Integer getVar3() { + return var3; + } + + public void setVar3(Integer var3) { + this.var3 = var3; + } +} diff --git a/src/ru/skypro/transport/Car.java b/src/ru/skypro/transport/Car.java new file mode 100644 index 0000000..5b91daf --- /dev/null +++ b/src/ru/skypro/transport/Car.java @@ -0,0 +1,145 @@ +package ru.skypro.transport; + +import java.time.Year; +import java.util.Objects; +import java.util.regex.Pattern; + +public class Car extends Transport { + private String engineVolume; + 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) { + super(brand, model, productionYear, productionCountry, color, 160); + this.engineVolume = engineVolume == null || engineVolume.equals("") ? " 1,5 л" : engineVolume; + 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 + String refill() { + return "Объекты класса car можно заправлять бензином, дизелем на заправке или заряжать на специальных электроду-парковках, если это электрокар."; + } + + @Override + public String toString() { + return "Car{" + + "brand='" + super.getBrand() + '\'' + + ", model='" + super.getModel() + '\'' + + ", engineVolume='" + engineVolume + '\'' + + ", color='" + super.getColor() + '\'' + + ", productionYear=" + super.getProductionYear() + + ", productionCountry='" + super.getProductionCountry() + '\'' + + ", transmission='" + transmission + '\'' + + ", bodyType='" + bodyType + '\'' + + ", registrationNumber='" + registrationNumber + '\'' + + ", numberOfSeats=" + numberOfSeats + + ", isSummerTiers=" + isSummerTiers + + '}'+refill(); + } + + + public String getEngineVolume() { + return engineVolume; + } + + 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 setTransmission(String transmission) { + this.transmission = transmission; + } + + public void setRegistrationNumber(String registrationNumber) { + this.registrationNumber = registrationNumber; + } + + public void setSummerTiers(Boolean summerTiers) { + isSummerTiers = summerTiers; + } +} diff --git a/src/ru/skypro/transport/Train.java b/src/ru/skypro/transport/Train.java new file mode 100644 index 0000000..2249369 --- /dev/null +++ b/src/ru/skypro/transport/Train.java @@ -0,0 +1,84 @@ +package ru.skypro.transport; + +public class Train extends Transport { + + private Double cost; + private Integer timeInMinutes; + private String startStantion; + private String endStantion; + private Integer numVagons; + + + public Train(String brand, String model, Integer productionYear, String productionCountry, String color, Integer maxSpeed, + Double cost, + Integer timeInMinutes, + String startStantion, + String endStantion, + Integer numVagons + ) { + super(brand, model, productionYear, productionCountry, color, maxSpeed); + this.cost = cost == null ? 120.0 : cost; + this.timeInMinutes = timeInMinutes == null ? 60 : timeInMinutes; + this.startStantion = startStantion == null ? "start" : startStantion; + this.endStantion = endStantion == null ? "end" : endStantion; + this.numVagons = numVagons == null ? 6 : numVagons; + + } + + @Override + String refill() { + return "Объекты класса train нужно заправлять дизелем."; + } + + @Override + public String toString() { + return "Train{" + + super.toString() + + "cost=" + cost + + ", timeInMinutes=" + timeInMinutes + + ", startStantion='" + startStantion + '\'' + + ", endStantion='" + endStantion + '\'' + + ", numVagons=" + numVagons + + '}'+refill(); + } + + public Double getCost() { + return cost; + } + + public void setCost(Double cost) { + this.cost = cost; + } + + public Integer getTimeInMinutes() { + return timeInMinutes; + } + + public void setTimeInMinutes(Integer timeInMinutes) { + this.timeInMinutes = timeInMinutes; + } + + public String getStartStantion() { + return startStantion; + } + + public void setStartStantion(String startStantion) { + this.startStantion = startStantion; + } + + public String getEndStantion() { + return endStantion; + } + + public void setEndStantion(String endStantion) { + this.endStantion = endStantion; + } + + public Integer getNumVagons() { + return numVagons; + } + + public void setNumVagons(Integer numVagons) { + this.numVagons = numVagons; + } +} diff --git a/src/ru/skypro/transport/Transport.java b/src/ru/skypro/transport/Transport.java new file mode 100644 index 0000000..695e3cc --- /dev/null +++ b/src/ru/skypro/transport/Transport.java @@ -0,0 +1,73 @@ +package ru.skypro.transport; + +public abstract class Transport { + private String brand; + private String model; + private final Integer productionYear; + private final String productionCountry; + private String color; + private Integer maxSpeed; + + abstract String refill(); + + public Transport(String brand, String model, Integer productionYear, String productionCountry, String color, Integer maxSpeed) { + this.brand = brand == null || brand.equals("") ? "default" : brand; + this.model = model == null || model.equals("") ? "default" : model; + this.color = color == null || color.equals("") ? "белый" : color; + this.productionYear = productionYear == null || productionYear <= 0 ? 2000 : productionYear; + this.productionCountry = productionCountry == null || productionCountry.equals("") ? "default" : productionCountry; + this.maxSpeed = maxSpeed == null || maxSpeed < 0 ? 0 : maxSpeed; + } + + @Override + public String toString() { + return "Transport{" + + "brand='" + brand + '\'' + + ", model='" + model + '\'' + + ", productionYear=" + productionYear + + ", productionCountry='" + productionCountry + '\'' + + ", color='" + color + '\'' + + ", maxSpeed=" + maxSpeed + + '}'; + } + + public String getBrand() { + return brand; + } + + public String getModel() { + return model; + } + + public Integer getProductionYear() { + return productionYear; + } + + public String getProductionCountry() { + return productionCountry; + } + + public String getColor() { + return color; + } + + public Integer getMaxSpeed() { + return maxSpeed; + } + + public void setBrand(String brand) { + this.brand = brand == null || brand.equals("") ? "default" : brand; + } + + public void setModel(String model) { + this.model = model == null || model.equals("") ? "default" : model; + } + + public void setColor(String color) { + this.color = color == null || color.equals("") ? "белый" : color; + } + + public void setMaxSpeed(Integer maxSpeed) { + this.maxSpeed = maxSpeed == null || maxSpeed < 0 ? 0 : maxSpeed; + } +}