Java Programming: The GolfTeam class has a teamName (String), schoolName (String
ID: 3756031 • Letter: J
Question
Java Programming:
The GolfTeam class has a teamName (String), schoolName (String) and a roster/list of Golfers. The roster is implemented using an ArrayList of Golfer objects. Answer the following questions assuming you already have a fully implemented Golfer class.
A. Show the Java code for the GolfTeam class header and the property definitions.
B. Show code for a no-arg constructor that initializes the first two properties to “Panthers” and “College”. The constructor also instantiates the roster ArrayList but leaves it empty.
C. Show the code for the getter and setter methods for the teamName property.
Explanation / Answer
//////////////////part A
import java.util.ArrayList;
public class GolfTeam {
String teamName;
String schoolName;
ArrayList<Golfer> roster ;
}
//////////////////////////////part B
GolfTeam()
{
teamName="Panthers";
schoolName="College";
roster=new ArrayList<Golfer>();
}
/////////////////////partC
void setteamName(String teamName)
{this.teamName=teamName;
}
String getteamName()
{
return teamName;
}
//////////////////fullcode
import java.util.ArrayList;
public class GolfTeam {
String teamName;
String schoolName;
ArrayList<Golfer> roster ;
GolfTeam()
{
teamName="Panthers";
schoolName="College";
roster=new ArrayList<Golfer>();
}
void setteamName(String teamName)
{this.teamName=teamName;
}
String getteamName()
{
return teamName;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.