This is how I achieved it (in my case the superclass was Team and the subclass was Scorer):
// Team.java
public class Team {
String team;
int won;
int drawn;
int lost;
int goalsFor;
int goalsAgainst;
Team(String team, int won, int drawn, int lost, int goalsFor, int goalsAgainst){
this.team = team;
this.won = won;
this.drawn = drawn;
this.lost = lost;
this.goalsFor = goalsFor;
this.goalsAgainst = goalsAgainst;
}
int matchesPlayed(){
return won + drawn + lost;
}
int goalDifference(){
return goalsFor - goalsAgainst;
}
int points(){
return (won * 3) + (drawn * 1);
}
}
// Scorer.java
public class Scorer extends Team{
String player;
int goalsScored;
Scorer(String player, int goalsScored, String team, int won, int drawn, int lost, int goalsFor, int goalsAgainst){
super(team, won, drawn, lost, goalsFor, goalsAgainst);
this.player = player;
this.goalsScored = goalsScored;
}
float contribution(){
return (float)this.goalsScored / (float)this.goalsFor;
}
float goalsPerMatch(){
return (float)this.goalsScored/(float)(this.won + this.drawn + this.lost);
}
}