Created
March 17, 2014 19:08
-
-
Save slava-konashkov/9606119 to your computer and use it in GitHub Desktop.
Создать список разработчиков и заполнить его случайным образом. Вывести на экран только Senior developer-ов с зарплатой больше 1500 у.е.
This file contains hidden or 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
| import java.util.Random; | |
| public class Main { | |
| private static Random random = new Random(); | |
| public static String randName() { | |
| StringBuilder sb = new StringBuilder(); | |
| int max = random.nextInt(20); | |
| sb.append((char) (65 + random.nextInt(26))); | |
| for (int i = 0; i < max; i++) { | |
| sb.append((char) (97 + random.nextInt(26))); | |
| } | |
| return sb.toString(); | |
| } | |
| public static void main(String[] args) { | |
| Developer[] list = new Developer[100]; | |
| for (int i = 0; i < 100; i++) { | |
| int iType = random.nextInt(4); | |
| switch (iType) { | |
| case 0: | |
| list[i] = new JuniorDeveloper(randName(), random.nextInt(3000), random.nextInt(10)); | |
| break; | |
| case 1: | |
| list[i] = new MiddleDeveloper(randName(), random.nextInt(3000), random.nextInt(10)); | |
| break; | |
| case 2: | |
| list[i] = new SeniorDeveloper(randName(), random.nextInt(3000), random.nextInt(10)); | |
| break; | |
| case 3: | |
| list[i] = new TeamLeadDeveloper(randName(), random.nextInt(3000), random.nextInt(10)); | |
| break; | |
| } | |
| } | |
| StringBuilder sb; | |
| for (Developer d : list) { | |
| if (d instanceof SeniorDeveloper && d.getSalary() > 1500) { | |
| sb = new StringBuilder() // !!! | |
| .append(d.getClass().getSimpleName()) | |
| .append(" is Name: ") | |
| .append(d.getName()) | |
| .append(": ") | |
| .append(d.getSalary()); | |
| System.out.println(sb.toString()); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment