WorldCup SuperClass

Create a world cup superclass with properties of your choice and subclasses for five teams which inherits those properties and have a constructor for one of those subclasses.

public class WorldCup {
    public String game;
    public String team1;
    public String team2;
    public int score;
    
    public WorldCup (String game, String team1, String team2, int score){
        this.game = game;
        this.team1=team1;
        this.team2=team2;
        this.score=score;
    }

    public String getTeam1(){
        return team1;
    }

    public String getTeam2(){
        return team2;
    }

    public void score() {
        this.score += 1;
    }

    public void stats(){
        System.out.println("");
    }
    public void printInfo() {
        System.out.println("Team game: " + this.game);
        System.out.println("Team 1: " + this.team1);
        System.out.println("Team 2: " + this.team2);
        System.out.println("Score: " + this.score);
        stats();
    }
}

public class Portugal extends WorldCup {
    
    public Portugal(String game, String team1, String team2, int score){
        super(game, team1, team2, score);
    }
    public void score() {
        this.score += 1;
    }
    public void stats(){
        System.out.println("Portugal pass accuracy: 71%");
        }
}
public class Morocco extends WorldCup {
    
    public Morocco(String game, String team1, String team2, int score){
        super(game, team1, team2, score);
    }
    public void score() {
        this.score += 1;
    }
    public void stats(){
        System.out.println("Morocco pass accuracy: 85%");
    }
}
public class England extends WorldCup {
    
    public England(String game, String team1, String team2, int score){
        super(game, team1, team2, score);
    }
    public void score() {
        this.score += 1;
    }
    public void stats(){
        System.out.println("England pass accuracy: 71%");
        }
}
public class France extends WorldCup {
    
    public France(String game, String team1, String team2, int score){
        super(game, team1, team2, score);
    }
    public void score() {
        this.score += 1;
    }
    public void stats(){
        System.out.println("France pass accuracy: 85%");
    }
}
public class Argentina extends WorldCup {
    
    public Argentina(String game, String team1, String team2, int score){
        super(game, team1, team2, score);
    }
    public void score() {
        this.score += 1;
    }
    public void stats(){
        System.out.println("Argentina pass accuracy: 71%");
        }
}
public class Croatia extends WorldCup {
    
    public Croatia(String game, String team1, String team2, int score){
        super(game, team1, team2, score);
    }
    public void score() {
        this.score += 1;
    }
    public void stats(){
        System.out.println("Croatia pass accuracy: 85%");
    }
}

WorldCup Portugal = new Portugal("Game 1", "Portugal", "Morocco", 0);
WorldCup Morocco = new Morocco("Game 2", "Portugal", "Morocco", 1);
WorldCup England = new England("Game 3", "England", "France", 0);
WorldCup France = new France("Game 4", "England", "France", 1);
WorldCup Argentina = new Argentina("Game 5", "Argentina", "Croatia", 0);
WorldCup Croatia = new Croatia("Game 6", "Argentina", "Croatia", 1);

WorldCup.printInfo();
Portugal.printInfo();
Morocco.printInfo();
England.printInfo();
France.printInfo();
Argentina.printInfo();
Croatia.printInfo();
Team game: Game 1
Team 1: Portugal
Team 2: Morocco
Score: 1

Team game: Game 1
Team 1: Portugal
Team 2: Morocco
Score: 0
Portugal pass accuracy: 71%
Team game: Game 2
Team 1: Portugal
Team 2: Morocco
Score: 1
Morocco pass accuracy: 85%
Team game: Game 3
Team 1: England
Team 2: France
Score: 0
England pass accuracy: 71%
Team game: Game 4
Team 1: England
Team 2: France
Score: 1
France pass accuracy: 85%
Team game: Game 5
Team 1: Argentina
Team 2: Croatia
Score: 0
Argentina pass accuracy: 71%
Team game: Game 6
Team 1: Argentina
Team 2: Croatia
Score: 1
Croatia pass accuracy: 85%

Person and Student Homework

Add a getAge method in the Person super class, create a new subclass Student with additional members and a new subclass Teacher with additional members, override the toString method using the @Override to print a Student and teacher object with new members, and 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;
    }
    // method for getting age based on their birthday year subtracted from this year
    public int getAge() {
         return 2022 - Integer.parseInt(birthday);
    }

    // using override for toString method
    @Override
    public String toString() {
         return "Person (name: " + name + ", birthday: " + birthday + ")";
    }
}
 
public class Student extends Person {
    private int grade;
    private double gpa;
 
    // student subclass with the personalized aspects
    public Student (String name, String birthday, int grade, double gpa) {
       super(name, birthday);
       this.grade = grade;
       this.gpa = gpa;
    }

    // tells the student's current gpa
    public double getGPA() {
        return gpa;
    }

    // tells the student's grade level
    public int getGrade() {
       return grade;
    }

    // using override to print student out
    @Override
    public String toString() {
        return "Student (name: " + name + ", birthday: " + birthday + ", weighted gpa: " + gpa + ", grade: " + grade + ")";
    }
}

public class Teacher extends Person {
    private String subject;
    private int yearsTaught;
    private String degree;
   
    // teacher subclass with personalized aspects
    public Teacher (String name, String birthday, String subject, int yearsTaught) {
        super(name, birthday);
        this.subject = subject;
        this.yearsTaught = yearsTaught;
    }
   
    // tells the subject teacher is currently teaching
    public String getSubject() {
        return subject;
    }

    // tells the number of years that the teacher has been teaching for
    public int getYears() {
        return yearsTaught;
    }

    // using override to print teacher out
    @Override
    public String toString() {
        return "Teacher (name: " + name + ", birthday: " + birthday + ", subject teaching: " + subject + ", number of years teaching: " + yearsTaught;
    }
}


// printing the person, student, and teacher along with their respective information
Person tom = new Person("Tom Cruise", "1962");
System.out.println(tom.toString());
Person pranavi = new Student("Pranavi Inukurti", "2005", 12, 4.1);
System.out.println(pranavi.toString());
Person john = new Teacher("John Mortensen", "1959", "Computer Science", 22);
System.out.println(john.toString());
Person (name: Tom Cruise, birthday: 1962)
Student (name: Pranavi Inukurti, birthday: 2005, weighted gpa: 4.1, grade: 12)
Teacher (name: John Mortensen, birthday: 1959, subject teaching: Computer Science, number of years teaching: 22