i need to create a program with array list and 3 file classes but it is hard HELP
ok this is what the professor want us to do:
Description
There are two data files you’ll need to build your league; Teams.txt and Players.txt. Teams.txt contains the names of the teams in your league while Players.txt has one line of data for each player. Here are excerpts from the two files:
Teams.txt
Diamondbacks
Braves
Cubs
...
Giants
Cardinals
Nationals
Players.txt
Diamondbacks Aquino Greg 325000 Pitcher
Diamondbacks Bruney Brian 322500 Pitcher
Diamondbacks Cintron Alex 360000 Shortstop
Diamondbacks Clayton Royce 1350000 Shortstop
Diamondbacks Counsell Craig 1350000 Second Baseman
Diamondbacks Cruz Jose 4000000 Outfielder
Diamondbacks Estes Shawn 2500000 Pitcher
...
Nationals Sledge Terrmel 345000 Outfielder
Nationals Tucker TJ 657000 Pitcher
Nationals Vargas Claudio 325000 Pitcher
Nationals Vidro Jose 7000000 Second Baseman
Nationals Wilkerson Brad 3050000 Outfielder
1. Player and Team Classes
Your Player should have a name, position and salary, along with the appropriate get/set methods and a toString() method.
Your Team class should have a team name and an ArrayList of players. You’ll also need to add a couple of methods to your Team class.
- a method to add players to your Team
- a method to retrieve the highest paid player on your team by position
Player getHighPay(“Pitcher”)
- a method that returns the cumulative payroll for your team
int getPayroll()
- you should add other methods as you see necessary
2. League Class
Define a League class that has a league name and an ArrayList of Teams. Here are a few methods you may want for your League. You should add others as you see necessary:
- void createTeams(): reads the Teams.txt data file, instantiates a team object for each team name in the file and adds it to the array list of teams.
- void populateTeams(): reads the Players.txt data file, instantiates a player object for each player in the file and adds it to the correct team.
- void openFiles(): opens the data files
- void closeFiles(): closes the data files
- void outputToFile(ArrayList<Player> list): outputs the contents of the ArrayList to a file.
- ArrayList<Player> getHighPaidInfield(String teamName): for the given team, return an ArrayList with the highest paid infielders. In other words, the highest paid pitcher on the team, catcher, first baseman, second baseman, third baseman and shortstop. Hint: You might want to think about calling the getHighPay() method that you have already written multiple times.
- void displayTeam(String teamName): displays all players on the roster to the console.
- Team getHighPayrollTeam(): returns the team with the highest overall payroll in the league.
3. Testing your classes
Add a main method to your League class or create a separate class with a main method. Use the following to test your classes:
League national = new League("National");
national.displayTeam("Cardinals");
ArrayList<Player> infield = national.getHighPaidInfield("Dodgers");
national.outputToFile(infield);
Team t = national.getHighPayrollTeam();
System.out.println("Highest paid team is the " + t.getName() +
" with a payroll of " + t.getPayroll());
4. Checking your results
Using the given data file, the highest paid team is the Mets. They had a payroll of 101,305,821.
The highest paid infield on the Dodgers roster consists of:
Pitcher: Darren Dreifort
Catcher: Paul Bako
First Baseman: Olmedo Saenz
Second Base: Jeff Kent
Third Baseman: Jason Grabowski
Shortstop: Jose Valentin
so far i can do easily the first part i mean the player class which i will show you right now so this is my player class
Code :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package HomeWork06;
import java.io.*;
import java.util.*;
/**
*
* @author ElvisBoss
*/
public class Player
{
private String Name;
private String Position;
private int Salary;
public Player(){
}
public String getName()
{
return Name;
}
public String getPosition()
{
return Position;
}
public int Salary()
{
return Salary;
}
public String toString()
{
return "Player Name = " + Name + " Player Position = " + Position
+ " Player Salary = " + Salary;
}
}
the second class that is Team class i start with this but i do not think it is right
Code :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package HomeWork06;
/**
*
* @author ElvisBoss
*/
import java.io.*;
import java.util.*;
public class Team
{
private String TeamName;
ArrayList playerList = new ArrayList();
public void addPlayers()
{
}
public String getHighPay(String Position)
{
return Position;
}
public int getPayroll()
{
return Total;
}
}
so that one is easy now the other 2 i am completely lost please HELP i will really appreciate it... THANK YOU
Re: i need to create a program with array list and 3 file classes but it is hard HELP
Welcome to Java Programming Forums elvis0288. If you read the rules, you will easily find out, how to get the best answer of your question. Well, please post SSCCEShort, Self Contained, Correct Example.
Ask an appropriate question and get appropriate answer.
Re: i need to create a program with array list and 3 file classes but it is hard HELP
(What class is this for?)
I first want to know what your main problem is.
Class structure, or what code to use to read the txt files so you can use the info in them?
If your problem is class structure, think of the IS A/HAS A relationships.
A Player HASA name,position,salary. Looks good.
A Team HASA name, list of players(you use an ArrayList). also looks good.
Nothing too complicated about a League
a League HASA name, list of Teams.(asks for ArrayList). so you would fill the ArrayList with "Team" Objects. (that you make with your Team Class)
something like this (which I am sure you got)
ArrayList teamList = new ArrayList();
I would like to point out, that you are using default constructors.
much much better to initialize your Objects when they are created.(let me know if you need help with that)
So the League methods then?
A lot of these methods are requiring you to write code that uses a txt file resource.(scary I know!)
I would search your notes/book for I/O chapters.(input/output).
Come back here and post what kind of I/O is used so I can freshen up on the api.
While you wait (1day?) Google I/O api that your teacher/book uses.
or
Post more specific questions in the input/output thread. You can keep posting here, and I will try to brush up on my first year I/O.
Hopefully hear from you soon,
Jonathan