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. 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.

Solutions

Expert Solution


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);
   }

}


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. Create a UML class diagram as well....
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...
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...
java For this assignment, you will create a Time class that holds an hour value and...
java For this assignment, you will create a Time class that holds an hour value and a minute value to represent a time. We will be using "military time", so 12:01 AM is 0001 and 1 PM is 1300. For this assignment, you may assume valid military times range from 0000 to 2359. Valid standard times range from 12:00 AM to 11:59 PM. In previous assignments, we had a requirement that your class be named Main. In this assignment, the...
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...
A sports team has a stadium that holds a maximum of 36,000 fans. The league has suggested that the owners of the team consider expanding its seating to 40,000.
A sports team has a stadium that holds a maximum of 36,000 fans. The league has suggested that the owners of the team consider expanding its seating to 40,000. The cost of permits, project management, and construction is expected to be $40,000 per seat. Work can be accomplished over two years, at which time the club will have 4,000 additional seats to sell. Assume the investment would occur equally over years 0 and 1.Each seat will generate an additional $3,500...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT