TestScores Class

I have written the code for the following problem and would just like some feedback before I move on. The problem states:

Write a class names TestScores. The class constructor should accept an array of test scores as its arguement. 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 IllegalArguementException. Demonstrate the class in a program.

you actually need two classes to do this assignment. you gather the test scores in the array as your doing and that looks good. But that will be your interface type class. once you have them in the array, it says take that array and pass it to class test scores through the constructor. so the interface class, which seems to be what you are writing, creates a test score object and feeds the constructor the array you populated. from what i read the work of calculating an average and giving output happens in the second class , test scores, not the interface.

Also, you want a method that returns an average of the test scores. I'm guessing that the specification means actually return, and not just print out. So you want to change your main method to another method that returns a double, and return the average. You can pretty much keep everything you have in main and just change the name of the method and have it return a double. Hope that helps.

I am not really understanding why I need two classes. Doesn't the program I wrote accomplish the task? It seems to complicate the problem to add another class...

Here is problem two from the same chapter that builds on the last problem.

Write an exception class named InvalidTestScore. Modify the TestScores class you wrote in Programming Challenge 1 so that it throws an InvalidTestScore exception if any of the test scores in the array are invalid.

Modify the TestScores class that you created for Programming Challenge 1 to be serializable. Write a program that creates an array of at least 5 TestScore objects and serializes them. Write another program that deserializes the objects from the file.

I am going to re-read the section serialization and let you know how it goes.

Mainly i dont see how you can implement this requirement otherwise, "The class constructor should accept an array of test scores as its arguement". I just got that from your problem. I don't see any constructors in your code. Really all you are doing is creating a class with a constructor , and an average method that returns the average. The constructor you will have to write new, the average method and display of output you can simply move from where it is to being under the new class for the most part, though the class would have to populate the test scores array from the constructor and it would use that data. your exception is probably thrown in this new class.

Modify the TestScores class that you created for Programming Challenge 1 to be serializable[\quote]

i'm not as up on serialization. If your set of homework problems is covering multiple topics, I might recommend starting a new post with a clear title, like java serialization question. The concern is that as this first thread grows with more posts, perhaps fewer people might be willing to dive in or they may think most issues are resolved and you are just doing followup.

I remember when i was in school i needed prompt answers to specific questions because hours or days wait can cause the flow of helpful information to not come in, in time, to meet my deadline.

I think you should revisit the first problem by actually creating a constructor and an average method.

Constructor :

public TestScores ( double[] grade )
{
... //probably want to copy the inputted array into your own array to manipulate in the average method
}

You should also not throw your exception in your try/catch block. Logically you could use an if/else statement to handle any problems there. I think you should create two classes. A driver class and a class with the constructor and the average method. Use the driver class to call/manipulate the methods from the other class as well as implement the try/catch block.

I believe you should also override the exception method with a string parameter :

public InvalidTestScore ( String message )
{
super(message);
}

You really should start a new thread for new problems to get the best help.

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...