0% found this document useful (0 votes)
2 views

import

The Java program allows users to register a specified number of teachers, collecting their names, surnames, ages, and associated university information. For each teacher, it also registers a specified number of students with their names, surnames, and ages. Finally, the program provides a search function to find and display information about a teacher based on their name.

Uploaded by

den
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

import

The Java program allows users to register a specified number of teachers, collecting their names, surnames, ages, and associated university information. For each teacher, it also registers a specified number of students with their names, surnames, and ages. Finally, the program provides a search function to find and display information about a teacher based on their name.

Uploaded by

den
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;

public class Main4 {


public static void main(String[] args) {
System.out.println("How many teachers do u want to register?");
int count = new Scanner(System.in).nextInt();
Teacher[] teachers = new Teacher[count];// verilen sayda teacher
massivi yaradildi
for(int i=0; i<count;i++) {
Teacher myTeacher = new Teacher(); // massivin her elementi ucun
teacher obyekti yaradildi
System.out.println("Enter teacher's name");
String name = new Scanner(System.in).nextLine();
myTeacher.setName(name);
System.out.println("Enter teacher's surname");
String surname = new Scanner(System.in).nextLine();
myTeacher.setSurname(surname);
System.out.println("Enter teacher's age");
int age = new Scanner(System.in).nextInt();
myTeacher.setAge(age); //teacher obyetktinin ad soyad yas elde
olundu ve menimsedildi

University university = new University(); // university obyekti


yaradildi
System.out.println("What university does the teacher work at?");
university.name = new Scanner(System.in).nextLine();
myTeacher.setUniversity(university); //teacher-e university
obyekti set olundu

System.out.println("How many students does teacher_"+i);


int studentCount = new Scanner(System.in).nextInt();
Student[] students = new Student[studentCount]; // obyekt1 ucun
verilen sayda student massivi yaradildi
for(int j=0; j<studentCount; j++) {
Student myStudent = new Student(); // student massivi
elementi ucun student obyekti yaradildi
System.out.println("Enter student's name");
myStudent.name = new Scanner(System.in).nextLine();
System.out.println("Enter student's surname");
myStudent.surname = new Scanner(System.in).nextLine();
System.out.println("Enter student's age");
myStudent.age = new Scanner(System.in).nextInt();
students[j] = myStudent; // student obyektine ad soyad yas
menimsedildi
}
myTeacher.setStudents(students); // student massivi teacher
obyektine set olundu
teachers[i] = myTeacher; // teacher massivinin i-ci elementine
teacher obyekti menimsedildi
}

System.out.println("Enter the name u want to search:");


String searchName = new Scanner(System.in).nextLine();

Search(teachers, count, searchName);


}
public static void Search(Teacher[] teachers, int count, String
searchName) {
for(int i=0; i<count;i++) {

if(searchName.equalsIgnoreCase(teachers[i].getName())) {
System.out.println(teachers[i].getName());
System.out.println(teachers[i].getSurname());
System.out.println(teachers[i].getAge());
System.out.println(teachers[i].getUniversity().name);
Student[] myStudents = teachers[i].getStudents();
for(int k=0; k<myStudents.length;k++) {
System.out.println(myStudents[k].name);
System.out.println(myStudents[k].surname);
System.out.println(myStudents[k].age);
}
}
}

}
}

You might also like