File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes TestScores Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "TestScores" Watch "TestScores" New topic
Author

TestScores

Curtis Bridges
Greenhorn

Joined: Jul 26, 2007
Posts: 9
/*Please help. I'm trying to throw an IllegalArgumentException.
*If any test score in the array is negative or greater than 100
*using a try block, but am having little if any progress after 9 hours of work.
* I am still getting an error mesage saying illegal start of expression and ) expected on line 48.
*The program will compute the average and display an Error invalid Score!message for average over 100
* but only calculates the - average without the Error invalid Score! message.
*Please help to make this work.
*
*
*Instructions:
Write a class named TestScores.
The class constructor should accept an array of test scores as its argument.
The class should have a method that returns the average of the test scores.
If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException.
Demonstrate the class in a program.

*/
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
Originally posted by Curtis Bridges:



Most likely, it is a missing or extra ( ) { or }.

Your try, catch, and finally are the ones involved. Bad syntax. Try see samples of try catch blocks to see correct matching of those delimiters, especially { and }.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

Originally posted by Curtis Bridges:
/*Please help. I'm trying to throw an IllegalArgumentException.


Problem isolation is all about removing stuff until it works and then
adding back in stuff until it breaks.

Hack out 90% of your code, specifically all the details on grades, to get the code to be under 15 lines.

Then add stuff back slowly.
Curtis Bridges
Greenhorn

Joined: Jul 26, 2007
Posts: 9
/*Please help. I'm trying to throw an IllegalArgumentException.
*If any test score in the array is negative or greater than 100
*using a try block, but am having little if any progress after many days of work.
* I am still getting an error mesage saying not a statement on line 74 and ";"expected on the same line
*The program will compute the average and display an Error invalid Score!message for an average over 100
and will compute a negative average and display an Error invalid Score!message for an average below 0 , but
It is not doing this using the try block. The way I am interpreting the instructions is that the try block is
to make this happen, if any testScore is entered that is neg. or > 100 before the average is calculated.
Would someone please make the corrections, so that I can see what I'm missing. I have read several tutorials
and can't find the answer. I have tore this down and built it back one line at a time.

*Instructions:
Write a class named TestScores.
The class constructor should accept an array of test scores as its argument.
The class should have a method that returns the average of the test scores.
If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException.
Demonstrate the class in a program.

*/
[/CODE]
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
Normally, you design, or write in plain english the steps that your program should do. Then code it.

Well, your code has improved a lot since your first post above.

Some that I noticed:
- why use array of char? shouldnt it be an array of int?
- when you test the scores if negative, you should loop thru the entire array to test each (using for example, a for loop)

The first step in debugging your code is looking at the error message. It says what is the error, and which line. You can check that line why the compiler is complaining about it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TestScores