Lesson 0

Introduction to Object-Oriented Programming

In the first lesson we will strengthen the knowledge from the PPJ course. We will focus on those elements that are crucial to create something interesting during GUI course.

Task 0
What do you remember about Java?
For each topic you will find useful links to remind the material.
[link] [link]
[link]
[link]
[link]
[link]
[link] [link]
[link] [link]
[link]
[link]
[link]
[link] [link]
Task 1

Without modifying the main method, make the code below work.

Hint: Subject class can have access to students' set (e.g. an array). Adding too many students to the set may throw an exception.


public class Main {
    public static void main(String args[]) {
        
        Person p1 = new Person("Jan", 50); //name, age
        Student s1 = new Student("Jasiek", 20, 2); //name, age, semester
        Person p3 = (Person)s1;
	    Student s2 = new Student("Anna", 21, 4);
        
        p1.sayHelloTo(p3); // Hi Jasiek!
        p3.sayHelloTo(p1); // Good morning, Jan!
	    s1.sayHelloTo(s2); // Yo, Anna!
        s1.sayHelloTo(p1); // Good morning, Jan!
        
        Subject s = new Subject("GUI");
        s.setTeacher(p1);
        
        try {
            s.addStudent(s1);
		    s.addStudent(s2);
        } catch(TooManyStudentsException e) {
            e.printStackTrace();
        }
        
        System.out.println(s); //GUI, teacher: Jan, students: Jasiek - 2 sem, Anna - 4 sem
        
    }
}