• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

TestScores

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/*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.

*/
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 }.
 
Rancher
Posts: 4804
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/*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
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic