Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Maintain a team roster Operation This application maintains a roster for a sport

ID: 643623 • Letter: M

Question

Maintain a team roster

Operation
   This application maintains a roster for a sports team. Each player has a last name, a first name, and a number.
   When the user selects a player from the combo box, the application lists the players name and number in the text fields. The user can then click the Edit or Delete button to edit or delete the player.
   If the user clicks the Edit button, the text fields are enabled, the Add, Edit, and Delete buttons are disabled, and the Accept and Cancel buttons are enabled. If the user then clicks the Accept button, any changes the user made to the players data are saved. If the user clicks Cancel, any changes are discarded.
   If the user clicks the Delete button, the player is immediately removed.
   If the user clicks the Add button, the text fields are cleared and enabled, the Add, Edit, and Delete buttons are disabled, and the Accept and Cancel buttons are enabled. The user can then enter data for a new player and click the Accept button to add the player. If the user clicks the Cancel button, the player is not added.
Specifications
   Create a Player class to represent a player. Should contain these three instance variables - Players last name, first name and a number and any methods needed.
   To simplify this project, a TeamIO class has been supplied for you to simulate the presence of a file. This class has a static getTeam method that returns an ArrayList of players. The ArrayList will be populated with the roster thats hard coded into the class, so no actual file I/O is performed. The class should also have a static saveTeam method that accepts an ArrayList of Player objects and displays the list on the console. This helps you verify that your program is working.
   When the application starts, it should call the getTeam method to get the team roster. Then, each time the user adds, changes, or deletes a player, the application should call the saveTeam method to save the changes.
   Include data validation that requires entries in all three text fields.
   Create an event handler for the focusGained event of a text field to select the text in any of the text fields on this form when the text field receives the focus.
   Create an event handler for the keyTyped event of a text field to restrict the input for the player number to the numbers 0 to 9.
Note
   TeamIO is supplied
   The structure of this application is similar to the structure of the Product Maintenance application shown in chapter 16. As a result, you can use the Product Maintenance application as a model for this application. Thou the Product Maintenance pulls from a file you can use the same concept as in Project II which developed a MovieIO as an ArrayList you will use the TeamIO to develop the ArrayList for this project.

Team IO file:

package murach.io;

import java.util.ArrayList;
import murach.business.Player;

public class TeamIO
{
public static ArrayList getTeam()
{
// This method returns an array list filled with the roster of the
// USA 2004 olympic softball team.
// In an actual application, it would return data read from a file.

ArrayList team = new ArrayList();
team.add(new Player("Berg", "Laura", 44));
team.add(new Player("Bustos", "Crystl", 6));
team.add(new Player("Clark", "Jamie", 24));
team.add(new Player("Fernandez", "Lisa", 16));
team.add(new Player("Finch", "Jennie", 27));
team.add(new Player("Flowers", "Tairia", 11));
team.add(new Player("Freed", "Amanda", 7));
team.add(new Player("Giordano", "Nicole", 4));
team.add(new Player("Harrigan", "Lori", 21));
team.add(new Player("Jung", "Lovieanne", 3));
team.add(new Player("Kretchman", "Kelly", 12));
team.add(new Player("Lappin", "Lauren", 37));
team.add(new Player("Mendoza", "Jessica", 2));
team.add(new Player("O'Brien-Amico", "Lisa", 20));
team.add(new Player("Nuveman", "Stacy", 33));
team.add(new Player("Osterman", "Catherine", 8));
team.add(new Player("Topping", "Jennie", 31));
team.add(new Player("Watley", "Natasha", 29));
return team;
}

public static void saveTeam(ArrayList team)
{
// This method displays the team roster on the console so you can
// verify that the maintenance logic of the main application works.
// In an actual application, this method would write the data to a file.

System.out.println("****************************************");
for (Player p : team)
System.out.println(p.getNumber() + " "
+ p.getLastName() + ", " + p.getFirstName());
System.out.println("**************************************** ");
}

}

