Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Homework5 {
- public static void main(String[] args) {
- //Создаем переменную и сканнер для сортировки по возрасту
- int age =0;
- Scanner sc = new Scanner(System.in);
- //Первая часть задания.
- Sotrydnik sotr1 = new Sotrydnik("Иванов Иван Иванович", "Инженер" ,
- "111@111.ru", "89167067716", 120000, 41);
- System.out.println(sotr1.getFio() + " " + sotr1.getSpec() + " " + sotr1.getEmail()
- + " " + sotr1.getNumTel() + " " + sotr1.getCash() + " " +sotr1.getAge());
- //Вторая часть задания.
- Sotrydnik[] persArray = new Sotrydnik[5];
- persArray[0] = new Sotrydnik("Петров Петр Петрович", "Электрик",
- "222@222.ru", "89232232323", 60000, 43);
- persArray[1] = new Sotrydnik("Павлов Павел Павлович", "Технолог",
- "333@333.ru", "89655521212", 60000, 35);
- persArray[2] = new Sotrydnik("Коренков Иван Иванович", "К.Качества",
- "444@444.ru", "9164433434", 60000, 27);
- persArray[3] = new Sotrydnik("Еврейкин Еврей Евреев", "Бухгалтер",
- "555@555.ru", "89653321212", 60000, 41);
- persArray[4] = new Sotrydnik("Ануфриев Валентин Валентинович", "Менеджер",
- "666@666.ru","89653445454", 35000,26);
- System.out.println("Введите возраст сотрудника: ");
- age = sc.nextInt();
- System.out.println();
- //сортировка по возрасту.
- //смотрим что пришло из консоли и сравниваем с age в массиве persArray.
- for( int i = 0; i<persArray.length; i++) {
- if( persArray[i].getAge() >= age) {
- persArray[i].print();
- }
- }
- }
- }
- class Sotrydnik {
- private String fio;
- private String spec;
- private String email;
- private String numTel;
- private int cash;
- private int age;
- //Этот метод при вызове в классе HomeWork5 будет конструктором
- public Sotrydnik(String fio, String spec, String email, String numTel, int cash, int age) {
- this.fio = fio;
- this.spec = spec;
- this.email = email;
- this.numTel = numTel;
- this.cash = cash;
- this.age = age;
- }
- public void print () {
- System.out.print("ФИО: " + fio + " ");
- System.out.print("Должность: " + spec + " ");
- System.out.print("Почта: " + email+ " ");
- System.out.print("Номер телефона: "+ numTel + " ");
- System.out.print("Зарплата: " + cash + " ");
- System.out.print("Возраст: "+ age + " ");
- System.out.println();
- }
- //т.к. переменные у нас private нам нужны методы вывода значений
- //когда мы хотим получить их в классе HomewWork5
- public String getFio() {
- return fio;
- }
- public String getSpec() {
- return spec;
- }
- public String getEmail() {
- return email;
- }
- public String getNumTel() {
- return numTel;
- }
- public int getCash() {
- return cash;
- }
- public int getAge() {
- return age;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement