Created
December 22, 2016 13:37
-
-
Save i0nyx/d355d6e4ace695cddc4f3d0aacee5736 to your computer and use it in GitHub Desktop.
Glava 2
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
/* | |
Создать классы, спецификации которых приведены ниже. | |
Определить конструкторы и методы setТип(), getТип(), toString(). Определить | |
дополнительно методы в классе, создающем массив объектов. Задать | |
критерий выбора данных и вывести эти данные на консоль. | |
1.1). Student: id, Фамилия, Имя, Отчество, Дата рождения, Адрес, | |
Телефон, Факультет, Курс, Группа. | |
Создать массив объектов. Вывести: | |
a) список студентов заданного факультета; | |
b) списки студентов для каждого факультета и курса; | |
c) список студентов, родившихся после заданного года; | |
d) список учебной группы. | |
*/ | |
package gl_2.zalanie_gl_2; | |
public class N_1_1 { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Student st = new Student(); | |
Student[] stud = new Student[5]; | |
Student stud1 = new Student(1,"Бур", "Вася", "Алексеевич","2,12,1987", "Новогрудок", "375299944882", "Агрономия", 3, "31c"); | |
Student stud2 = new Student(2,"Бузук", "Сергей", "Дмитриевич","29,04,1986", "Новогрудок", "375299944882", "Экономика", 5, "53-A"); | |
Student stud3 = new Student(3,"Сивко", "Елена", "Григорьевна","7,02,1993", "Новогрудок", "375299944882", "Агрономия", 1, "11A"); | |
Student stud4 = new Student(4,"Кошур", "Андрей", "Васильевич","21,06,1990", "Новогрудок", "375299944882", "Программирование", 3, "31c"); | |
Student stud5 = new Student(5,"Скварада", "Ольга", "Сергеевна","16,10,1990", "Новогрудок", "375299944882", "Агрономия", 1, "1B"); | |
stud[0] = stud1; | |
stud[1] = stud2; | |
stud[2] = stud3; | |
stud[3] = stud4; | |
stud[4] = stud5; | |
for(Student s : stud){ | |
s.show(); | |
} | |
System.out.println("Факультет Аграномии:"); | |
for(Student s : stud){ | |
s.fakultet(); | |
} | |
System.out.println("Список факультетов и курсов: "); | |
System.out.println("Факультет АГРОНОМИЯ"); | |
System.out.println("1 КУРС:"); | |
for(Student s : stud){ | |
s.listFakultet("Агрономия", 1); | |
} | |
System.out.println("Студенты с 1990г рождения:"); | |
for(Student s : stud){ | |
s.vozrast(1990); | |
} | |
} | |
} | |
class Student{ | |
private int id; | |
private String familia; | |
private String name; | |
private String otchestvo; | |
private String birthday; | |
private String adress; | |
private String phoneNumber; | |
private String fakultet; | |
private int kurs; | |
private String group; | |
public Student(){ | |
} | |
public Student(int id, String familia, String name, String otchestvo, String birthday, String adress, String phoneNumber, | |
String fakultet, int kurs, String group){ | |
this.id = id; | |
this.familia = familia; | |
this.name = name; | |
this.otchestvo = otchestvo; | |
this.birthday = birthday; | |
this.adress = adress; | |
this.phoneNumber = phoneNumber; | |
this.fakultet = fakultet; | |
this.kurs = kurs; | |
this.group = group; | |
} | |
// get'тэры | |
public int getId(){ | |
return id; | |
} | |
public String getFamilia(){ | |
return familia; | |
} | |
public String getName(){ | |
return name; | |
} | |
public String getOtchestvo(){ | |
return otchestvo; | |
} | |
public String getBirthday(){ | |
return birthday; | |
} | |
public String getAdress(){ | |
return adress; | |
} | |
public String getPhoneNumber(){ | |
return phoneNumber; | |
} | |
public String getFakultet(){ | |
return fakultet; | |
} | |
public int getKurs(){ | |
return kurs; | |
} | |
public String getGroup(){ | |
return group; | |
} | |
//set'тэры | |
public void setId(int id){ | |
this.id = id; | |
} | |
public void setFamilia(String familia){ | |
this.familia = familia; | |
} | |
public void setName(String name){ | |
this.name = name; | |
} | |
public void setOtchestvo(String otchestvo){ | |
this.otchestvo = otchestvo; | |
} | |
public void setBirthday(String birthday){ | |
this.birthday = birthday; | |
} | |
public void setAdress(String adress){ | |
this.adress = adress; | |
} | |
public void setPhoneNumber(String phoneNumber){ | |
this.phoneNumber = phoneNumber; | |
} | |
public void setFakultet(String fakultet){ | |
this.fakultet = fakultet; | |
} | |
public void setKurs(int kurs){ | |
this.kurs = kurs; | |
} | |
public void setGroup(String group){ | |
this.group = group; | |
} | |
public void show(){ | |
System.out.println(getId() + " " + getFamilia() + " " + getName() + " " + getOtchestvo() + " " + getBirthday() + " " + getAdress() + " " + getPhoneNumber() + " " + getFakultet() | |
+ " " + getKurs() + " " + getGroup()); | |
} | |
public void fakultet(){ | |
if(this.getFakultet().equals("Агрономия")){ | |
System.out.println(getId() + " " + getFamilia() + " " + getName() + " " + getOtchestvo() + " " + getBirthday() + " " + getAdress() + " " + getPhoneNumber() + " " + getFakultet() | |
+ " " + getKurs() + " " + getGroup()); | |
} | |
} | |
public void listFakultet(String fakultet, int kurs){ | |
if(getFakultet().equals(fakultet) && getKurs() == kurs){ | |
System.out.println(getId() + " " + getFamilia() + " " + getName() + " " + getOtchestvo() + " " + getBirthday() + " " + getAdress() + " " + getPhoneNumber() + " " + getFakultet() | |
+ " " + getKurs() + " " + getGroup()); | |
} | |
} | |
public void vozrast(int years){ | |
String[] strBirthday = getBirthday().split(","); | |
//System.out.print(strBirthday[0] + " " + strBirthday[1] + " " + strBirthday[2]); | |
int year = (int)Integer.valueOf(strBirthday[2]); | |
if(year >= years){ | |
System.out.println(getId() + " " + getFamilia() + " " + getName() + " " + getOtchestvo() + " " + getBirthday() + " " + getAdress() + " " + getPhoneNumber() + " " + getFakultet() | |
+ " " + getKurs() + " " + getGroup()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment