Error that i cant figure out!...

mypr2.java:71: 'class' or 'interface' expected
public double calcMilesTraveled(dataSet ds, double frstEnt, double sndEnt ) {
^
mypr2.java:122: 'class' or 'interface' expected
^
mypr2.java:128: 'class' or 'interface' expected
^
////////// methods //////////
/////////////////// load data collection ////////////////////////
  public dataCollection loadDataCollection() {
    //String whichTrack = "stock";
    String whichTrack = "gas";
    // Load all datasets from specified directory
    dataCollection dc = new dataCollection("pr2.data/", whichTrack);
    return dc;
/////////////////// tally distance traveled ////////////////////////
  public void tallyDistanceTraveled(dataCollection dc) {
    //  variables: totalDistanceTraveled
    //  set totalDistanceTraveled to 0
    //  loop through all datasets within dataCollection:
    //    milesTraveled = calcMilesTraveled(dataset)
    //    incr totalDistanceTraveled appropriately
System.out.println(
        "\n============= beginning PR2 warmup =========");
System.out.println(
        "\n============= print first stockVal from all files =========");
      int numDataSets = dc.size(); // determine number of data sets in collection
      for (int i=0; i<numDataSets; i++) {
        dataSet ds = dc.get(i); // get the ith dataset
        String  filename = ds.sourceFileName;
        int j = 0;
      //for (int j=0; j<0; j++)
        dataEl  el = ds.get(j); // get the 0th element of the ith dataset
        double value = el.getMainValue(); // get the associated main value
        int dateInt = el.getDateInt();
        //for (int dateInt=0; dateInt<0; dateInt++) {
        System.out.println("data set " + filename + ": value " + value + dateInt);
    // ... continue with our implementation
/////////////////// calcMilesTraveled ////////////////////////
  public double calcMilesTraveled(dataSet ds, double frstEnt, double sndEnt ) {
    // variables:
    //    firstDataEl, lastDataEl (both of type dataEl)
    //    firstDataVal, lastDataVal (both of type double)
    //    milesTraveled
//    firstDataVal, lastDataVal (both of type double)
    //    milesTraveled
    // pseudocode:
    //  assign firstDataEl to the first element of ds
    //  calc number of data elements in dataSet ds
    //  use this to assign lastDataEl to the last element of ds
    //  use these two variables to correctly set firstDataVal and lastDataVal
    //  calculate milesTraveled
    //  return this result
        dataEl firstDataEl = ds.get(frstEnt);
        dataEl lastDataEl  = ds.get(sndEnt);
        double firstDataVal = firstDataEl.getMainValue();
        double lastDataVal = lastDataEl.getMainValue();
        int milesTraveled = 0;
        return milesTraveled;
        //System.out.println("first data" + firstDataEl);
/////////////////// main ////////////////////////
   public static void main(String[] args) {
    // Example to be worked through in class:
    //   calculate the total number of miles reported traveled by
    //   all those watching their odometers
    // Variables: collection (a dataCollection)
    //  collection = loadDataCollection(gas)
    //  tallyDistanceTraveled(collection)
//  tallyDistanceTraveled(collection)
        pr2 myCode = new myCode();
        myCode.calcMilesTraveled(ds,frstEnt,sndEnt);
        myCode.loadDataCollection();
        myCode.tallyDistanceTraveled(dc);
}

You have an extra closing curly brace. As a result, the method that the error message is pointing to is outside of any class, and the compiler is expecting a class declaration.
Just be sure that all your methods are defined inside of classes or interfaces.

Similar Messages

Maybe you are looking for