8 Replies - 353 Views - Last Post: 25 November 2012 - 08:46 AM Rate Topic: -----

#1 jfuentes2975  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 10-August 11

Exception in thread "main" java.lang.RuntimeException: Uncompi

Posted 24 November 2012 - 08:37 PM

Ok so I am so lost right now please someone guide me. So so far I can read the file fine but have trouble calulating the averages for the teams.

I should be able to do the following
  • Display teams and batting averages (done used 20 players)
  • Calculate teams average
  • Get min/max
  • diplay teams with above 300 average

I attached my txt file and pasted the code. Running NetBeans and Thank you

Here is my array
package teamstatisticeclient;
import java.io.*;
import java.util.*;
/**
 *
 * Juan Fuentes
 * Project 5
 */
public class TeamStatistic 
{
    private int NAME_OF_TEAMS;
    private String[] numberOfTeams;
    public int fileSize;
    private int [] totalHits;
   private int [] totalHitsAverages;
   private int [] hits;
   private int [] hitStat;
    
    
    
    //constructor
    public TeamStatistic(String fileName)throws IOException
    {
        numberOfTeams = new String [NAME_OF_TEAMS];
        
        File input = new File (fileName);
        Scanner file = new Scanner (input);
        /*************************************************************
         * Ms Anderson I tried doing the below array based on the    *
         * snippet but i could not get it to work.  So I tried an    *
         * ArrayList (the While loop)and that work to read the file  *
         *************************************************************/
        for (int i = 0; 1 <numberOfTeams.length;i++)
        {
            numberOfTeams[i] = file.nextLine();
        }
        //My arrayList
        while ( file.hasNext() )
        {
            file.nextLine();
            fileSize++;
        }
        file.close();
        numberOfTeams = new String[fileSize];
        int i = 0;
        
        file = new Scanner (input);
        
        while ( file.hasNext() )
        {
   
            numberOfTeams[i++] = file.nextLine();
        }
        
        file.close();
        
    }
    //List teams
    public int teams(String title)
    {
        for (int i=0; i < numberOfTeams.length;i++)
        {
            if (numberOfTeams[i].equalsIgnoreCase(title))
                return -1;
        }
        return -1;
    }
    public String toString()
    {
        String teamList = "";
        for (int i=0; i < numberOfTeams.length;i++)
        {
            teamList += numberOfTeams[i] + "\n";
        }
        return teamList;
    }
    

//team batting averages
    public double[] battingAverages()
    {
        int [] totalHitsAverages= new Integer.parseInt(numberOfTeams);
        
        for(int i = 0; 1 <numberOfTeams.length;i++)
        {
            if(totalHitsAverages[i]==0)
                totalHitsAverages[i]=0;
            else
                hitStat[i]=(int)(hits[i]/totalHitsAverages[i]);
        }
        return hitStat;
    }
    //totalHitsAverages
    // @ return total number of hits for the team
    public int totalHitsAverages()
    {
        int total=0;
        for(int i = 0; 1 <numberOfTeams.length;i++)
        {
            total= total+hits[i];
        }
        return total;
    }
    //good players
    // @ return number of players with batting avg>30
    public int goodPlayers()
    {
        double average[] = battingAverages();
        int count=0;
        
        for(int i = 0; 1 <numberOfTeams.length;i++)
        {
            if(average[i]>=300)
            {
                count++;
            }
        }
        return count;
    }
    private static int maxMinHits(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 [] hitStat = new int[hits.length];
        for(int i=0;i<hits.length;i++)
            hitStat[i]=hits[i];
        int max;
        for(int i=0;i<hitStat.length;i++)
        {
            max=maxMinHits(hitStat,hitStat.length-i);
            int swapTemp= hitStat[max];
            hitStat[max]=hitStat[hitStat.length-i-1];
            hitStat[hitStat.length-i-1]=swapTemp;
        }
        return hitStat;
    }
}


Here is my client
package teamstatisticeclient;

import java.util.*;
import java.io.*;
import java.text.*;
/**
 *
 *Juan Fuentes
 */
public class TeamStatisticeClient 
{
   
    public static void main(String[] args) throws IOException
    {
        Scanner scan = new Scanner(System.in);
         //NumberFormat average = new DecimalFormat ("0.00");
        
        System.out.print ("Enter the name of the input file: ");
        String fileName = scan.nextLine();
        
        TeamStatistic teamsListed = new TeamStatistic(fileName);
        
        System.out.println("\t\t\t\t\t\t\t\t\t *****Listed teams***** " 
                +"\n"+ teamsListed);

        Scanner hits = new Scanner(System.in);
        
  
     //calling accessors
       
     
     //change some data-call mutator
     System.out.println("\nBlah");
     hitStat.totalHitsaverages(teamHits);
     //bStat2.totalHits(teamHits);

     System.out.println(hitStat);
     System.out.println("Comparing Stat1 and Stat2 for equality");


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




Here is what output min you before everything after line 85 was added I was able to display the Teams and player
averages
run:
Enter the name of the input file: TeamStatisticFile.txt
*****Listed teams*****
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
ARI 273 348 301 340 244 240 308 357 283 349 282 288 270 333 305 229 254 338 194 323
at teamstatisticeclient.TeamStatisticeClient.main(ATL 275 350 303 342 246 242 310 359 285 351 284 290 272 335 307 231 256 340 196 325
TeamStatisticeClient.java:31)
BAL 277 352 305 344 248 244 312 361 287 353 286 292 274 337 309 233 258 342 198 327
BOS 279 354 307 346 250 246 314 363 289 355 288 294 276 339 311 235 260 344 200 329
CHC 281 356 309 348 252 248 316 365 291 357 290 296 278 341 313 237 262 346 202 331
CHW 283 358 311 350 254 250 318 367 293 359 292 298 280 343 315 239 264 348 204 333
CIN 285 360 313 352 256 252 320 369 295 361 294 300 282 345 317 241 266 350 206 335
CLE 287 362 315 354 258 254 322 371 297 363 296 302 284 347 319 243 268 352 208 337
COL 289 364 317 356 260 256 324 373 299 365 298 304 286 349 321 245 270 354 210 339
DET 291 366 319 358 262 258 326 375 301 367 300 306 288 351 323 247 272 356 212 341
HOU 293 368 321 360 264 260 328 377 303 369 302 308 290 353 325 249 274 358 214 343
KCR 295 370 323 362 266 262 330 379 305 371 304 310 292 355 327 251 276 360 216 345
LAA 297 372 325 364 268 264 332 381 307 373 306 312 294 357 329 253 278 362 218 347
MIA 299 374 327 366 270 266 334 383 309 375 308 314 296 359 331 255 280 364 220 349
MIL 301 376 329 368 272 268 336 385 311 377 310 316 298 361 333 257 282 366 222 351
MIN 303 378 331 370 274 270 338 387 313 379 312 318 300 363 335 259 284 368 224 353
NYM 305 380 333 372 276 272 340 389 315 381 314 320 302 365 337 261 286 370 226 355
NYY 307 382 335 374 278 274 342 391 317 383 316 322 304 367 339 263 288 372 228 357
OAK 309 384 337 376 280 276 344 393 319 385 318 324 306 369 341 265 290 374 230 359
PHI 311 386 339 378 282 278 346 395 321 387 320 326 308 371 343 267 292 376 232 361

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Exception in thread "main" java.lang.RuntimeException: Uncompi

#2 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7283
  • View blog
  • Posts: 12,079
  • Joined: 19-March 11

Re: Exception in thread "main" java.lang.RuntimeException: Uncompi

Posted 24 November 2012 - 09:47 PM

I'm not sure how you got to that state - that's an exception I don't think I've ever seen before. However, it's clearly the case that you have source code that can't be compiled - your client shows all sorts of compile-time errors. Delete your .class files and recompile, you'll see a bunch of errors that you need to fix. Fix them and recompile, and you should be good. Unless there are logic errors, but I'm not even looking for those in code that won't compile.
Was This Post Helpful? 0
  • +
  • -

#3 bgammill  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 39
  • Joined: 11-June 12

Re: Exception in thread "main" java.lang.RuntimeException: Uncompi

Posted 24 November 2012 - 09:53 PM

I glanced through your code, recreated the classes you've specified, and found numerous errors. First, some of your variable calls are spelled incorrectly. Second, you're using the wrong object to call methods in the TeamStatistic class. Third, you've declared hitStat as an integer array while trying to return it from a method with a double array return type. NetBeans should've picked up all of those simple fixes.
Was This Post Helpful? 0
  • +
  • -

#4 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7283
  • View blog
  • Posts: 12,079
  • Joined: 19-March 11

Re: Exception in thread "main" java.lang.RuntimeException: Uncompi

Posted 24 November 2012 - 10:00 PM

View Postbgammill, on 24 November 2012 - 11:53 PM, said:

NetBeans You should've picked up all of those simple fixes.


FTFY - if you rely on your IDE to find this stuff, you must immediately stop using your IDE until you can find them for yourself!

This post has been edited by jon.kiparsky: 24 November 2012 - 10:01 PM

Was This Post Helpful? 1
  • +
  • -

#5 bgammill  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 39
  • Joined: 11-June 12

Re: Exception in thread "main" java.lang.RuntimeException: Uncompi

Posted 24 November 2012 - 10:29 PM

View Postjon.kiparsky, on 25 November 2012 - 12:00 AM, said:

View Postbgammill, on 24 November 2012 - 11:53 PM, said:

NetBeans You should've picked up all of those simple fixes.


FTFY - if you rely on your IDE to find this stuff, you must immediately stop using your IDE until you can find them for yourself!

Posted Image
Was This Post Helpful? -1
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Exception in thread "main" java.lang.RuntimeException: Uncompi

Posted 24 November 2012 - 10:37 PM

If it is the way you see it.... become an actor forget about programming :)
Was This Post Helpful? 0
  • +
  • -

#7 bgammill  Icon User is offline

  • New D.I.C Head

Reputation: 12
  • View blog
  • Posts: 39
  • Joined: 11-June 12

Re: Exception in thread "main" java.lang.RuntimeException: Uncompi

Posted 24 November 2012 - 10:46 PM

View Postpbl, on 25 November 2012 - 12:37 AM, said:

If it is the way you see it.... become an actor forget about programming :)/>

I agree with the post to a point; but I think it it's unconstructive. Relying on an IDE for help is neither here nor there. If you're relying on your textbook for help, should you stop? If you're relying on your professor for help, should you stop? An IDE is meant to be a crutch, and I'm sure the OP knows that.
Was This Post Helpful? 0
  • +
  • -

#8 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7283
  • View blog
  • Posts: 12,079
  • Joined: 19-March 11

Re: Exception in thread "main" java.lang.RuntimeException: Uncompi

Posted 24 November 2012 - 11:01 PM

View Postbgammill, on 25 November 2012 - 12:46 AM, said:

I agree with the post to a point; but I think it it's unconstructive. Relying on an IDE for help is neither here nor there. If you're relying on your textbook for help, should you stop? If you're relying on your professor for help, should you stop?


I think your examples miss the mark. Relying on a book is generally self-correcting. Over time, when you look things up in books or ask some knowledgeable person about them, you learn about them. When you accept suggestions from an IDE, you do not learn them, and in fact you are actively avoiding learning them.
Memory is constructed by attending to some detail about the world, working on it in short term memory, and building associations with it which add to a semantic network in the brain. If you look something up in a book, translate it into your current context, and apply it, you are attending to a detail, workingg on it in short term memory, and building associations. Likewise, if you ask someone about a construction, and they explain it to you, if they're any good they'll explain it in a way that forces you to work with them, asking you to make key connections in the argument, making sure you're working through the logic rather than just nodding along - so again, you're building associations.

If the IDE throws a suggestion at you, you might glance at it, but there's no place for you to involve yourself with it. The whole point is to remove any need for you to think about it. This is very useful for an experienced programmer, who has already thought about it, but it's a disaster for a novice, who needs precisely to spend their time thinking through these details and attending to them and learning about them.

So no, I don't think that books and mentors (professorial or otherwise) are like IDEs, in that they don't prevent you from learning the way an IDE does.

Quote

An IDE is meant to be a crutch, and I'm sure the OP knows that.


Crutches are great if you have a broken leg - then they help you walk around. But if you don't have a broken leg, why would you want a crutch? They're not going to make you stronger, that's for sure.
Was This Post Helpful? 2
  • +
  • -

#9 jfuentes2975  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 10-August 11

Re: Exception in thread "main" java.lang.RuntimeException: Uncompi

Posted 25 November 2012 - 08:46 AM

View Postjon.kiparsky, on 24 November 2012 - 10:00 PM, said:

View Postbgammill, on 24 November 2012 - 11:53 PM, said:

NetBeans You should've picked up all of those simple fixes.


FTFY - if you rely on your IDE to find this stuff, you must immediately stop using your IDE until you can find them for yourself!


I trying to learn it my self. actually I work with it in Dr Java then copy it over to Netbeans. I start a class on java in January and have been trying to get a heads up. One book has these practice code and gave me a snippet for a grades module to reference I did the Movie ticket one fine this is just giving me trouble.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1