esoe 2 years ago
parent
commit
76a7b5f367
  1. BIN
      country/src/main/doc/j110-lab1.pdf
  2. 16
      country/src/main/java/ru/molokoin/Area.java
  3. 24
      country/src/main/java/ru/molokoin/Country.java
  4. 34
      country/src/main/java/ru/molokoin/Map.java
  5. BIN
      country/target/classes/ru/molokoin/Area.class
  6. BIN
      country/target/classes/ru/molokoin/Country.class
  7. BIN
      country/target/classes/ru/molokoin/Map.class

BIN
country/src/main/doc/j110-lab1.pdf

Binary file not shown.

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

@ -9,26 +9,35 @@ public class Area { @@ -9,26 +9,35 @@ public class Area {
Area(String name, int population, int square){
init(name, population, square);
}
public void init(String name, int population, int square){
setName(name);
setPopulation(population);
setSquare(square);
}
public void print(){
System.out.println("name: " + name + "; population:" + population + "; square: " + square);
if (name != "") System.out.println("name: " + name);
if (population > 0) System.out.println("population: " + population);
if (square > 0) System.out.println("square: " + square);
}
/**
* @param name the name to set
*/
public void setName(String name) {
try {
if(name == "")throw new IllegalArgumentException(name);
} catch (IllegalArgumentException e) {
System.out.println("Наименвание не должно быть пустым. ");
e.printStackTrace();
this.name = name;
}
this.name = name;
}
/**
* @param population the population to set
*/
public void setPopulation(int population) {
//население не может быть отрицательным
if (population < 0) throw new IllegalArgumentException("Население не может быть отрицательным ...");
this.population = population;
}
/**
@ -38,7 +47,6 @@ public class Area { @@ -38,7 +47,6 @@ public class Area {
if (square < 0) throw new IllegalArgumentException("площадь не может быть отрицательной ...");
this.square = square;
}
/**
* @return the name
*/

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

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

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

@ -1,32 +1,36 @@ @@ -1,32 +1,36 @@
package ru.molokoin;
public class Map {
private Country[] map = new Country[5];
public Country[] map;
//заполняем поля данными
public void initDefaults(){
System.out.println("map.length: " + map.length + " ...");
//заполняем поля данными
map[0] = new Country("Russia", 17100000, 146700000, "Moscow", 12600000, 0);
map[1] = new Country("Russia", 17100000, 146700000, "Moscow", 12600000, 0);
map[2] = new Country("Russia", 17100000, 146700000, "Moscow", 12600000, 0);
map[3] = new Country("Russia", 17100000, 146700000, "Moscow", 12600000, 0);
map[4] = new Country("Russia", 17100000, 146700000, "Moscow", 12600000, 0);
map = new Country[5];
//Россия
map[0] = new Country("Russia", 146700000, 17100000, "Moscow", 12600000, 0);
//Финляндия
map[1] = new Country("Finland", 5500000, 338000, "Helsinki", 655000, 0);
//Франция
map[2] = 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);
}
public static void print(Country[] map){
public static void printAll(Country[] map){
System.out.println("printAll");
System.out.println("Количество государств, данные о которых включены в terra: " + map.length);
int i = 0;
while (i < map.length) {
System.out.println("-------------------------------------------");
map[i].print();
map[i].getCapital().print();
System.out.println("-------------------------------------------");
Country.print(map[i]);
i++;
}
}
public static void main(String[] args) {
System.out.println("App.main()");
Map terra = new Map();
terra.initDefaults();
print(terra.map);
printAll(terra.map);
}
}

BIN
country/target/classes/ru/molokoin/Area.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