09 Inheritance Student Lesson
Documentation of 09 inheritance
public class WorldCup {
private char group;
public WorldCup(char group) {
this.group = group;
}
public char getGroup() {
return group;
}
public class Brazil extends WorldCup {
private String name;
private String continent;
private String jerseyColor;
public Brazil(char group, String name, String continent, String jerseyColor) {
super(group);
this.name = name;
this.continent = continent;
this.jerseyColor = jerseyColor;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name + ": {" + "group: " + group + " continent: " + continent + ", jersey color: " + jerseyColor
+ "}";
}
}
public class Argentina extends WorldCup {
private String name;
private String continent;
private String jerseyColor;
public Argentina(char group, String name, String continent, String jerseyColor) {
super(group);
this.name = name;
this.continent = continent;
this.jerseyColor = jerseyColor;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name + ": {" + "group: " + group + " continent: " + continent + ", jersey color: " + jerseyColor
+ "}";
}
}
public class Croatia extends WorldCup {
private String name;
private String continent;
private String jerseyColor;
public Croatia(char group, String name, String continent, String jerseyColor) {
super(group);
this.name = name;
this.continent = continent;
this.jerseyColor = jerseyColor;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name + ": {" + "group: " + group + " continent: " + continent + ", jersey color: " + jerseyColor
+ "}";
}
}
public class Morocco extends WorldCup {
private String name;
private String continent;
private String jerseyColor;
public Morocco(char group, String name, String continent, String jerseyColor) {
super(group);
this.name = name;
this.continent = continent;
this.jerseyColor = jerseyColor;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name + ": {" + "group: " + group + " continent: " + continent + ", jersey color: " + jerseyColor
+ "}";
}
}
public class France extends WorldCup {
private String name;
private String continent;
private String jerseyColor;
public France(char group, String name, String continent, String jerseyColor) {
super(group);
this.name = name;
this.continent = continent;
this.jerseyColor = jerseyColor;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name + ": {" + "group: " + group + " continent: " + continent + ", jersey color: " + jerseyColor
+ "}";
}
}
public static void main(String[] args) {
WorldCup Qatar = new WorldCup('A');
Brazil brazilTeam = Qatar.new Brazil('F', "Brazil", "South America", "Yellow");
Argentina argentinaTeam = Qatar.new Argentina('C', "Argentina", "South America", "Blue");
Croatia croatiaTeam = Qatar.new Croatia('F', "Croatia", "Europe", "White");
Morocco moroccoTeam = Qatar.new Morocco('F', "Morocco", "Africa", "Red");
France franceTeam = Qatar.new France('D', "France", "Europe", "Blue");
System.out.println(brazilTeam);
System.out.println(argentinaTeam);
System.out.println(croatiaTeam);
System.out.println(moroccoTeam);
System.out.println(franceTeam);
}
}
WorldCup.main(null);
public class Person {
private String name;
private String birthday;
private int age;
public Person(String name, String birthday, int age) {
this.name = name;
this.birthday = birthday;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public static void main(String[] args) {
Person Bob = new Person("Bob", "Jan 1,2000", 22);
Student Ted = Bob.new Student("Ted", "Jan 2, 2010", 12, 11, 4.0, 5);
Teacher MsSmith = Bob.new Teacher("Ms. Smith", "Jan 5, 1999", 23, 4, "Computer Science");
System.out.println(Ted);
System.out.println(MsSmith);
}
public class Student extends Person {
private int grade;
private double gpa;
private int numFriends;
public Student(String name, String birthday, int age, int grade, double gpa, int numFriends) {
super(name, birthday, age);
this.grade = grade;
this.gpa = gpa;
this.numFriends = numFriends;
}
public int getGrade() {
return grade;
}
public int getNumFriends() {
return numFriends;
}
@Override
public String toString() {
return name + ": {" + "gpa: " + gpa + " grade: " + grade + "}";
}
}
public class Teacher extends Person {
private int classes;
private String subject;
public Teacher (String name, String birthday, int age, int classes, String subject) {
super(name, birthday, age);
this.classes = classes;
this.subject = subject;
}
public int getNumClasses() {
return classes;
}
public String getSubject() {
return subject;
}
@Override
public String toString() {
return name + ": {" + "number of classes: " + classes + " subject: " + subject + "}";
}
}
}
Person.main(null);