Advertisement
kalin729

TestPeople

Apr 19th, 2022
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class TestPeople {
  4.     public static void main(String[] args) {
  5.  
  6.         Student[] students = new Student[3];
  7.         Scanner keyboard = new Scanner(System.in);
  8.         double average = 0.0;
  9.         for (int i = 0; i < students.length; i++) {
  10.  
  11.             students[i] = new Student(); // Конструктор без параметри
  12.             System.out.println("Enter student's name: ");
  13.             students[i].setName(keyboard.nextLine()); // Метод setName()
  14.             System.out.println("Enter student's school: ");
  15.             students[i].setSchool(keyboard.nextLine()); // Метод setSchool()
  16.             System.out.println("Enter student's address: ");
  17.             students[i].setAddress(keyboard.nextLine());// Метод setAddress()
  18.             System.out.println("Enter student's grade: ");
  19.             students[i].setGrade(Double.parseDouble(keyboard.nextLine())); // Метод setGrade()
  20.             average += students[i].getGrade(); // Метод getGrade()
  21.  
  22.         }
  23.  
  24.         for (int i = 0; i < 3; i++) {
  25.             System.out.println((i + 1) + ". " + students[i].toString());
  26.         }
  27.  
  28.         Teacher[] teachers = new Teacher[2];
  29.         for (int i = 0; i < teachers.length; i++) {
  30.             teachers[i] = new Teacher();
  31.             System.out.println("Enter teacher's name: ");
  32.             teachers[i].setName(keyboard.nextLine());
  33.             System.out.println("Enter subject: ");
  34.             teachers[i].setSubject(keyboard.nextLine());
  35.             System.out.println("Enter teacher's room: ");
  36.             teachers[i].setRoom(Integer.parseInt(keyboard.nextLine()));
  37.         }
  38.  
  39.         printList(students, "TU");
  40.         System.out.println("Average grade: " + average / students.length);
  41.  
  42.         for (int i = 0; i < 2; i++) {
  43.             System.out.println((i + 1) + ". " + teachers[i].toString());
  44.         }
  45.  
  46.         info_Prog(teachers);
  47.         keyboard.close();
  48.     }
  49.  
  50.     static void printList(Student[] st, String uni) {
  51.         System.out.println("Students from " + uni);
  52.         for (int i = 0; i < st.length; i++) {
  53.             if (st[i].getSchool().equals(uni))
  54.                 System.out.println((i + 1) + ". " + st[i].getName());
  55.         }
  56.     }
  57.  
  58.     public static void info_Prog(Teacher[] teach) {
  59.         System.out.println("Programirane teachers : ");
  60.         boolean foundTeacher = false;
  61.         for (int i = 0; i < teach.length; i++) {
  62.             if (teach[i].getSubject().equals("Programirane")) {
  63.                 System.out.println((i + 1) + ". " + teach[i].getName() + " Room: " + teach[i].getRoom());
  64.                 foundTeacher = true;
  65.             }
  66.         }
  67.         if (!foundTeacher) {
  68.             System.out.println("No teachers found.");
  69.         }
  70.     }
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement