Inheritance

A ability to inherit characteristics from super class to sub classes. Reduces risk of error and reduces redundancy. extends key word used to inherit characteristics from a class. You can have multiple instances of inheritance. Constructors in a sub class needs to have at least the same definition as the old class. When you call super() you call the supper class's constructor which must have all relevant parameters passed into it. @Override needed to state overriding methods of a super class and makes it readable

Creating Reference Using Inheritance Hierarchies

Tree called inheritance hierarchies where lower subclasses inherit upper super classes in the hierarchy

Polymorphism

Allows methods to take on multiple forms for code reusability of methods with different forms/implementations but execute the same way

Super class

Includes equals() and toString() methods which are the most common methods of the Object class

Homework Part I

public class QuarterFinalTeam{
    String jerseyColor;
    boolean quarterFinals;
    boolean semiFinals;

    public QuarterFinalTeam(){
        this.quarterFinals = true;
    }

    public static void determineResults(QuarterFinalTeam team1, QuarterFinalTeam team2){
        team1.quarterFinalResult();
        team2.quarterFinalResult();
    }

    public void quarterFinalResult(){}

    public static void main(String[] args){
        Netherlands netherlands = new Netherlands();
        Argentina argentina = new Argentina();
        Croatia croatia = new Croatia();
        Brazil brazil = new Brazil();
        England england = new England();
        France france = new France();
        Morocco morocco = new Morocco();
        Portugal portugal = new Portugal();

        QuarterFinalTeam.determineResults(netherlands, argentina);
        QuarterFinalTeam.determineResults(croatia, brazil);
        QuarterFinalTeam.determineResults(england, france);
        QuarterFinalTeam.determineResults(morocco, portugal);

        System.out.println("Netherlands: " + "jerseyColor = " + netherlands.jerseyColor + ", quarterFinals = " + netherlands.quarterFinals + ", semiFinals = " + netherlands.semiFinals);
        System.out.println("Argentina: " + "jerseyColor = " + argentina.jerseyColor + ", quarterFinals = " + argentina.quarterFinals + ", semiFinals = " + argentina.semiFinals);
        System.out.println("Croatia: " + "jerseyColor = " + croatia.jerseyColor + ", quarterFinals = " + croatia.quarterFinals + ", semiFinals = " + croatia.semiFinals);
        System.out.println("Brazil: " + "jerseyColor = " + brazil.jerseyColor + ", quarterFinals = " + brazil.quarterFinals + ", semiFinals = " + brazil.semiFinals);
        System.out.println("England: " + "jerseyColor = " + england.jerseyColor + ", quarterFinals = " + england.quarterFinals + ", semiFinals = " + england.semiFinals);
        System.out.println("France: " + "jerseyColor = " + france.jerseyColor + ", quarterFinals = " + france.quarterFinals + ", semiFinals = " + france.semiFinals);
        System.out.println("Morocco: " + "jerseyColor = " + morocco.jerseyColor + ", quarterFinals = " + morocco.quarterFinals + ", semiFinals = " + morocco.semiFinals);
        System.out.println("Portugal: " + "jerseyColor = " + portugal.jerseyColor + ", quarterFinals = " + portugal.quarterFinals + ", semiFinals = " + portugal.semiFinals);
    }

}

public class Netherlands extends QuarterFinalTeam{
    public Netherlands(){
        super();
        super.jerseyColor = "Orange";
    }

    public void quarterFinalResult(){
        super.semiFinals = false;
    }
}

public class Argentina extends QuarterFinalTeam{
    public Argentina(){
        super();
        super.jerseyColor = "Blue & White";
    }

    public void quarterFinalResult(){
        super.semiFinals = true;
    }
}

public class Croatia extends QuarterFinalTeam{
    public Croatia(){
        super();
        super.jerseyColor = "Red & White";
    }

    public void quarterFinalResult(){
        super.semiFinals = true;
    }
}

public class Brazil extends QuarterFinalTeam{
    public Brazil(){
        super();
        super.jerseyColor = "Yellow";
    }

    public void quarterFinalResult(){
        super.semiFinals = false;
    }
}

public class England extends QuarterFinalTeam{
    public England(){
        super();
        super.jerseyColor = "White & Blue";
    }

    public void quarterFinalResult(){
        super.semiFinals = false;
    }
}

public class France extends QuarterFinalTeam{
    public France(){
        super();
        super.jerseyColor = "Blue White & Red";
    }

    public void quarterFinalResult(){
        super.semiFinals = true;
    }
}

public class Morocco extends QuarterFinalTeam{
    public Morocco(){
        super();
        super.jerseyColor = "Red & Green";
    }

    public void quarterFinalResult(){
        super.semiFinals = true;
    }
}

public class Portugal extends QuarterFinalTeam{
    public Portugal(){
        super();
        super.jerseyColor = "Red & Green";
    }

    public void quarterFinalResult(){
        super.semiFinals = false;
    }
}

QuarterFinalTeam.main(null);
Netherlands: jerseyColor = Orange, quarterFinals = true, semiFinals = false
Argentina: jerseyColor = Blue & White, quarterFinals = true, semiFinals = true
Croatia: jerseyColor = Red & White, quarterFinals = true, semiFinals = true
Brazil: jerseyColor = Yellow, quarterFinals = true, semiFinals = false
England: jerseyColor = White & Blue, quarterFinals = true, semiFinals = false
France: jerseyColor = Blue White & Red, quarterFinals = true, semiFinals = true
Morocco: jerseyColor = Red & Green, quarterFinals = true, semiFinals = true
Portugal: jerseyColor = Red & Green, quarterFinals = true, semiFinals = false

Homework Part II

import java.util.Date;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;

public class Person {
   private String name;
   private String birthday;

   public Person (String name, String birthday){
      this.name = name;
      this.birthday = birthday;
   }

   public String getName(){
      return name;
   }

   public int getAge(){
      if (this.birthday != null) {
            // LocalDate birthDay = this.birthday.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
            // return Period.between(birthDay, LocalDate.now()).getYears();

            // too lazy to use a name thing
      }
      
      return -1;
   }
 }
 
public class Student extends Person {
   private int grade;
   private double gpa;

   public Student (String name, String birthday, int grade, double gpa) {
      super(name, birthday);
      this.grade = grade;
      this.gpa = gpa;
   }

   public int getGrade(){
      return grade;
   }

   @Override
   public String toString(){
      return "wow crazy string, im too lazy to write a proper to string";
   }
}

public class Teacher extends Person {
   private String subject;

   public Teacher (String name, String birthday, String subject){
      super(name, birthday);
      this.subject = subject;
   }

   @Override
   public String toString(){
      return "woah";
   }
}

public class Main{
   public static void main(String[] args){
      Student nathan = new Student("Nathan", "Sometime in April? I think?", 11, 4.0);
      System.out.println(nathan.toString());
      
      Teacher mrMort = new Teacher("John Mortensen", "Old.", "Computer Science");
      System.out.println(mrMort.toString());
   }
}

Main.main(null);
wow crazy string, im too lazy to write a proper to string
woah