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 16 of 16

Thread: Client and Class - Error

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    35
    My Mood
    Goofy
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Client and Class - Error

    I've got my client and my class.
    My class seems to be okay, at least on the written part i'm not getting any errors.
    import java.text.DecimalFormat;
     
    public class EncapTest {
    public static void main(String[]args)
    {
        int[]numofTeamHits={22,31,25,21,29,35,33,23,30};
        int[]teamAtBats={102,100,99,81,7576,83,71,90};
        int numOfPlayers=0;
     
        //initiate an object calling the overloaded constructor
        BaseballClient bCli1 = new BaseballClient(numofTeamHits,teamAtBats,numOfPlayers);
     
        //call toString
        System.out.println("bStat1:\n"+bCli1);
     
        //instantiate identical object
        BaseballClient bCli2 = new BaseballClient(numofTeamHits,teamAtBats, numOfPlayers);
     
        //calling accessors
        System.out.println("bStat2\n"+bCli2);
        int[]x=bCli1.getAtBats();
        for(int i=0;i<x.length;i++)
            System.out.print(x[i]+"");
        System.out.println();
     
        //test equals
        if(bCli1.equals(bCli2))
            System.out.println("Equal");
        else
            System.out.println("Not Equal");
     
        //change some data-call mutator
        System.out.println("\nSetting Stat1 and Stat2 arrays to teamHits");
        bCli1.setHits(numofTeamHits);
        bCli2.setHits(numofTeamHits);
     
        System.out.println(bCli1);
        System.out.println("Comparing State1 and Stat2 for equality");
     
        //test average>100
        DecimalFormat average = new DecimalFormat("0.00");
        System.out.println("The average score is" +
                average.format(bCli1.battingAverages()));
     
        //sorting
        System.out.println("\nSorted Score");
        x=bCli1.sortedHits();
        for(int i=0;i<x.length;i++)
            System.out.println(x[i]+"");
        System.out.println();
    }
    }

    But on the client i'm getting errors here:
    public void setAtBats(int[]newAtBats)
    {
        atBats=new int[newAtBats.length];
        for(int i = 0; i <atBats.length;i++);
        atBats[i]= newAtBats[i];
        }
    says empty statement for i and can't find symbol.

    Also getting error here:
    public boolean equals(Object o)
    {
        if(!(o instanceof BaseballClient))
            return false;
        else
        {
            BaseballClient b=(BaseballClient)o;
            if(numberOfPlayers!=b.numberOfPlayers)
                return false;
            for(int i = 0;<atBats.length;i++)
            {
                if(atBats[i]!=b.atBats[i])
                    return false;
            }
            for(int i=0;i<numOfhits.length;i++)
            {
                if(numOfhits[i]!=b.numOfhits[i])
                        return false;
            }
        return true;
    }
    }
    at this part: for(int i = 0;<atBats.length;i++) says incompatible types.

    Here is teh intirety of the client:
    /*
    62. Write a class encapsulating the concept of statistics for a baseball
    team, which has the following attributes: a number of players, a list of
    number of hits for each player, a list of number of at-bats for each player.
    Write the following methods:
    ❑ A constuctor with two equal-length arrays as parameters, the number of hits 
    * per player, and the number of at-bats per player.
    ❑ Accessors, mutators, toString, and equals methods.
    ❑ Generate and return an array of batting averages based on the attributes given.
    ❑ Calculate and return the total number of hits for the team.
    ❑ Calculate and return the number of players with a batting average greater than .300.
    ❑ A method returning an array holding the number of hits,sorted in ascending order.
    Write a client class to test all the methods in your class.
     */
    package natashaepperson_chapter_08_exercise_62;
     
    import java.util.Arrays;
     
    /**
     *
     * @author natasha
     */
    public class BaseballClient {
     
    private int numberOfPlayers;
    private int [] atBats;
    private int []numOfhits;
     
    //constructor
    public BaseballClient(int [] initHits, int [] forAtBats, int num)
    {
        atBats = forAtBats;
        numOfhits= initHits;
        numberOfPlayers=num;
    }
     
    //accessor for numberOfPlayers
    //@return number of players
    public int getNumberOfPlayers()
    {
    return numberOfPlayers;
    }
     
    //@return array with number of at-bats per player
    public int[]getAtBats()
    {
        int [] temp = new int[numberOfPlayers];
        System.arraycopy(atBats, 0, temp, 0, atBats.length);
        return temp;
        }
    //@return array with number of hits per player
    public int[]getHits()
    {
        int[]temp = new int[numberOfPlayers];
        System.arraycopy(numOfhits, 0, temp, 0, numOfhits.length);
        return temp;
        }
    //mutator for atBats
    //newAtBats number of times each player batted
    public void setAtBats(int[]newAtBats)
    {
        atBats=new int[newAtBats.length];
        for(int i = 0; i <atBats.length;i++);
        atBats[i]= newAtBats[i];
        }
    //mutator for atHits
    //newHits number of times each player batted
    public void setHits(int[]newHits)
    {
        numOfhits=new int[newHits.length];
    }
     
    //number of Players, at bats, and hits
    @Override
    public String toString()
    {
        String returnString="";
        for(int i=0;i<numOfhits.length;i++)
            returnString=returnString+(i++)+"\t"+numOfhits[i]
                   +"\t"+atBats[i]+"\n";
        return returnString;
    }
    //true if the numberOfPlayers, atBats, and hits in this object
    //are equal to those in parameter object; false otherwise
    @Override
    public boolean equals(Object o)
    {
        if(!(o instanceof BaseballClient))
            return false;
        else
        {
            BaseballClient b=(BaseballClient)o;
            if(numberOfPlayers!=b.numberOfPlayers)
                return false;
            for(int i = 0;<atBats.length;i++)
            {
                if(atBats[i]!=b.atBats[i])
                    return false;
            }
            for(int i=0;i<numOfhits.length;i++)
            {
                if(numOfhits[i]!=b.numOfhits[i])
                        return false;
            }
        return true;
    }
    }
     
        @Override
        public int hashCode() {
            int hash = 3;
            hash = 97 * hash + this.numberOfPlayers;
            hash = 97 * hash + Arrays.hashCode(this.atBats);
            hash = 97 * hash + Arrays.hashCode(this.numOfhits);
            return hash;
        }
    //return array of batting averages for each player
    public double[]battingAverages()
    {
        double[]temp = new double[numberOfPlayers];
        for(int i = 0; i<numberOfPlayers;i++)
        {
            if(atBats[i]==0)
                temp[i]=0;
            else
                temp[i]=(double)(numOfhits[i]/atBats[i]);
        }
        return temp;
            }
    //return total number of hits for the team
    public int totalHits()
    {
        int total=0;
        for(int i=0;i<numberOfPlayers;i++)
        {
            total=total+numOfhits[i];
            }
        return total;
    }
    public int goodPlayers()
    {
        double average[]=battingAverages();
        int count=0;
        for(int i=0;i<numberOfPlayers;i++)
        {
            if(average[i]>0.300)
            {
                count++;
            }
        }
        return count;
    }
     
    private static int indexOfLargestElement(int[]array,int size)
    {
        int index=0;
        for(int i=0;i<size;i++)
        {
            if(array[i]>array[index])
                index=i;
            }
        return index;
        }
    public int[] sortedHits()
    {
        int[]temp = new int[numOfhits.length];
        System.arraycopy(numOfhits, 0, temp, 0, numOfhits.length);
        int max;
        for(int i=0;i<temp.length;i++)
        {
            max=indexOfLargestElement(temp,temp.length-i);
            int swapTemp=temp[max];
            temp[max]=temp[temp.length-i-1];
            temp[temp.length-i-1]=swapTemp;
        }
        return temp;
        }
     
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Client and Class - Error

    You don't need a semi-colon at the end of this line (the first error):

    for(int i = 0; i <atBats.length;i++);

    The for statement in the next error is incomplete. Review it and fix it.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    nepperso (November 29th, 2013)

  4. #3
    Member
    Join Date
    Sep 2013
    Posts
    35
    My Mood
    Goofy
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Re: Client and Class - Error

    haha DUH
    Thanks

    --- Update ---

    Okay My Client is now correct:
    import java.util.Arrays;
     
    /**
     *
     * @author natasha
     */
    public class BaseballClient {
     
    private int numberOfPlayers;
    private int [] atBats;
    private int []numOfhits;
     
    //constructor
    public BaseballClient(int [] initHits, int [] forAtBats, int num)
    {
        atBats = forAtBats;
        numOfhits= initHits;
        numberOfPlayers=num;
    }
     
    //accessor for numberOfPlayers
    //@return number of players
    public int getNumberOfPlayers()
    {
    return numberOfPlayers;
    }
     
    //@return array with number of at-bats per player
    public int[]getAtBats()
    {
        int [] temp = new int[numberOfPlayers];
        System.arraycopy(atBats, 0, temp, 0, atBats.length);
        return temp;
        }
    //@return array with number of hits per player
    public int[]getHits()
    {
        int[]temp = new int[numberOfPlayers];
        System.arraycopy(numOfhits, 0, temp, 0, numOfhits.length);
        return temp;
        }
    //mutator for atBats
    //newAtBats number of times each player batted
    public void setAtBats(int[]newAtBats)
    {
        atBats=new int[newAtBats.length];
        System.arraycopy(newAtBats, 0, atBats, 0, atBats.length);
        }
    //mutator for atHits
    //newHits number of times each player batted
    public void setHits(int[]newHits)
    {
        numOfhits=new int[newHits.length];
    }
     
    //number of Players, at bats, and hits
    @Override
    public String toString()
    {
        String returnString="";
        for(int i=0;i<numOfhits.length;i++)
            returnString=returnString+(i++)+"\t"+numOfhits[i]
                   +"\t"+atBats[i]+"\n";
        return returnString;
    }
    //true if the numberOfPlayers, atBats, and hits in this object
    //are equal to those in parameter object; false otherwise
    @Override
    public boolean equals(Object o)
    {
        if(!(o instanceof BaseballClient))
            return false;
        else
        {
            BaseballClient b=(BaseballClient)o;
            if(numberOfPlayers!=b.numberOfPlayers)
                return false;
            for(int i = 0;i<atBats.length;i++)
            {
                if(atBats[i]!=b.atBats[i])
                    return false;
            }
            for(int i=0;i<numOfhits.length;i++)
            {
                if(numOfhits[i]!=b.numOfhits[i])
                        return false;
            }
        return true;
    }
    }
     
        @Override
        public int hashCode() {
            int hash = 3;
            hash = 97 * hash + this.numberOfPlayers;
            hash = 97 * hash + Arrays.hashCode(this.atBats);
            hash = 97 * hash + Arrays.hashCode(this.numOfhits);
            return hash;
        }
    //return array of batting averages for each player
    public double[]battingAverages()
    {
        double[]temp = new double[numberOfPlayers];
        for(int i = 0; i<numberOfPlayers;i++)
        {
            if(atBats[i]==0)
                temp[i]=0;
            else
                temp[i]=(double)(numOfhits[i]/atBats[i]);
        }
        return temp;
            }
    //return total number of hits for the team
    public int totalHits()
    {
        int total=0;
        for(int i=0;i<numberOfPlayers;i++)
        {
            total=total+numOfhits[i];
            }
        return total;
    }
    public int goodPlayers()
    {
        double average[]=battingAverages();
        int count=0;
        for(int i=0;i<numberOfPlayers;i++)
        {
            if(average[i]>0.300)
            {
                count++;
            }
        }
        return count;
    }
     
    private static int indexOfLargestElement(int[]array,int size)
    {
        int index=0;
        for(int i=0;i<size;i++)
        {
            if(array[i]>array[index])
                index=i;
            }
        return index;
        }
    public int[] sortedHits()
    {
        int[]temp = new int[numOfhits.length];
        System.arraycopy(numOfhits, 0, temp, 0, numOfhits.length);
        int max;
        for(int i=0;i<temp.length;i++)
        {
            max=indexOfLargestElement(temp,temp.length-i);
            int swapTemp=temp[max];
            temp[max]=temp[temp.length-i-1];
            temp[temp.length-i-1]=swapTemp;
        }
        return temp;
        }
     
    }

    and the class is:
    /*
    Class
     */
    package natashaepperson_chapter_08_exercise_62;
    import java.text.DecimalFormat;
     
    public class EncapTest {
    public static void main(String[]args)
    {
        int[]numofTeamHits={22,31,25,21,29,35,33,23,30};
        int[]teamAtBats={102,100,99,81,7576,83,71,90};
        int numOfPlayers=0;
     
        //initiate an object calling the overloaded constructor
        BaseballClient bCli1 = new BaseballClient(numofTeamHits,teamAtBats,numOfPlayers);
     
        //call toString
        System.out.println("bStat1:\n"+bCli1);
     
        //instantiate identical object
        BaseballClient bCli2 = new BaseballClient(numofTeamHits,teamAtBats, numOfPlayers);
     
        //calling accessors
        System.out.println("bStat2\n"+bCli2);
        int[]x=bCli1.getAtBats();
        for(int i=0;i<x.length;i++)
            System.out.print(x[i]+"");
        System.out.println();
     
        //test equals
        if(bCli1.equals(bCli2))
            System.out.println("Equal");
        else
            System.out.println("Not Equal");
     
        //change some data-call mutator
        System.out.println("\nSetting Stat1 and Stat2 arrays to teamHits");
        bCli1.setHits(numofTeamHits);
        bCli2.setHits(numofTeamHits);
     
        System.out.println(bCli1);
        System.out.println("Comparing State1 and Stat2 for equality");
     
        //test average>100
        DecimalFormat average = new DecimalFormat("0.00");
        System.out.println("The average score is" +
                average.format(bCli1.battingAverages()));
     
        //sorting
        System.out.println("\nSorted Score");
        x=bCli1.sortedHits();
        for(int i=0;i<x.length;i++)
            System.out.println(x[i]+"");
        System.out.println();
    }
    }

    I Get this error when i run it:
    /*
    Class
    */
    package natashaepperson_chapter_08_exercise_62;
    import java.text.DecimalFormat;

    public class EncapTest {
    public static void main(String[]args)
    {
    int[]numofTeamHits={22,31,25,21,29,35,33,23,30};
    int[]teamAtBats={102,100,99,81,7576,83,71,90};
    int numOfPlayers=0;

    //initiate an object calling the overloaded constructor
    BaseballClient bCli1 = new BaseballClient(numofTeamHits,teamAtBats,numOfPlaye rs);

    //call toString
    System.out.println("bStat1:\n"+bCli1);

    //instantiate identical object
    BaseballClient bCli2 = new BaseballClient(numofTeamHits,teamAtBats, numOfPlayers);

    //calling accessors
    System.out.println("bStat2\n"+bCli2);
    int[]x=bCli1.getAtBats();
    for(int i=0;i<x.length;i++)
    System.out.print(x[i]+"");
    System.out.println();

    //test equals
    if(bCli1.equals(bCli2))
    System.out.println("Equal");
    else
    System.out.println("Not Equal");

    //change some data-call mutator
    System.out.println("\nSetting Stat1 and Stat2 arrays to teamHits");
    bCli1.setHits(numofTeamHits);
    bCli2.setHits(numofTeamHits);

    System.out.println(bCli1);
    System.out.println("Comparing State1 and Stat2 for equality");

    //test average>100
    DecimalFormat average = new DecimalFormat("0.00");
    System.out.println("The average score is" +
    average.format(bCli1.battingAverages()));

    //sorting
    System.out.println("\nSorted Score");
    x=bCli1.sortedHits();
    for(int i=0;i<x.length;i++)
    System.out.println(x[i]+"");
    System.out.println();
    }
    }

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Client and Class - Error

    Error?

  6. #5
    Member
    Join Date
    Sep 2013
    Posts
    35
    My Mood
    Goofy
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Re: Client and Class - Error

    sorry, didn't copy the right thing

    run:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 9
    at natashaepperson_chapter_08_exercise_62.BaseballCli ent.toString(BaseballClient.java:78)
    at java.lang.String.valueOf(String.java:2854)
    at java.lang.StringBuilder.append(StringBuilder.java: 128)
    at natashaepperson_chapter_08_exercise_62.EncapTest.m ain(EncapTest.java:18)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)

  7. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Client and Class - Error

    So at line 78 in the BaseballClient class, the toString() method, the index is exceeding the number of elements. Try to find that and fix it yourself, but if you can't, post the code being pointed to by the error message with enough context for us to see what's going on.

  8. #7
    Member
    Join Date
    Sep 2013
    Posts
    35
    My Mood
    Goofy
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Re: Client and Class - Error

    NatashaEpperson_Chapter_08_Exercise_62.zip

    i am not sure why it's exceeding the elements, it should be right

    it's saying here:
    public String toString()
    {
        String returnString="";
        for(int i=0;i<numOfhits.length;i++)
            returnString=returnString+(i++)+"\t"+numOfhits[i]
                   +"\t"+atBats[i]+"\n";
        return returnString;
    }

    and here on the string.java it acts like it wants me to add an override notation but won't let me:
        public static String valueOf(Object obj) {
            return (obj == null) ? "null" : obj.toString();
        }
    and the Encaptest error
        System.out.println("bStat1:\n"+bCli1);
    I also attached the entire program in zip file

  9. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Client and Class - Error

    if 'i' is specified to be as large as the length of numOfhits, what could 'i++' become and what error might that cause? Modifying the for loop control variable inside the for loop body is always risky and must be done carefully.

  10. The Following User Says Thank You to GregBrannon For This Useful Post:

    nepperso (December 1st, 2013)

  11. #9
    Member
    Join Date
    Sep 2013
    Posts
    35
    My Mood
    Goofy
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Re: Client and Class - Error

    how would you suggest to fix it?

  12. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Client and Class - Error

    Use a different variable from the loop control variable.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #11
    Member
    Join Date
    Sep 2013
    Posts
    35
    My Mood
    Goofy
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Re: Client and Class - Error

    so instead of having it be [i]? have it be like [r]?

  14. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Client and Class - Error

    Instead of having (i++) have (r)
    If you don't understand my answer, don't ignore it, ask a question.

  15. #13
    Member
    Join Date
    Sep 2013
    Posts
    35
    My Mood
    Goofy
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Re: Client and Class - Error

    Quote Originally Posted by Norm View Post
    Instead of having (i++) have (r)
    and I should change it where i have numOfhits with i to r? on the client or the class?

    Like so? :
    /*
    62. Write a class encapsulating the concept of statistics for a baseball
    team, which has the following attributes: a number of players, a list of
    number of hits for each player, a list of number of at-bats for each player.
    Write the following methods:
    ❑ A constuctor with two equal-length arrays as parameters, the number of hits 
    * per player, and the number of at-bats per player.
    ❑ Accessors, mutators, toString, and equals methods.
    ❑ Generate and return an array of batting averages based on the attributes given.
    ❑ Calculate and return the total number of hits for the team.
    ❑ Calculate and return the number of players with a batting average greater than .300.
    ❑ A method returning an array holding the number of hits,sorted in ascending order.
    Write a client class to test all the methods in your class.
     */
    package natashaepperson_chapter_08_exercise_62;
     
    import java.util.Arrays;
     
    /**
     *
     * @author natasha
     */
    public class BaseballClient {
     
    private int numberOfPlayers;
    private int [] atBats;
    private int []numOfhits;
     
    //constructor
    public BaseballClient(int [] initHits, int [] forAtBats, int num)
    {
        atBats = forAtBats;
        numOfhits= initHits;
        numberOfPlayers=num;
    }
     
    //accessor for numberOfPlayers
    //@return number of players
    public int getNumberOfPlayers()
    {
    return numberOfPlayers;
    }
     
    //@return array with number of at-bats per player
    public int[]getAtBats()
    {
        int [] temp = new int[numberOfPlayers];
        System.arraycopy(atBats, 0, temp, 0, atBats.length);
        return temp;
        }
    //@return array with number of hits per player
    public int[]getHits()
    {
        int[]temp = new int[numberOfPlayers];
        System.arraycopy(numOfhits, 0, temp, 0, numOfhits.length);
        return temp;
        }
    //mutator for atBats
    //newAtBats number of times each player batted
    public void setAtBats(int[]newAtBats)
    {
        atBats=new int[newAtBats.length];
        System.arraycopy(newAtBats, 0, atBats, 0, atBats.length);
        }
    //mutator for atHits
    //newHits number of times each player batted
    public void setHits(int[]newHits)
    {
        numOfhits=new int[newHits.length];
    }
     
    //number of Players, at bats, and hits
    @Override
    public String toString()
    {
        String returnString="";
        for(int r=0;r<numOfhits.length;r++)
            returnString=returnString+(r++)+"\t"+numOfhits[r]
                   +"\t"+atBats[i]+"\n";
        return returnString;
    }
    //true if the numberOfPlayers, atBats, and hits in this object
    //are equal to those in parameter object; false otherwise
    @Override
    public boolean equals(Object o)
    {
        if(!(o instanceof BaseballClient))
            return false;
        else
        {
            BaseballClient b=(BaseballClient)o;
            if(numberOfPlayers!=b.numberOfPlayers)
                return false;
            for(int i = 0;i<atBats.length;i++)
            {
                if(atBats[i]!=b.atBats[i])
                    return false;
            }
            for(int r=0;r<numOfhits.length;r++)
            {
                if(numOfhits[r]!=b.numOfhits[r])
                        return false;
            }
        return true;
    }
    }
     
        @Override
        public int hashCode() {
            int hash = 3;
            hash = 97 * hash + this.numberOfPlayers;
            hash = 97 * hash + Arrays.hashCode(this.atBats);
            hash = 97 * hash + Arrays.hashCode(this.numOfhits);
            return hash;
        }
    //return array of batting averages for each player
    public double[]battingAverages()
    {
        double[]temp = new double[numberOfPlayers];
        for(int i = 0; i<numberOfPlayers;i++)
        {
            if(atBats[i]==0)
                temp[i]=0;
            else
                temp[i]=(double)(numOfhits[r]/atBats[i]);
        }
        return temp;
            }
    //return total number of hits for the team
    public int totalHits()
    {
        int total=0;
        for(int i=0;i<numberOfPlayers;i++)
        {
            total=total+numOfhits[r];
            }
        return total;
    }
    public int goodPlayers()
    {
        double average[]=battingAverages();
        int count=0;
        for(int i=0;i<numberOfPlayers;i++)
        {
            if(average[i]>0.300)
            {
                count++;
            }
        }
        return count;
    }
     
    private static int indexOfLargestElement(int[]array,int size)
    {
        int index=0;
        for(int i=0;i<size;i++)
        {
            if(array[i]>array[index])
                index=i;
            }
        return index;
        }
    public int[] sortedHits()
    {
        int[]temp = new int[numOfhits.length];
        System.arraycopy(numOfhits, 0, temp, 0, numOfhits.length);
        int max;
        for(int i=0;i<temp.length;i++)
        {
            max=indexOfLargestElement(temp,temp.length-i);
            int swapTemp=temp[max];
            temp[max]=temp[temp.length-i-1];
            temp[temp.length-i-1]=swapTemp;
        }
        return temp;
        }
     
    }

  16. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Client and Class - Error

    What happens when you compile and execute the program? Does it do what you want?
    If you don't understand my answer, don't ignore it, ask a question.

  17. #15
    Member
    Join Date
    Sep 2013
    Posts
    35
    My Mood
    Goofy
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Default Re: Client and Class - Error

    no gave me the same error lol

  18. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Client and Class - Error

    Your changing the variable named i to one named r would NOT change what happens.
    You need to remove the code that changes the value of i (i++)
    What do you want shown where (i++) is used?

    You should NOT change the value of the loop index inside of the loop
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: October 15th, 2013, 04:33 AM
  2. Replies: 0
    Last Post: May 31st, 2012, 05:35 PM
  3. Client error
    By frozen java in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 13th, 2011, 05:31 PM
  4. Applet cannot find client.class?
    By JoshRod in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 18th, 2010, 05:17 PM
  5. Error of "class or interface expected" at Mylong class for problem of API's
    By lostgoat in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 22nd, 2009, 08:28 PM