Created
March 19, 2016 12:55
-
-
Save FaAway/1295202f47f1ea3e5a0b to your computer and use it in GitHub Desktop.
javarush level30.lesson06.task01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level30.lesson06.task01; | |
import java.util.ArrayList; | |
import java.util.List; | |
/* Такие хитрые исключения! | |
Исправьте реализацию метода checkAFlag, чтобы во всех случаях он не приводил к бросанию исключений. | |
Сохраните логику вывода данных. | |
Метод main не участвует в тестировании. | |
*/ | |
public class Solution { | |
public static void main(String[] args) { | |
checkAFlag(new D()); | |
} | |
public static void checkAFlag(D d) { | |
if(d != null && d.cs != null && d.cs.size() > 0 && d.cs.get(0).bs != null && | |
d.cs.get(0).bs.size() > 0 && d.cs.get(0).bs.get(0) != null && d.cs.get(0).bs.get(0).as != null && | |
d.cs.get(0).bs.get(0).as.size() > 0 && d.cs.get(0).bs.get(0).as.get(0) != null) | |
{ | |
System.out.println("A's flag is true"); | |
} else { //all other cases | |
System.out.println("Oops!"); | |
} | |
} | |
static class A { | |
boolean flag = true; | |
} | |
static class B { | |
List<A> as = new ArrayList<>(); | |
{ | |
as.add(new A()); | |
} | |
} | |
static class C { | |
List<B> bs = new ArrayList<>(); | |
{ | |
bs.add(new B()); | |
} | |
} | |
static class D { | |
List<C> cs = new ArrayList<>(); | |
{ | |
cs.add(new C()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment