The major issue I am having right now is my client class cannot run/compile, I tried different methods to fix it from calling it from overload constructor and setScores but neither work.

Scoresclient.java:16: error: cannot find symbol
    myScores.setScores();
            ^
  symbol:   method setScores()
  location: variable myScores of type Scanner
Scoresclient.java:18: error: cannot find symbol
    System.out.println("The average score is: " + myScores.average() );
                                                          ^
  symbol:   method average()
  location: variable myScores of type Scanner
Scoresclient.java:20: error: cannot find symbol
    System.out.println("The highest overall score is: " + myScores.highestscores() );
                                                                  ^
  symbol:   method highestscores()
  location: variable myScores of type Scanner
Scoresclient.java:22: error: cannot find symbol
    System.out.println("The lowest overall score is: " + myScores.lowestscores() );
                                                                 ^
  symbol:   method lowestscores()
  location: variable myScores of type Scanner
4 errors

This is my service class

/**
 * Java Car Service class
 * @author blake
 * 2/20/2012
 */

 import java.util.Scanner;
 import java.io.*;


 public class Scores
 {

   private final int MAX=20;
    private int[] scores = new int[MAX];
    private int inUse = 0;

    public Scores()
    {
    }

  public Scores(String File) throws IOException

  {
  File myfile = new File("myfile.dat");
  Scanner inputFile = new Scanner(myfile);
  inUse =0;

     while (inputFile.hasNext() && inUse < scores.length)
        {
           scores[inUse] = inputFile.nextInt();
            inUse++;
      }


  }*/

  public static void setScores() throws IOException
  {
  File myfile = new File("myfile.dat");
  Scanner inputFile = new Scanner(myfile);
  inUse =0;

  while (inputFile.hasNext() && inUse < scores.length)
        {
           scores[inUse] = inputFile.nextInt();
            inUse++;



      }
  }


  public String toString()
  {
  String result = "";

  result = scores[0] + "/t" + scores[1] + "/t" + scores[2] + "/t" + scores[3] + "/t" + scores[4] + "/t" + scores[5] + "/t" + scores[6] + "/t" + scores[7] + "/t" + scores[8] + "/t" + scores[9] + "/t" + scores[10] + "/t" + scores[11] + "/t" + scores[12] + "/t" + scores[13] + "/t" + scores[14] + "/t" + scores[15] + "/t" + scores[16] + "/t" + scores[17] + "/t" + scores[18] + "/t" + scores[19];
  for (int i = 0; i < scores.length; i++)
         result += scores[i] + "\t";
  return result;
  }  

  public int averages()

  {
  int avg;
  avg = scores[1] + scores[2] + scores[3] + scores[4] + scores[5] + scores[6] + scores[7] + scores[8] + scores[9] + scores[10] + scores[11] + scores[12] + scores[13] + scores[14] + scores[15] + scores[16] + scores[17] + scores[18] + scores[19] + scores[20];
  for (int i = 0; i < scores.length; i++)
                avg += scores[i];
  return avg;
  }

  public int lowestscores()
   {
    int smallest = Integer.MAX_VALUE;

    for (int i = 0; i < scores.length; i++)
            if (scores[i] < smallest)
                smallest = scores[i];

    return smallest;
    }

  public int highestscores()
  {
  int highest = -Integer.MAX_VALUE;

  for (int i = 0; i < scores.length; i++)
            if (scores[i] > highest)
                highest = scores[i];


    return highest;
    }
}

This is my client class

/**
 * Java Car Service class
 * @author blake
 * 2/2
 **/

import java.util.Scanner;
import java.io.*;

public class Scoresclient
{

   public static void main(String[] args) throws IOException
    {
    Scanner myScores = new Scanner(System.in);
    myScores.setScores();

    System.out.println("The average score is: " + myScores.average() );

    System.out.println("The highest overall score is: " + myScores.highestscores() );

    System.out.println("The lowest overall score is: " + myScores.lowestscores() );

}

}

It should be working but just getting it to accept the set method but it's not for some reason.

Recommended Answers

All 7 Replies

The compiler is complaining because it can not find the methods you are trying to use with a Scanner object in the Scanner class. Did you mean to define myScores as some other class object instead of as a Scanner? Perhaps as a Score?

no I did not, I did not define it anywhere except for the application/client class so I could print out the method.

What is this?

Scanner myScores = new Scanner(System.in);

yeah I am using that to call my setscores method, so when I print it out it gives me number 20 or 30 or whatever it asks for.

okay figured out what the error was, I am suppose to call in scores object instance instead of scanner.

but then I got this error

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 20
    at Scores.averages(Scores.java:69)
    at Scoresclient.main(Scoresclient.java:18)

The code tried to index an array with a value past the end of the array. Remember the indexes to arrays range in value from 0 to the array's length-1. For example the max index for an array with 20 elements is 19.

Check your logic at line 69 to make sure the index does not go past the end of the array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.