Question: 1. Create a class to hold data about a high school sports team. The Team class holds data fields for high school name (such as
1. Create a class to hold data about a high school sports team. The Team class holds data fields for high school name (such as Roosevelt High), sport (such as Girls Basketball), and team name (such as Dolphins). Include a constructor that takes parameters for each field, and include get methods that return the values of the fields. Also include a public final static String named MOTTOand initialize it to Sportsmanship!
2. Create a class named Game. Include two Team fields that hold data about the teams participating in the game. Also include a field for game time (for example, 7 PM). Include a constructor that takes parameters for two Team objects and a time.
Please help this is the second time posting this question
Given code :
public class Game { //declaring instance variables HighSchoolSportsTeam team1 ; HighSchoolSportsTeam team2 ; String time ; //defining constructor public Game(HighSchoolSportsTeam team1,HighSchoolSportsTeam team2,String gameTime) { this.team1 = team1; this.team2 = team2; time = gameTime; } public static void main(String args[]) { HighSchoolSportsTeam school1 = new HighSchoolSportsTeam("Roosevelt High","Girls Basketball","Dolphins"); HighSchoolSportsTeam school2 = new HighSchoolSportsTeam("DumbleDor High","Girls Basketball","Wizards"); System.out.println("Team1 details is:"); System.out.println(school1); System.out.println("Team2 details is:"); System.out.println(school2); Game game = new Game(school1,school2,"7 PM"); System.out.println("The game is between below two teams:"); System.out.println(game.team1); System.out.println(game.team2); System.out.println(" The game starts at "+game.time); } }
public class TestGame { public static void main(String[] args) { Team team1 = new Team("Roosevelt High", "Girls Basketball", "Dolphins"); Team team2 = new Team("Hoover High", "Girls Basketball", "Tigers"); Game game1 = new Game(team1, team2, "7 PM"); display(game1); } public static void display(Game g) { Team t1 = g.getTeam1(); Team t2 = g.getTeam2(); System.out.println("The game between " + t1.getName() + " " + t1.getSport() + " " + t1.getMascot()); System.out.println(" and " + t2.getName() + " " + t2.getSport() + " " + t2.getMascot()); System.out.println(" takes place at " + g.getTime()); } }
public class Team { //declare a constant public final static String MOTTO = "Sportsmanship!"; //declaring instance variables private String schoolName; private String sportName; private String teamName; //declare default constructor public Team(String school, String sport, String team) { schoolName = school; sportName = sport; team = teamName; } //method to set the school name public void setSchoolName(String schoolName) { this.schoolName = schoolName; }
//method to set the sport name public void setSportName(String sportName) { this.sportName = sportName; }
//method to set the team name public void setTeamName(String teamName) { this.teamName = teamName; }
//method to return school name public String getSchoolName() { return schoolName; }
//method to return sport name public String getSportName() { return sportName; }
//method to return team name public String getTeamName() { return teamName; }
//toSting method to return string with class details public String toString() { return "School Name: " + schoolName + " Sport Name: " + sportName + " Team Name: " + teamName; } }
public class TestTeam { public static void main(String args[]) { // create three Team objects with different values Team team1 = new Team("Roosevelt High", "Girls Basketball", "Dolphins"); Team team2 = new Team("DumbleDor High", "Boys Baseball", "Wizards"); Team team3 = new Team("DumbleDor High", "Boys Baseball", "Wizards"); // display the details of the team1 System.out.println("\t+++ Team1 details +++"); System.out.println(Team.MOTTO); System.out.println(team1.toString()); System.out.println(); // display the details of the team2 System.out.println("\t+++ Team2 details +++"); System.out.println(Team.MOTTO); System.out.println(team2.toString()); System.out.println(); // display the details of the team3 System.out.println("\t+++ Team3 details +++"); System.out.println(Team.MOTTO); System.out.println(team3.toString()); System.out.println(); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
