In: Computer Science
Create a class Team to hold data about a college sports team. The Team class holds data fields for college name (such as Hampton College), sport (such as Soccer), and team name (such as Tigers). Include a constructor that takes parameters for each field, and get methods that return the values of the fields. Also include a public final static String named MOTTO and initialize it to Sportsmanship! Save the class in Team.java. Write an application named TestTeam with the main method which declares and instantiates three Team objects with different values for their fields. Accept field values as a user input (utilizing JOptionPane) for each of team fields and assign those to proper instances of Team class (three sets of three input strings will be needed to fill all fields in each of three Team objects). Add a displayTeams method which displays all the data, including the motto, for each instantiated Team objects. When doing so use JOptionPane again and format the output in orderly fashion, one team data per a separate line. Save the class as TestTeam .java.
import javax.swing.JOptionPane;
class Team {
private String collegeName;
private String sports;
private String teamName;
public static String MOTTO = "Sportsmanship!";
public Team(String aCollegeName, String aSports,
String aTeamName) {
super();
collegeName = aCollegeName;
sports = aSports;
teamName = aTeamName;
}
public String getCollegeName() {
return collegeName;
}
public void setCollegeName(String aCollegeName)
{
collegeName = aCollegeName;
}
public String getSports() {
return sports;
}
public void setSports(String aSports) {
sports = aSports;
}
public String getTeamName() {
return teamName;
}
public void setTeamName(String aTeamName) {
teamName = aTeamName;
}
public static String getMotto() {
return MOTTO;
}
public static void setMotto(String aMotto) {
MOTTO = aMotto;
}
@Override
public String toString() {
return "CollegeName : " +
collegeName + ", Sports : " + sports + ", Team Name : " +
teamName;
}
}
public class TestTeam {
public static void main(String[] args) {
String cname =
JOptionPane.showInputDialog("Enter College Name ?");
String teamname =
JOptionPane.showInputDialog("Enter team Name ?");
String sports =
JOptionPane.showInputDialog("Enter sports Name ?");
Team t1 = new Team(cname, sports,
teamname);
cname =
JOptionPane.showInputDialog("Enter College Name ?");
teamname =
JOptionPane.showInputDialog("Enter team Name ?");
sports =
JOptionPane.showInputDialog("Enter sports Name ?");
Team t2 = new Team(cname, sports,
teamname);
cname =
JOptionPane.showInputDialog("Enter College Name ?");
teamname =
JOptionPane.showInputDialog("Enter team Name ?");
sports =
JOptionPane.showInputDialog("Enter sports Name ?");
Team t3 = new Team(cname, sports,
teamname);
displayData(t1, t2, t3);
}
private static void displayData(Team t1, Team t2,
Team t3) {
String msg = t1 + " " + Team.MOTTO
+ "\n" + t2 + " " + Team.MOTTO + "\n" + t3 + " " +
Team.MOTTO;
JOptionPane.showMessageDialog(null,
msg);
}
}