Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TestPeople {
- public static void main(String[] args) {
- Student[] students = new Student[3];
- Scanner keyboard = new Scanner(System.in);
- double average = 0.0;
- for (int i = 0; i < students.length; i++) {
- students[i] = new Student(); // Конструктор без параметри
- System.out.println("Enter student's name: ");
- students[i].setName(keyboard.nextLine()); // Метод setName()
- System.out.println("Enter student's school: ");
- students[i].setSchool(keyboard.nextLine()); // Метод setSchool()
- System.out.println("Enter student's address: ");
- students[i].setAddress(keyboard.nextLine());// Метод setAddress()
- System.out.println("Enter student's grade: ");
- students[i].setGrade(Double.parseDouble(keyboard.nextLine())); // Метод setGrade()
- average += students[i].getGrade(); // Метод getGrade()
- }
- for (int i = 0; i < 3; i++) {
- System.out.println((i + 1) + ". " + students[i].toString());
- }
- Teacher[] teachers = new Teacher[2];
- for (int i = 0; i < teachers.length; i++) {
- teachers[i] = new Teacher();
- System.out.println("Enter teacher's name: ");
- teachers[i].setName(keyboard.nextLine());
- System.out.println("Enter subject: ");
- teachers[i].setSubject(keyboard.nextLine());
- System.out.println("Enter teacher's room: ");
- teachers[i].setRoom(Integer.parseInt(keyboard.nextLine()));
- }
- printList(students, "TU");
- System.out.println("Average grade: " + average / students.length);
- for (int i = 0; i < 2; i++) {
- System.out.println((i + 1) + ". " + teachers[i].toString());
- }
- info_Prog(teachers);
- keyboard.close();
- }
- static void printList(Student[] st, String uni) {
- System.out.println("Students from " + uni);
- for (int i = 0; i < st.length; i++) {
- if (st[i].getSchool().equals(uni))
- System.out.println((i + 1) + ". " + st[i].getName());
- }
- }
- public static void info_Prog(Teacher[] teach) {
- System.out.println("Programirane teachers : ");
- boolean foundTeacher = false;
- for (int i = 0; i < teach.length; i++) {
- if (teach[i].getSubject().equals("Programirane")) {
- System.out.println((i + 1) + ". " + teach[i].getName() + " Room: " + teach[i].getRoom());
- foundTeacher = true;
- }
- }
- if (!foundTeacher) {
- System.out.println("No teachers found.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement