Question

In: Computer Science

Create a class Team to hold data about a college sports team. The Team class holds...

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. Create a UML class diagram as well.

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. Create a UML class diagram as well.

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// Team.java

public class Team {

      // attributes and constants

      private String collegeName;

      private String sport;

      private String teamName;

      public final static String MOTTO = "Sportsmanship!";

      // constructor taking values for all fields

      public Team(String collegeName, String sport, String teamName) {

            this.collegeName = collegeName;

            this.sport = sport;

            this.teamName = teamName;

      }

      // getter methods

      public String getCollegeName() {

            return collegeName;

      }

      public String getSport() {

            return sport;

      }

      public String getTeamName() {

            return teamName;

      }

}

// TestTeam.java

import javax.swing.JOptionPane;

public class TestTeam {

      // method to display details of an array of teams

      static void displayTeams(Team teams[]) {

            String data = "";

            // appending all team info to a string

            for (int i = 0; i < teams.length; i++) {

                  data += "College Name: " + teams[i].getCollegeName() + ", Sport: "

                              + teams[i].getSport() + ", Team Name: "

                              + teams[i].getTeamName() + ", MOTTO: " + teams[i].MOTTO

                              /* note: MOTTO can be called by Team.MOTTO or teams[i].MOTTO*/

                              + "\n";

            }

            // displaying using JOptionPane window

            JOptionPane.showMessageDialog(null, data.trim());

      }

      public static void main(String[] args) {

            //creating an array of 3 Teams

            Team teams[] = new Team[3];

            //looping and filling with 3 Team objects

            for (int i = 0; i < teams.length; i++) {

                  //getting inputs for current team

                  String college = JOptionPane

                              .showInputDialog("Enter college name for team " + (i + 1));

                  String sport = JOptionPane.showInputDialog("Enter sport for team "

                              + (i + 1));

                  String teamName = JOptionPane

                              .showInputDialog("Enter team name for team " + (i + 1));

                  //creating a team and adding to array

                  teams[i] = new Team(college, sport, teamName);

            }

            //displaying teams

            displayTeams(teams);

      }

}

/*UML , INPUT&OUTPUT*/



Related Solutions

Create a class Team to hold data about a college sports team. The Team class holds...
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...
Create a class BankAccount to hold at least the following data / information about a bank...
Create a class BankAccount to hold at least the following data / information about a bank account: Account balance Total number of deposits Total number of withdrawals Interest rate e.g., annual rate = 0.05 Service charges per month The class should have the following member functions: Constructor To set the required data. It may be parameterized or user’s input. depositAmount A virtual function used to accept an argument for the amount to be deposited. It should add the argument (amount)...
Create a class that holds data about a job applicant. Include a name, a phone number,...
Create a class that holds data about a job applicant. Include a name, a phone number, and four Boolean fields that represent whether the applicant is skilled in each of the following areas: word processing, spreadsheets, databases, and graphics: Include a constructor that accepts values for each of the fields. Also include a get method for each field. Create an application that instantiates several job applicant objects and pass each in turn to a Boolean method that determines whether each...
Using Java: Create a class that will hold the information about a clock, called Clock. You...
Using Java: Create a class that will hold the information about a clock, called Clock. You need to keep minutes, hours and seconds in military time (24-hour) format. Include member functions that will setTime ( this will set the hours, minutes and seconds of the clock), getHours (return the hours), getMinutes (return the minutes) and getSeconds (return the seconds). Another method printTime which will print the time out like this 03:13:09 (hours:minutes:seconds). Overloaded constructors that will take in hours, minutes...
Create a class named CollegeCourse that includes the following data fields: dept (String) - holds the...
Create a class named CollegeCourse that includes the following data fields: dept (String) - holds the department (for example, ENG) id (int) - the course number (for example, 101) credits (double) - the credits (for example, 3) price (double) - the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display() method that displays the course data....
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG),...
Create a class named CollegeCourse that includes data fields that hold the department (for example, ENG), the course number (for example, 101), the credits (for example, 3), and the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display() method that displays the course data. Create a subclass named LabCourse that adds $50 to the course fee....
Java program Create a constructor for a class named Signal that will hold digitized acceleration data....
Java program Create a constructor for a class named Signal that will hold digitized acceleration data. Signal has the following field declarations private     double timeStep;               // time between each data point     int numberOfPoints;          // number of data samples in array     double [] acceleration = new double [1000];          // acceleration data     double [] velocity = new double [1000];        // calculated velocity data     double [] displacement = new double [1000];        // calculated disp data The constructor...
Write a class named RetailItem that holds data about an item in retail store.
Python 3Your program will have 2 classes:A) RetailItem ClassWrite a class named RetailItem that holds data about an item in retail store.Attributes: The class should store following data in attributes:>item_Name> PriceMethods:> RetailItem class’s __init__ method should accept an argument for each attribute.> RetailItem class should also have accessor and mutator methods for each attributeB) MainMenu ClassAttributes: The class should store following data in attributes:> List of RetailItem Objects: InventoryMethods:> createInventory(): method to create three RetailItem Objects store in list Inventory...
a. Design a class named ItemForSale that holds data about items placed for sale on Carlos's...
a. Design a class named ItemForSale that holds data about items placed for sale on Carlos's List, a classified advertising website. Fields include an ad number, item description, asking price, and phone number. Include get and set methods for each field. Include a static method that displays the website's motto ("Sell Stuff Locally!"). Include two overloaded constructors as follows: A default constructor that sets the ad number to 101, the asking price to $1, and the item description and phone...
The sports saga with MRSA continues. A recent article in the NY Times about college sports...
The sports saga with MRSA continues. A recent article in the NY Times about college sports described “To prevent teammates from sharing towels to wipe their faces or arms on the sideline, trainers have sometimes employed a small army of interns who scoop up any used towel so it can quickly be placed in the laundry. Jim Thornton, the athletic trainer at Clarion University in Pennsylvania, said his teams had begun using chemically treated towelettes that are about half the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT