LWB LW CB CM AM CF ?? CM RB Figure 1. Soccer position map Various positions avai
ID: 3914992 • Letter: L
Question
LWB LW CB CM AM CF ?? CM RB Figure 1. Soccer position map Various positions available on a soccer field for players are depicted in figure 1. A SoccerPlayer class with following: name (XXXX: String type), dob (dd-mm-yyyy: Date type), clubName(XXXX: String type), countryName(XXXX: String type), numYellowCards (X; int type), numRedCards (X: int type), and gamesPlayed (X: int type) A Goalkeeper is a SoccerPlayer that in addition has the following: goalsAllowed (X int type). shotsOnGoal (X. int type), and numSaves (X: int type) A Defender is a SoccerPlayer that in addition has the following: numTackles (X: double type) A CentreBack is a Defender that in addition has the following: shotsBlocked (X: int type) A Sweeper is a Defender that in addition has the following: sweepUps (X: int type) A WingBack is a Defender that in addition has the following: throwIns (X: int type) A Midfielder is a SoccerPlayer that in addition has the following: attacksStopped (X: int type) A CenreMidfielder is a Midfielder that in addition has the following: numPasses (X: int type) A WideMidfielder is a Midfielder that in addition has the following: chancesCreated (X: int type) A DefensiveMidfielder is a Midfielder that in addition has the following: intercepts (X: int type) A Forward is a SoccerPlayer that in addition has following: goalsScored (X: int type), numAssists (X: int type), shotsOnTarget (X: int type) A CenreForward is a Forward that in addition has the following: longBallsRecieved (X: int type) A Winger is a Forward that in addition has the following: numCrosses (X: int type) A Striker is a Forward that in addition has the following: goalsToShotsRatio (X: double type).Explanation / Answer
package soccerpackage;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
public class SoccerPlayer {
private String name;
private Date dob;
private String clubName;
private String countryName;
private int numYellowCards;
private int numRedCards;
private int gamesPlayed;
public SoccerPlayer()
{
super();
Date d = new Date();
this.name = "saurabh";
this.dob = d;
this.clubName = "Barsilona";
this.countryName = "England";
this.numYellowCards = 2;
this.numRedCards = 3;
this.gamesPlayed = 10;
}
public SoccerPlayer(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed) {
this.name = name;
this.dob = dob;
this.clubName = clubName;
this.countryName = countryName;
this.numYellowCards = numYellowCards;
this.numRedCards = numRedCards;
this.gamesPlayed = gamesPlayed;
}
public String getName() {
return name;
}
public Date getDob() {
return dob;
}
public String getClubName() {
return clubName;
}
public String getCountryName() {
return countryName;
}
public int getNumYellowCards() {
return numYellowCards;
}
public int getNumRedCards() {
return numRedCards;
}
public int getGamesPlayed() {
return gamesPlayed;
}
public void setName(String name) {
this.name = name;
}
public void setDob(Date dob) {
this.dob = dob;
}
public void setClubName(String clubName) {
this.clubName = clubName;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public void setNumYellowCards(int numYellowCards) {
this.numYellowCards = numYellowCards;
}
public void setNumRedCards(int numRedCards) {
this.numRedCards = numRedCards;
}
public void setGamesPlayed(int gamesPlayed) {
this.gamesPlayed = gamesPlayed;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SoccerPlayer)) return false;
SoccerPlayer that = (SoccerPlayer) o;
return getNumYellowCards() == that.getNumYellowCards() &&
getNumRedCards() == that.getNumRedCards() &&
getGamesPlayed() == that.getGamesPlayed() &&
Objects.equals(getName(), that.getName()) &&
Objects.equals(getDob(), that.getDob()) &&
Objects.equals(getClubName(), that.getClubName()) &&
Objects.equals(getCountryName(), that.getCountryName());
}
@Override
public int hashCode() {
return Objects.hash(getName(), getDob(), getClubName(), getCountryName(), getNumYellowCards(), getNumRedCards(), getGamesPlayed());
}
@Override
public String toString() {
return "SoccerPlayer{" +
"name='" + name + ''' +
", dob=" + dob +
", clubName='" + clubName + ''' +
", countryName='" + countryName + ''' +
", numYellowCards=" + numYellowCards +
", numRedCards=" + numRedCards +
", gamesPlayed=" + gamesPlayed +
'}';
}
}
******************************************************
package goalkeeperpackage;
import soccerpackage.SoccerPlayer;
import java.util.Date;
import java.util.Objects;
public class Goalkeeper extends SoccerPlayer{
private int goalsAllowed;
private int shotsOnGoal;
private int numSaves;
public int getGoalsAllowed() {
return goalsAllowed;
}
public int getShotsOnGoal() {
return shotsOnGoal;
}
public int getNumSaves() {
return numSaves;
}
public void setGoalsAllowed(int goalsAllowed) {
this.goalsAllowed = goalsAllowed;
}
public void setShotsOnGoal(int shotsOnGoal) {
this.shotsOnGoal = shotsOnGoal;
}
public void setNumSaves(int numSaves) {
this.numSaves = numSaves;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Goalkeeper)) return false;
if (!super.equals(o)) return false;
Goalkeeper that = (Goalkeeper) o;
return getGoalsAllowed() == that.getGoalsAllowed() &&
getShotsOnGoal() == that.getShotsOnGoal() &&
getNumSaves() == that.getNumSaves();
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getGoalsAllowed(), getShotsOnGoal(), getNumSaves());
}
@Override
public String toString() {
return "Goalkeeper{" +
"goalsAllowed=" + goalsAllowed +
", shotsOnGoal=" + shotsOnGoal +
", numSaves=" + numSaves +
'}';
}
public Goalkeeper(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed, int goalsAllowed, int shotsOnGoal, int numSaves) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed);
this.goalsAllowed = goalsAllowed;
this.shotsOnGoal = shotsOnGoal;
this.numSaves = numSaves;
}
public Goalkeeper(int goalsAllowed, int shotsOnGoal, int numSaves) {
this.goalsAllowed = goalsAllowed;
this.shotsOnGoal = shotsOnGoal;
this.numSaves = numSaves;
}
public Goalkeeper()
{
super();
}
}
*********************************************
package forwardcenterforwardpackage;
import java.util.Date;
import java.util.Objects;
public class CenreForward extends Forward {
private int longBallsRecieved;
public CenreForward(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed);
}
public int getLongBallsRecieved() {
return longBallsRecieved;
}
public void setLongBallsRecieved(int longBallsRecieved) {
this.longBallsRecieved = longBallsRecieved;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CenreForward)) return false;
if (!super.equals(o)) return false;
CenreForward that = (CenreForward) o;
return getLongBallsRecieved() == that.getLongBallsRecieved();
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getLongBallsRecieved());
}
@Override
public String toString() {
return "CenreForward{" +
"longBallsRecieved=" + longBallsRecieved +
'}';
}
public CenreForward(int longBallsRecieved) {
this.longBallsRecieved = longBallsRecieved;
}
public CenreForward()
{
super();
}
}
*******************************************
package forwardcenterforwardpackage;
import soccerpackage.SoccerPlayer;
import java.util.Date;
import java.util.Objects;
public class Forward extends SoccerPlayer {
private int goalsScored;
private int numAssists;
private int shotsOnTarget;
public Forward(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed);
}
public int getGoalsScored() {
return goalsScored;
}
public void setGoalsScored(int goalsScored) {
this.goalsScored = goalsScored;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Forward)) return false;
if (!super.equals(o)) return false;
Forward forward = (Forward) o;
return getGoalsScored() == forward.getGoalsScored() &&
numAssists == forward.numAssists &&
shotsOnTarget == forward.shotsOnTarget;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getGoalsScored(), numAssists, shotsOnTarget);
}
@Override
public String toString() {
return "Forward{" +
"goalsScored=" + goalsScored +
", numAssists=" + numAssists +
", shotsOnTarget=" + shotsOnTarget +
'}';
}
public Forward()
{
super();
}
public Forward(int goalsScored, int numAssists, int shotsOnTarget) {
this.goalsScored = goalsScored;
this.numAssists = numAssists;
this.shotsOnTarget = shotsOnTarget;
}
}
******************************************
package forwardcenterforwardpackage;
import java.util.Date;
import java.util.Objects;
public class Striker extends Forward {
private double goalsToShotsRatio;
public Striker(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed, double goalsToShotsRatio) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed);
this.goalsToShotsRatio = goalsToShotsRatio;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Striker)) return false;
if (!super.equals(o)) return false;
Striker striker = (Striker) o;
return Double.compare(striker.goalsToShotsRatio, goalsToShotsRatio) == 0;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), goalsToShotsRatio);
}
@Override
public String toString() {
return "Striker{" +
"goalsToShotsRatio=" + goalsToShotsRatio +
'}';
}
public Striker(double goalsToShotsRatio) {
this.goalsToShotsRatio = goalsToShotsRatio;
}
public Striker(int goalsScored, int numAssists, int shotsOnTarget) {
super(goalsScored, numAssists, shotsOnTarget);
}
public Striker(){
super();
}
}
***************************************
package forwardcenterforwardpackage;
import java.util.Date;
import java.util.Objects;
public class Winger extends Forward {
private int numCrosses;
public Winger(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed);
}
public int getNumCrosses() {
return numCrosses;
}
public void setNumCrosses(int numCrosses) {
this.numCrosses = numCrosses;
}
@Override
public String toString() {
return "Winger{" +
"numCrosses=" + numCrosses +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Winger)) return false;
if (!super.equals(o)) return false;
Winger winger = (Winger) o;
return getNumCrosses() == winger.getNumCrosses();
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getNumCrosses());
}
public Winger() {
super();
}
public Winger(int goalsScored, int numAssists, int shotsOnTarget) {
super(goalsScored, numAssists, shotsOnTarget);
}
}
************************************************
package defensivemidfielderpackage;
import java.util.Date;
import java.util.Objects;
public class CenreMidfielder extends Midfielder {
private int numPasses;
public int getNumPasses() {
return numPasses;
}
public void setNumPasses(int numPasses) {
this.numPasses = numPasses;
}
public CenreMidfielder(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed, int attacksStopped) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed, attacksStopped);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CenreMidfielder)) return false;
if (!super.equals(o)) return false;
CenreMidfielder that = (CenreMidfielder) o;
return getNumPasses() == that.getNumPasses();
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getNumPasses());
}
@Override
public String toString() {
return "CenreMidfielder{" +
"numPasses=" + numPasses +
'}';
}
public CenreMidfielder(int numPasses) {
this.numPasses = numPasses;
}
public CenreMidfielder()
{
super();
}
}
**********************************************
package defensivemidfielderpackage;
import soccerpackage.SoccerPlayer;
import java.util.Date;
import java.util.Objects;
public class DefensiveMidfielder extends Midfielder{
private int intercepts;
public DefensiveMidfielder(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed, int attacksStopped) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed, attacksStopped);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DefensiveMidfielder)) return false;
if (!super.equals(o)) return false;
DefensiveMidfielder that = (DefensiveMidfielder) o;
return intercepts == that.intercepts;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), intercepts);
}
@Override
public String toString() {
return "DefensiveMidfielder{" +
"intercepts=" + intercepts +
'}';
}
public DefensiveMidfielder(int intercepts) {
this.intercepts = intercepts;
}
}
************************************************
package defensivemidfielderpackage;
import soccerpackage.SoccerPlayer;
import java.util.Date;
import java.util.Objects;
public class Midfielder extends SoccerPlayer {
private int attacksStopped;
public Midfielder(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed, int attacksStopped) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed);
this.attacksStopped = attacksStopped;
}
public int getAttacksStopped() {
return attacksStopped;
}
public void setAttacksStopped(int attacksStopped) {
this.attacksStopped = attacksStopped;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Midfielder)) return false;
if (!super.equals(o)) return false;
Midfielder that = (Midfielder) o;
return getAttacksStopped() == that.getAttacksStopped();
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getAttacksStopped());
}
@Override
public String toString() {
return "Midfielder{" +
"attacksStopped=" + attacksStopped +
'}';
}
public Midfielder(int attacksStopped) {
this.attacksStopped = attacksStopped;
}
public Midfielder()
{
super();
}
}
*****************************************
package defensivemidfielderpackage;
import java.util.Date;
import java.util.Objects;
public class WideMidfielder extends Midfielder {
private int chancesCreated;
public WideMidfielder(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed, int attacksStopped, int chancesCreated) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed, attacksStopped);
this.chancesCreated = chancesCreated;
}
public int getChancesCreated() {
return chancesCreated;
}
public void setChancesCreated(int chancesCreated) {
this.chancesCreated = chancesCreated;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof WideMidfielder)) return false;
if (!super.equals(o)) return false;
WideMidfielder that = (WideMidfielder) o;
return getChancesCreated() == that.getChancesCreated();
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getChancesCreated());
}
@Override
public String toString() {
return "WideMidfielder{" +
"chancesCreated=" + chancesCreated +
'}';
}
public WideMidfielder(int attacksStopped) {
super(attacksStopped);
}
public WideMidfielder()
{
super();
}
}
***************************************
package defctrbacksweeperwingbackpackage;
import forwardcenterforwardpackage.CenreForward;
import java.util.Date;
import java.util.Objects;
public class CentreBack extends Defender {
private int shotsBlocked;
public CentreBack(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed, double numTackles) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed, numTackles);
}
public int getShotsBlocked() {
return shotsBlocked;
}
public void setShotsBlocked(int shotsBlocked) {
this.shotsBlocked = shotsBlocked;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CentreBack)) return false;
if (!super.equals(o)) return false;
CentreBack that = (CentreBack) o;
return getShotsBlocked() == that.getShotsBlocked();
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getShotsBlocked());
}
@Override
public String toString() {
return "CentreBack{" +
"shotsBlocked=" + shotsBlocked +
'}';
}
public CentreBack(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed, double numTackles, int shotsBlocked) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed, numTackles);
this.shotsBlocked = shotsBlocked;
}
public CentreBack(int shotsBlocked) {
this.shotsBlocked = shotsBlocked;
}
public CentreBack()
{
super();
}
}
*****************************************************
package defctrbacksweeperwingbackpackage;
import soccerpackage.SoccerPlayer;
import java.util.Date;
import java.util.Objects;
public class Defender extends SoccerPlayer {
private double numTackles;
public double getNumTackles() {
return numTackles;
}
public void setNumTackles(double numTackles) {
this.numTackles = numTackles;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Defender)) return false;
if (!super.equals(o)) return false;
Defender defender = (Defender) o;
return Double.compare(defender.getNumTackles(), getNumTackles()) == 0;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getNumTackles());
}
@Override
public String toString() {
return "Defender{" +
"numTackles=" + numTackles +
'}';
}
public Defender(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed, double numTackles) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed);
this.numTackles = numTackles;
}
public Defender()
{
super();
}
}
****************************************
package defctrbacksweeperwingbackpackage;
import java.util.Date;
import java.util.Objects;
public class Sweeper extends Defender {
private int sweepUps;
public int getSweepUps() {
return sweepUps;
}
public void setSweepUps(int sweepUps) {
this.sweepUps = sweepUps;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Sweeper)) return false;
if (!super.equals(o)) return false;
Sweeper sweeper = (Sweeper) o;
return getSweepUps() == sweeper.getSweepUps();
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getSweepUps());
}
@Override
public String toString() {
return "Sweeper{" +
"sweepUps=" + sweepUps +
'}';
}
public Sweeper(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed, double numTackles) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed, numTackles);
}
public Sweeper(int sweepUps) {
this.sweepUps = sweepUps;
}
public Sweeper()
{
super();
}
}
****************************************
package defctrbacksweeperwingbackpackage;
import java.util.Date;
import java.util.Objects;
public class WingBack extends Defender {
private int throwIns;
public WingBack(String name, Date dob, String clubName, String countryName, int numYellowCards, int numRedCards, int gamesPlayed, double numTackles, int throwIns) {
super(name, dob, clubName, countryName, numYellowCards, numRedCards, gamesPlayed, numTackles);
this.throwIns = throwIns;
}
public int getThrowIns() {
return throwIns;
}
public void setThrowIns(int throwIns) {
this.throwIns = throwIns;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof WingBack)) return false;
if (!super.equals(o)) return false;
WingBack wingBack = (WingBack) o;
return getThrowIns() == wingBack.getThrowIns();
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getThrowIns());
}
@Override
public String toString() {
return "WingBack{" +
"throwIns=" + throwIns +
'}';
}
public WingBack(int throwIns) {
this.throwIns = throwIns;
}
public WingBack()
{
super();
}
}
**************************************************************
import defctrbacksweeperwingbackpackage.CentreBack;
import defctrbacksweeperwingbackpackage.Defender;
import defctrbacksweeperwingbackpackage.Sweeper;
import defctrbacksweeperwingbackpackage.WingBack;
import defensivemidfielderpackage.CenreMidfielder;
import goalkeeperpackage.Goalkeeper;
import soccerpackage.SoccerPlayer;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class Main {
public static void main(String[] args) {
Date d=new Date();
SoccerPlayer soccerPlayer= new SoccerPlayer("priyanka", d, "Barsilona", "England", 4, 2, 6);
Goalkeeper goalkeeper= new Goalkeeper("name1", d, "Barsilona", "England", 4, 2, 6,2, 6, 2);
CentreBack centreBack=new CentreBack("one", d, "new ", "india", 3, 3, 3, 3,3);
Defender defender= new Defender("one", d, "new ", "india", 3, 3, 3, 3);
Sweeper sweeper= new Sweeper("one", d, "new ", "india", 3, 3, 3, 3);
WingBack wingBack= new WingBack("one", d, "new ", "india", 3, 3, 3, 3,4);
CenreMidfielder cenreMidfielder= new CenreMidfielder("dd", d, "yy", "nn", 3, 4, 2,2);
System.out.print(soccerPlayer.toString());
System.out.print(goalkeeper.toString());
System.out.print(defender.toString());
System.out.print(sweeper.toString());
System.out.print(wingBack.toString());
System.out.print(cenreMidfielder.toString());
List<SoccerPlayer> soccerPlayers= new ArrayList<SoccerPlayer>();
for(int i=0;i<18;i++)
{
String name ="Saurabh" + i;
soccerPlayer= new SoccerPlayer(name, d, "Barsilona", "England", 4, 2, 6);
soccerPlayers.add(soccerPlayer);
}
for(SoccerPlayer s:soccerPlayers)
{
System.out.print(s.toString());
}
//Implement these methods as time is less i have not provided solution
int mostNumberOfGoals = mostNumberOfGoals(soccerPlayers);
//Implement these methods as time is less i have not provided solution
int leastNumberOfGoals = leastNumberOfGoals(soccerPlayers);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.