Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: ArrayList Help

  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ArrayList Help

    I am trying to write a program that has 4 teammates. The first part of the code calculated the number of goals scored by each member. I then have to write a new class that puts each teammate in an arraylist and then has a method that calculated the combined number of goals of the 4 teammates. I am very lost and really don't even know where to start. Can someone please help me? Here is what I have so far. I already have a class that calculates the goals of each teammate.



    Code:
    import java.util.ArrayList;
    
    public class team {
    
    public void teammate(goals teammate){
    
    ArrayList teammate = new ArrayList();
    
    }
    
    
    public double totalGoals() {
    ArrayList teammates = new ArrayList();
    for(int i = 0; i < teammate.size();i++){
    
    Object t = teammate.get(i);
    goals E = (goals) F;
    }
    
    return 0;
    }

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,603
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Wrong forum.

    This is the JavaSCRIPT forum.

    About the only thing Java and JavaScript have in common are the first 4 letters of their names.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,603
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    FWIW, your code makes no sense.
    Code:
    public void teammate(goals teammate){
    
        ArrayList teammate = new ArrayList();
    
    }
    You just used the name teammate to refer to THREE different things!
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •