Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Homework5 {
  4.  
  5.     public static void main(String[] args) {
  6.         //Создаем переменную и сканнер для сортировки по возрасту
  7.         int age =0;
  8.         Scanner sc = new Scanner(System.in);
  9.  
  10.         //Первая часть задания.
  11.         Sotrydnik sotr1 = new Sotrydnik("Иванов Иван Иванович", "Инженер" ,
  12.                 "111@111.ru", "89167067716", 120000, 41);
  13.         System.out.println(sotr1.getFio() + " " + sotr1.getSpec() + " " + sotr1.getEmail()
  14.                 + " " + sotr1.getNumTel() + " " + sotr1.getCash() + " " +sotr1.getAge());
  15.  
  16.         //Вторая часть задания.
  17.         Sotrydnik[] persArray = new Sotrydnik[5];
  18.         persArray[0] = new Sotrydnik("Петров Петр Петрович", "Электрик",
  19.                 "222@222.ru", "89232232323", 60000, 43);
  20.         persArray[1] = new Sotrydnik("Павлов Павел Павлович", "Технолог",
  21.                 "333@333.ru", "89655521212", 60000, 35);
  22.         persArray[2] = new Sotrydnik("Коренков Иван Иванович", "К.Качества",
  23.                 "444@444.ru", "9164433434", 60000, 27);
  24.         persArray[3] = new Sotrydnik("Еврейкин Еврей Евреев", "Бухгалтер",
  25.                 "555@555.ru", "89653321212", 60000, 41);
  26.         persArray[4] = new Sotrydnik("Ануфриев Валентин Валентинович", "Менеджер",
  27.                 "666@666.ru","89653445454", 35000,26);
  28.  
  29.         System.out.println("Введите возраст сотрудника: ");
  30.         age = sc.nextInt();
  31.  
  32.         System.out.println();
  33.        
  34.         //сортировка по возрасту.
  35.         //смотрим что пришло из консоли и сравниваем с age в массиве persArray.
  36.         for( int i = 0; i<persArray.length; i++) {
  37.             if( persArray[i].getAge() >= age) {
  38.                   persArray[i].print();
  39.               }
  40.         }
  41.     }
  42.  
  43. }
  44.  
  45.  
  46. class Sotrydnik {
  47.  
  48.     private String fio;
  49.     private String spec;
  50.     private String email;
  51.     private String numTel;
  52.     private int cash;
  53.     private int age;
  54.  
  55.     //Этот метод при вызове в классе HomeWork5 будет конструктором
  56.     public  Sotrydnik(String fio, String spec, String email, String numTel, int cash, int age) {
  57.         this.fio = fio;
  58.         this.spec = spec;
  59.         this.email = email;
  60.         this.numTel = numTel;
  61.         this.cash = cash;
  62.         this.age = age;
  63.     }
  64.  
  65.     public void print () {
  66.         System.out.print("ФИО: " + fio + " ");
  67.         System.out.print("Должность: " + spec + " ");
  68.         System.out.print("Почта: " + email+ " ");
  69.         System.out.print("Номер телефона: "+ numTel + " ");
  70.         System.out.print("Зарплата: " + cash + " ");
  71.         System.out.print("Возраст: "+ age + " ");
  72.         System.out.println();
  73.     }
  74.  
  75.  
  76.     //т.к. переменные у нас private нам нужны методы вывода значений
  77.     //когда мы хотим получить их в классе HomewWork5
  78.     public String getFio() {
  79.         return fio;
  80.     }
  81.  
  82.     public String getSpec() {
  83.         return spec;
  84.     }
  85.  
  86.     public String getEmail() {
  87.         return email;
  88.     }
  89.  
  90.     public String getNumTel() {
  91.         return numTel;
  92.     }
  93.  
  94.     public int getCash() {
  95.         return cash;
  96.     }
  97.  
  98.     public int getAge() {
  99.         return age;
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement