Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java programming 1) Part A: Implement the Position enum and the Player class 2) Part B: Implement the Team class 3) Part C: Implement the

java programming

1) Part A: Implement the Position enum and the Player class

2) Part B: Implement the Team class

3) Part C: Implement the loadTeamFromFile(...) method

4) Part D: Implement the writeTeamToFile(...) method

PartATest.txt

Player p1 = new Player("Miles Bridges", 21, 0, Position.FORWARD);

Player p2 = new Player("Nicholas Batum", 24, 5, Position.FORWARD);

Player p3 = new Player("Malik Monk", 21, 1, Position.GUARD);

System.out.println(p1.compareTo(p2));

System.out.println(p1.compareTo(p3));

System.out.println(p2.compareTo(p3));

PartBTest.txt

Player p1 = new Player("Miles Bridges", 21, 0, Position.FORWARD);

Player p2 = new Player("Nicholas Batum", 24, 5, Position.FORWARD);

Player p3 = new Player("Malik Monk", 21, 1, Position.GUARD);

Team team = new Team("Hornets", "Charlotte");

team.addPlayer(p3);

team.addPlayer(p1);

team.addPlayer(p2);

System.out.println(team);

System.out.println("Sorting the players ");

team.sortPlayers();System.out.println(team);

team.txt

Hornet

Charlotte

Dwayne Bacon 24 7 GUARD

Nicholas Batum 24 5 FORWARD

Bismac Biyombo 26 8 CENTER

Miles Bridges 21 0 FORWARD

Joe Chealey 23 31 GUARD

Robert Franks 22 22 FORWARD

Devonte' Graham 24 4 GUARD

Willy Hernangomez24 9 CENTER

Ahmed Hill 24 20 GUARD

Michael Kidd-Gilchrist 26 14 FORWARD

Caleb Martin 24 10 FORWARD

Cody Martin 24 11 FORWARD

Malik Monk 21 1 GUARD

Josh Perkins 24 55 FORWARD

Terry Rozier 25 3 GUARD

Kobi Simmons 22 23 GUARDP

.J. Washington 21 25 FORWARD

Thomas Welsh 23 54 CENTER

Marvin Williams 32 2 FORWARD

Cody Zeller 26 40 FORWARD

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
5) Implement the constructor, the getters, and the setters. 6) Implement the toString () method, which will return a String that contains the player's name, age, jersey number, and position, separated by a tab. e.g., Kemba Walker 28 15 GUARD 7) Make Player class implement the Comparable interface. 8) Override the compareTo () method so that Player objects can be compared by position and jersey number. Specifically, objects should be compared by position first, then compared by jersey number if the positions are the same. Every enum has a built-in compareTo () method, which is based on the order in which the options in the enum are defined. You should use this method to compare positions. 9) Add a new class to the Project called Start. In this class, add a main () method. 10) To test your Player class, copy paste the code in PartATest. txt into the main () method. 1 1) Run your project. You should see the following output: -1 Part B: Implement the Team class 1) Add a new class to the project called Team. 2) Add fields to the class according to the UML class diagram. 3) Implement the constructor. Don't forget to create/initialize the ArrayList. 4) Implement the getters and the setters. 5) Implement the addPlayer (..) method, which will add a Player object to the player's list. 6) Implement the sortPlayers () method, which will sort the players in the ArrayList. Use the Collections. sort () method to implement this. 7) Implement the tostring () method, which returns a multiline String, including the name of the team, the city, and the players on the team (each player should be on a separate line). The String is formatted as follows:Hornet Charlotte PLAYERS Dwayne Bacon 24 GUARD Nicholas Batum 24 5 FORWARD Bismac Biyombo 26 8 CENTER Miles Bridges 21 FORWARD Joe Chealey 23 31 GUARD Robert Franks 22 22 FORWARD Devonte' Graham 24 4 GUARD Willy Hernangomez 24 9 CENTER Ahmed Hill 24 20 GUARD Michael Kidd-Gilchrist 26 14 FORWARD Caleb Martin 24 10 FORWARD Cody Martin 24 11 FORWARD Malik Monk 21 1 GUARD Josh Perkins 24 55 FORWARD Terry Rozier 25 3 GUARD Kobi Simmons 22 23 GUARD P. J. Washington 21 25 FORWARD Thomas Welsh 23 54 CENTER Marvin Williams 32 2 FORWARD Cody Zeller 26 40 FORWARD Part D: Implement the writeTeamToFile (...) method In this part, you will implement a method to write a given Team object to a file. 1) In Start. java, add the following method: public static void writeTeamToFile (Team team, String fileName) This is a static method, which will create or overwrite the file located at the fileName passed as a parameter. The Team object should be written in the same format as in team, txt. 2) You will use the PrintWriter class to write the file. Begin by creating an object of the PrintWriter class. When you call the constructor of the PrintWriter class, NetBeans reminds you that there is a complier error as the constructor can potentially throw a FileNotFoundException. Fix this by using a try-catch bock. In the catch block, print out "The file cannot be found.Preamble: For this Lab, you will simulate a basketball team, which contains three classes and an enum type. The UML class diagram for the project is as follow. Start > > Position Comparable + main(String[ ]): void FORWARD + loadTeamFromFile(String fileName): Team CENTER + compare To(T other): int + write Team ToFile(Team team. String fileName): void GUARD A Uses A Uses Implements V Player Team - name: String name: String age: int city; String jerseyNumber; int players: ArrayList position: Position + Team(String name, String city) * Player(String name, int age, int number, + getName(): String + getCity(): String -Uses- - Position position) + getPlayers(): ArrayList + getName(): String + setName(String name): void getAge(): int + setCity(String city): void * getJerseyNumber(): int + addPlayer(Player p): void * getPosition(): Postion + sortPlayers(): void * setAge(): void * toString(): String * setJerseyNumber(int number) void * setPosition(Position position): void * to String(): String * compare To(Player o) int Part A: Implement the Position enum and the Player class 1) Create a new project in NetBeans called Lab8TeamManagement. Uncheck the "Create Main Class" checkbox before creating this project. 2) Add a new class to the project called Position. In Position. java, change it from a class to an enum type. It provides three options: FORWARD, CENTER and GUARD. 3) Add a new class to the project called Player. 4) Add fields to the Player class according to the UML class diagram.Hornets Charlotte PLAYERS (list of players) 8) To test your Team class, comment out all of the statements in the main () method, then copy paste the code in PartBTest. txt to the main() method. 9) Run your project. You should see the following output: Hornets Charlotte PLAYERS Malik Monk GUARD Miles Bridges 21 21 FORWARD Nicholas Batum 24 FORWARD Sorting the players Hornets Charlotte PLAYERS Miles Bridges 21 FORWARD Nicholas Batum 24 FORWARD Malik Monk 21 GUARD Part C: Implement the loadTeamFromFile (..) method We need a large amount data to set up a team and all of its players. Instead of asking the user to enter everything through the keyboard, we will read the data from a file. 1) In Start. java, add the following method: public static Team loadTeamFromFile (String fileName) This is a static method, which will read the file located at the fileName passed as a parameter. The file that will be used to test your method stores information about an NBA team in the following format

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions