esoe 2 years ago
parent
commit
cd8bceee40
  1. 55
      country/src/main/java/ru/molokoin/Area.java
  2. 24
      country/src/main/java/ru/molokoin/Conversion.java
  3. 15
      country/src/main/java/ru/molokoin/Country.java
  4. 4
      country/src/main/java/ru/molokoin/Map.java
  5. BIN
      country/target/classes/ru/molokoin/Area.class
  6. BIN
      country/target/classes/ru/molokoin/Conversion.class
  7. BIN
      country/target/classes/ru/molokoin/Country.class
  8. BIN
      country/target/classes/ru/molokoin/Map.class

55
country/src/main/java/ru/molokoin/Area.java

@ -6,16 +6,9 @@ public class Area {
private int square; private int square;
Area(){ Area(){
//TODO сделать инициализацию полей как объектов и последующий каст в нужный тип this(null, null, null);
//чтобы была возможность обрабатывать null поля
//this(null,null,null);
//Area (Object name, Object population, Object square){}
}
Area(Object name, int population, int square){
init(name, population, square);
} }
public void init(Object name, int population, int square){ Area(Object name, Object population, Object square){
setName(name); setName(name);
setPopulation(population); setPopulation(population);
setSquare(square); setSquare(square);
@ -33,34 +26,46 @@ public class Area {
try { try {
if (name == null) throw new NullPointerException(getName()); if (name == null) throw new NullPointerException(getName());
} catch (Exception e) { } catch (Exception e) {
System.out.println("Наименвание не должно быть пустым. ");
e.printStackTrace();
this.name = "";
}
try {
if((String)name == "")throw new IllegalArgumentException((String)name);
} catch (IllegalArgumentException e) {
System.out.println("Наименвание не должно быть пустым. ");
e.printStackTrace(); e.printStackTrace();
this.name = ""; this.name = "";
} } finally{
if (name != null) this.name = (String)name; if (name != null) this.name = (String)name;
} }
}
/** /**
* @param population the population to set * @param population the population to set
*/ */
public void setPopulation(int population) { public void setPopulation(Object population) {
try {
if (population == null) throw new NullPointerException("Параметр {население} не задан ...");
//население не может быть отрицательным } catch (NullPointerException e) {
if (population < 0) throw new IllegalArgumentException("Население не может быть отрицательным ..."); e.printStackTrace();
this.population = population; this.population = 0;
} finally{
this.population = (Integer) population;
}
} }
/** /**
* @param square the square to set * @param square the square to set
*/ */
public void setSquare(int square) { public void setSquare(Object square) {
if (square < 0) throw new IllegalArgumentException("площадь не может быть отрицательной ..."); try {
this.square = square; if (square == null) throw new NullPointerException("Параметр {площадь} не задан ...");
} catch (NullPointerException e) {
System.out.println("Наименвание не установлено ...");
e.printStackTrace();
this.square = 0;
} finally{
this.square = (Integer) square;
}
try {
if (this.square < 0) throw new IllegalArgumentException("площадь не может быть отрицательной ...");
} catch (IllegalArgumentException e) {
e.printStackTrace();
this.square = 0;
}
} }
/** /**
* @return the name * @return the name

24
country/src/main/java/ru/molokoin/Conversion.java

@ -1,24 +0,0 @@
package ru.molokoin;
public class Conversion {
/**
* Проверяем содержимое объекта.
*
* @param object
* @return
*/
public static Object checknull(Object object){
Object result = new Object();
if (object == null)throw new NullPointerException("Обнаружено пустое поле данных ...");
return (Object)result;
}
public static int toint(Object object){
String s = (String) object;
return Integer.parseInt(s);
}
public static String toString(Object object){
return "";
}
}

15
country/src/main/java/ru/molokoin/Country.java

@ -5,21 +5,22 @@ public class Country extends Area{
public Country() { public Country() {
} }
Country(String name, int population, int square){ Country(Object name, Object population, Object square){
//this(name, population, square, null, null, null); super(name, population, square);
//TODO исключить дублирование метода Area.init()
this.init(name, population, square);
} }
Country(String name, int population, int square, String capitalName, int capitalPopulation, int capitalSquare){ Country(String name, int population, int square, String capitalName, int capitalPopulation, int capitalSquare){
//параметры страны //параметры страны
this.init(name super(name, population, square);
, population
, square);
//параметры столицы //параметры столицы
if (capitalName != null) if (capitalName != null)
setCapital(new Area(capitalName setCapital(new Area(capitalName
, capitalPopulation , capitalPopulation
, capitalSquare)); , capitalSquare));
if (capitalName == null){
setCapital(new Area(null
, 0
, 0));
}
} }
public static void print(Country country){ public static void print(Country country){
System.out.println("-------------------------------------------"); System.out.println("-------------------------------------------");

4
country/src/main/java/ru/molokoin/Map.java

@ -10,13 +10,13 @@ public class Map {
//Финляндия //Финляндия
map[1] = new Country("Finland", 5500000, 338000, "Helsinki", 655000, 0); map[1] = new Country("Finland", 5500000, 338000, "Helsinki", 655000, 0);
//Франция //Франция
map[2] = new Country("France", 67800000, 643800, "Paris", 2100000, 0); map[4] = new Country("France", 67800000, 643800, "Paris", 2100000, 0);
//Андора //Андора
map[3] = new Country("Andorra", 85000, 647, "Andorra la Vella", 22600, 0); map[3] = new Country("Andorra", 85000, 647, "Andorra la Vella", 22600, 0);
//Сингапур //Сингапур
map[4] = new Country("Singapore", 5700000, 725, "", 0, 0); map[2] = new Country("Singapore", 5700000, 725, null, 0, 0);
} }
public static void printAll(Country[] map){ public static void printAll(Country[] map){
System.out.println("printAll"); System.out.println("printAll");

BIN
country/target/classes/ru/molokoin/Area.class

Binary file not shown.

BIN
country/target/classes/ru/molokoin/Conversion.class

Binary file not shown.

BIN
country/target/classes/ru/molokoin/Country.class

Binary file not shown.

BIN
country/target/classes/ru/molokoin/Map.class

Binary file not shown.
Loading…
Cancel
Save