Unit 9 Homework
Inheritance
public class WorldCupTeam {
private int players;
private String name;
private String manager;
public WorldCupTeam(int players, String name, String manager) {
this.players = players;
this.name = name;
this.manager = manager;
}
public boolean playGame() {
// randomly select if the team wins
if(Math.random() > 0.5) {
return false;
}
return true;
}
}
5 teams extending WorldCupTeam
class.
public class Portugal extends WorldCupTeam {
public Portugal(int players, String name, String manager) {
super(players, name, manager);
}
}
public class Croatia extends WorldCupTeam {
public Croatia(int players, String name, String manager) {
super(players, name, manager);
}
}
public class Brazil extends WorldCupTeam {
public Brazil(int players, String name, String manager) {
super(players, name, manager);
}
}
public class USA extends WorldCupTeam {
public USA(int players, String name, String manager) {
super(players, name, manager);
}
}
public class Morocco extends WorldCupTeam {
public Morocco(int players, String name, String manager) {
super(players, name, manager);
}
}