Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Old MathJax webview Could u show me all the steps and the output? Thanks in advance The class League, outlined below, uses a HashSet to
Old MathJax webview
Could u show me all the steps and the output? Thanks in advance
The class League, outlined below, uses a HashSet to manage a collection of Teams that took part in a league. The public methods of this class are given and your task is to write the code for each of these. The description of the task for each method is described as a comment in the code below. (Class Team is described in Question9 above and you may assume that class Team has an equals and a hashCode method) class League Hash Sets Team> teams = new Hashset(); public void addTeams(HashSet Team> tm){//add set to teams) (2 marks) public Team search(String name) { //search for a team given its name 1 (2 marks) public int numScored(int gls){ //calculate number of teams that scored gls goals (3 marks) public HashSets Team> teams ScoredZero(){ //return a set of the teams that scored 0 goals } (3 marks) Given below is a class Team that has attributes name and goals scored. It has public methods that retrieve information about the current state of the class. You are required to write the methods: equals (6 marks) and hashCode (4 marks). Two teams are said to be equal if they have the same name. class Team{ private String name; private int scored; Team(String n, int gls){name = n; scored = gls;} public String name(){return name;} public int scored(){return scored;} - } (10 marks) name +" Sured if (this ezob! doverride Public String to String () { Doverride return 't Scored, Public int hush lode 1) { @osoreide Public bodeon equals (Object oby) { return Object hash code (nomelj . ; 3 if loby omul 11 objepoteloss () != this.petclass 133 == return false Team geek (Team) oby : pecko name shume -- this name & peck. Scored == this. scored 3 land/ return QUESTION 10 The class League, outlined below, uses a HashSet to manage a collection of Teams that took part in a league. The public methods of this class are given and your task is to write the code for each of these. The description of the task for each method is described as a comment in the code below. (Class Team is described in Question above and you may assume that class Team has an equals and a hashCode method) class League HashSets Team> teams = new Hashset->(); public void addTeams(HashSets Team> tm){//add set to teams) (2 marks) public Team search(String name) //search for a team given its name 1 (2 marks) public int numScored(int gls){ 1/calculate number of teams that scored gls goals (3 marks) public HashSets Team> teams ScoredZero({ //return a set of the teams that scored 0 goals (3 marks) ) (10 marks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started