Maintain a team roster Operation This application maintains a roster for a sports team. Each player has a last name, a first name, and a number. When the user selects a player from the combo box, the application lists the players name and number in the text fields. The user can then click the Edit or Delete button to edit or delete the player. If the user clicks the Edit button, the text fields are enabled, the Add, Edit, and Delete buttons are disabled, and the Accept and Cancel buttons are enabled. If the user then clicks the Accept button, any changes the user made to the players data are saved. If the user clicks Cancel, any changes are discarded. If the user clicks the Delete button, the player is immediately removed. If the user clicks the Add button, the text fields are cleared and enabled, the Add, Edit, and Delete buttons are disabled, and the Accept and Cancel buttons are enabled. The user can then enter data for a new player and click the Accept button to add the player. If the user clicks the Cancel button, the player is not added. Specifications Create a Player class to represent a player. Should contain these three instance variables - Players last name, first name and a number and any methods needed. To simplify this project, a TeamIO class has been supplied for you to simulate the presence of a file. This class has a static getTeam method that returns an ArrayList of players. The ArrayList will be populated with the roster thats hard coded into the class, so no actual file I/O is performed. The class should also have a static saveTeam method that accepts an ArrayList of Player objects and displays the list on the console. This helps you verify that your program is working. When the application starts, it should call the getTeam method to get the team roster. Then, each time the user adds, changes, or deletes a player, the application should call the saveTeam method to save the changes. Include data validation that requires entries in all three text fields. Create an event handler for the focusGained event of a text field to select the text in any of the text fields on this form when the text field receives the focus. Create an event handler for the keyTyped event of a text field to restrict the input for the player number to the numbers 0 to 9. Note TeamIO is supplied The structure of this application is similar to the structure of the Product Maintenance application shown in chapter 16. As a result, you can use the Product Maintenance application as a model for this application. Thou the Product Maintenance pulls from a file you can use the same concept as in Project II which developed a MovieIO as an ArrayList you will use the TeamIO to develop the ArrayList for this project.

Explanation / Answer

import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.JTextComponent; import java.util.ArrayList; import java.text.*; import java.lang.*; import java.util.*; public class TeamRosterAppTest { public static void main(String[] args) { TeamIO.getTeam(); JFrame frame = new TeamRosterFrame(); frame.setVisible(true); } } class Player { String lname; String fname; int number; public Player() { lname = ""; fname = ""; number = 0; } public Player(String lname, String fname, int number) { this.lname = lname; this.fname = fname; this.number = number; } public void setLastName(String lname) { this.lname = lname; } public String getLastName() { return lname; } public void setFirstName(String fname) { this.fname = fname; } public String getFirstName() { return fname; } public void setNumber(int number) { this.number = number; } public int getNumber() { return number; } } class TeamIO { private static final ArrayList team = new ArrayList(); public static ArrayList getTeam() { team.add(new Player("Campbell", "Corey", 69)); team.add(new Player("Berg", "Laura", 44)); team.add(new Player("Bustos", "Crystl", 6)); team.add(new Player("Clark", "Jamie", 24)); team.add(new Player("Fernandez", "Lisa", 16)); team.add(new Player("Finch", "Jennie", 27)); team.add(new Player("Flowers", "Tairia", 11)); team.add(new Player("Freed", "Amanda", 7)); team.add(new Player("Giordano", "Nicole", 4)); team.add(new Player("Harrigan", "Lori", 21)); team.add(new Player("Jung", "Lovieanne", 3)); team.add(new Player("Kretchman", "Kelly", 12)); team.add(new Player("Lappin", "Lauren", 37)); team.add(new Player("Mendoza", "Jessica", 2)); team.add(new Player("O'Brien-Amico", "Lisa", 20)); team.add(new Player("Nuveman", "Stacy", 33)); team.add(new Player("Osterman", "Catherine", 8)); team.add(new Player("Topping", "Jennie", 31)); team.add(new Player("Watley", "Natasha", 29)); //System.out.println(" Opening team list" + " " + "****************************************"); //for(int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote