Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: i need to create a program with array list and 3 file classes but it is hard HELP

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

    /*
     * 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

    /*
     * 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
    Last edited by elvis0288; February 20th, 2012 at 11:17 PM.


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

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

  3. #3
    Member
    Join Date
    Feb 2012
    Posts
    106
    My Mood
    Yeehaw
    Thanks
    8
    Thanked 11 Times in 11 Posts

    Default 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

Similar Threads

  1. create linked list from file?
    By junsugal in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: November 12th, 2011, 11:39 PM
  2. Reading file of floats into array list and sorting into subsets
    By Skave in forum Collections and Generics
    Replies: 2
    Last Post: November 9th, 2011, 06:03 PM
  3. Create an Array wich represent Classes
    By Sjaakie91 in forum Collections and Generics
    Replies: 3
    Last Post: September 21st, 2011, 07:54 AM
  4. In a class create an array list of elements of another class, help!
    By LadyBelka in forum Collections and Generics
    Replies: 3
    Last Post: May 4th, 2011, 05:00 PM
  5. loading things from a text file into an array list
    By sp11k3t3ht3rd in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 6th, 2011, 02:32 PM