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

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

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

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

@ -10,13 +10,13 @@ public class Map { @@ -10,13 +10,13 @@ public class Map {
//Финляндия
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[4] = new Country("Singapore", 5700000, 725, "", 0, 0);
map[2] = new Country("Singapore", 5700000, 725, null, 0, 0);
}
public static void printAll(Country[] map){
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