diff --git a/lesson1.maraphon/Animal.java b/lesson1.maraphon/Animal.java index ace66bd..686aec1 100644 --- a/lesson1.maraphon/Animal.java +++ b/lesson1.maraphon/Animal.java @@ -58,4 +58,5 @@ public boolean isDistance() { public void info() { System.out.println(type + " " +name+ " "+ onDistance); } + } diff --git a/lesson1.maraphon/Cource.java b/lesson1.maraphon/Cource.java index b30ff47..46db634 100644 --- a/lesson1.maraphon/Cource.java +++ b/lesson1.maraphon/Cource.java @@ -2,11 +2,23 @@ public class Cource { - Obstracle[] c = {new Cross(80),new Wall(5),new Water(3)}; + private Obstracle[] c = {new Cross(80),new Wall(5),new Water(3)}; + + public void doIt(Team team){ + System.out.println("Команда: " + team); + for (Competitor competitor : team.getCompetitors()) { + for (Obstracle obstracle : c) { + if (competitor.isDistance() == true) { + System.out.println(team.getCompetitors() + " успешно перепрыгнул"); + obstracle.doIt(competitor); + } else { + System.out.println(team.getCompetitors() + " не получилось"); + } + } + } - public void doIt(){ - Cross(80); - Wall(5); - Water(3); } + + } + diff --git a/lesson1.maraphon/Human.java b/lesson1.maraphon/Human.java index cd1f10b..a2f7e98 100644 --- a/lesson1.maraphon/Human.java +++ b/lesson1.maraphon/Human.java @@ -56,4 +56,8 @@ public boolean isDistance() { public void info() { System.out.println(name + " " + active); } + + public String getName() { + return name; + } } diff --git a/lesson1.maraphon/MainCross.java b/lesson1.maraphon/MainCross.java index 6275898..1411d87 100644 --- a/lesson1.maraphon/MainCross.java +++ b/lesson1.maraphon/MainCross.java @@ -5,10 +5,12 @@ public class MainCross { public static void main(String[] args) { Cource c = new Cource (); - Team comp = new Team (); + Team comp = new Team ("1" , new Human("Bob"), new Cat("Vaska"), new Dog("Tuzik") ); c.doIt(comp); + + /* Competitor[] competitors = {new Human("Bob"), new Cat("Vaska"),new Dog("Tuzik")}; Obstracle[] obstracles = {new Cross(80),new Wall(5),new Water(3)}; for(Competitor c: competitors){ diff --git a/lesson1.maraphon/Team.java b/lesson1.maraphon/Team.java index 2dbf64b..67d5d65 100644 --- a/lesson1.maraphon/Team.java +++ b/lesson1.maraphon/Team.java @@ -1,7 +1,19 @@ package lesson1.maraphon; public class Team { - Competitor[] comp = {new Human("Bob"), new Cat("Vaska"),new Dog("Tuzik")}; + + private String name; + private Competitor[] competitors; + + public Team (String name, Competitor... competitors){ + this.name = name; + this.competitors = competitors; + } + + + public Competitor[] getCompetitors() { + return competitors; + } } diff --git a/lesson2/arrayExceprion/main.java b/lesson2/arrayExceprion/main.java new file mode 100644 index 0000000..92de2fb --- /dev/null +++ b/lesson2/arrayExceprion/main.java @@ -0,0 +1,47 @@ +package lesson2.arrayException; + +public class main { + public static void main(String[] args) { + + String[][] weekDays = { {"1","2","3","4"},{"5","6","7","8"}}; + try { + Arr(weekDays); + } catch (ArrayIndexOutOfBoundsException | NumberFormatException e) { + System.out.println(e); + } + } + + public static void Arr(String a[][]) { + int[][] pars = new int[a.length][]; // массив для преобразования + int sum = 0; // переменная для суммирования + + for (int i = 0; i < a.length; i++) { + pars[i] = new int[a[i].length]; + + for (int j = 0; j < a[i].length; j++) { + try { + pars[i][j] = Integer.parseInt(a[i][j]) ; + + } catch (NumberFormatException e) {} + System.out.print(pars[i][j] + " "); + } + } + + try { + + for (int i = 0; i < pars.length; i++) { + for (int j = 0; j < pars[i].length; j++) { + sum = sum + pars[i][j]; + } + } + }catch (ArithmeticException e) { + System.out.println(""); + } + System.out.println("\n" + "----------"); + System.out.println("Сумма всех элементов = " + sum); + } + + + } + +