Notes

  • Can Create super classes
Public class A{

}

Public class B extends A{
    
}
  • a subclass can become a super class because you can extend it many many time
  • can add other parameters inside of a subclass to make it more unique
  • put the parameters you are using from the super class to go inside of the new
  • @Override to give different method of a super class

HW pt 1

1) Create a world cup superclass with properties of your choice and subclasses for five teams which inherits those properties 2) Write a constructor for one of those subclasses

public class WorldCup{
    boolean isGood = true;
    String color = "maroon";
}
public class Argentina extends WorldCup{
    String color = "blue";
    public static void main(String args[]){
        Argentina argentina = new Argentina();
        System.out.println("Argentina is good = " + argentina.isGood);
        System.out.println("Argentina color = " +argentina.color);
    }
}
public class Brazil extends WorldCup{
    String color = "yellow";
    public static void main(String args[]){
        Brazil brazil = new Brazil();
        System.out.println("Brazil is good = " + brazil.isGood);
        System.out.println("Brazil color = " + brazil.color);
    }
}
public class Japan extends WorldCup{
    String color = "blue";
    public static void main(String args[]){
        Japan japan = new Japan();
        System.out.println("Japan is good = " + japan.isGood);
        System.out.println("Japan color = " + japan.color);
    }
}
public class France extends WorldCup{
    String color = "dark blue";
    public static void main(String args[]){
        France france = new France();
        System.out.println("France is good = " + france.isGood);
        System.out.println("France color = " +france.color);
    }
}
public class Morocco extends WorldCup{
    String color = "red";
    public static void main(String args[]){
        Morocco morocco = new Morocco();
        System.out.println("Morocco is good = " + morocco.isGood);
        System.out.println("Morocco color = " + morocco.color);
    }
}

Argentina.main(null);
Brazil.main(null);
Japan.main(null);
France.main(null);
Morocco.main(null);
Argentina is good = true
Argentina color = blue
Brazil is good = true
Brazil color = yellow
Japan is good = true
Japan color = blue
France is good = true
France color = dark blue
Morocco is good = true
Morocco color = red

HW pt 2

  • Add a getAge method in the Person super class
  • Create a new subclass Student with additional members of your choice to personalize the Student class
  • Create a new subclass Teacher with additiona members of your choice
  • Override the toString method using the @Override to print a Student and teacher object with new members
  • Print the student and teacher.
public class Person {
    protected String name;
    protected String birthday;
 
    public Person (String name, String birthday){
       this.name = name;
       this.birthday = birthday;
    }
 
    public String getName(){
       return name;
    }

    public int getAge() {
         return 2022 - Integer.parseInt(birthday);
    }

    @Override
    public String toString() {
         return "Person (name: " + name + ", birthday: " + birthday + ")";
    }
 }
 
 public class Student extends Person {
    private int grade;
    private double gpa;
    private String coding;
 
    public Student (String name, String birthday, int grade, double gpa, String coding) {
       super(name, birthday);
       this.grade = grade;
       this.gpa = gpa;
       this.coding = coding;
    }

    // return gpa
    public double getGPA() {
        return gpa;
    }

    public String coding() {
        return coding;
    }

    // return grade
    public int getGrade(){
       return grade;
    }

    @Override
    public String toString() {
         return "Student (name: " + name + ", birthday: " + birthday + ", coding: " + coding + ", gpa:" + gpa + ", grade: " + grade + ")";
    }
 }

 public class Teacher extends Person {
      private String subject;
      private String degree;
   
      public Teacher (String name, String birthday, String subject, String degree) {
         super(name, birthday);
         this.subject = subject;
         this.degree = degree;
      }
   
      // return subject
      public String getSubject() {
         return subject;
      }

   
      // return degree
      public String getDegree() {
         return degree;
      }

      @Override
      public String toString() {
            return "Teacher (name: " + name + ", birthday: " + birthday + ", subject: " + subject + ", degree: " + degree + ")";
      }
 }

Person johnnysins = new Person("Johnny Sins", "1985");
Person don = new Student("Don", "2005", 11, 5.0, "true");
Person mortensen = new Teacher("Mortensen", "Since Forever", "CODE CODE CODE", "IDK lmao");
System.out.println(don.toString());
System.out.println(johnnysins.toString());
System.out.println(mortensen.toString());
Student (name: Don, birthday: 2005, coding: true, gpa:5.0, grade: 11)
Person (name: Johnny Sins, birthday: 1985)
Teacher (name: Mortensen, birthday: Since Forever, subject: CODE CODE CODE, degree: IDK lmao)