Is there a better way to do this?
- From: John <jtlinux1@xxxxxxxx>
- Date: 28 Jul 2007 01:02:55 GMT
I gave it a shot, to answer the question that that person posted here a couple of days ago
Create a java program that generates 10000 random integer numbers
between 1 and 500. Then use the generated numbers to calculate:
- the mean (average) of all numbers
- the standard deviation
- the largest and smallest number
- the median number (50% is above it, 50% is below it)
- the mode (the number(s) that occurs most frequently)
The hardest part was the "mode" part.
At first I thought I'd use arrays, but then I realized that using an ArrayList<Integer> would let me use the various methods associated with the Collections class
So I wrote my program, tested it with some small numbers. It looks ok, and when I run it with 10000 occurances of randoms 1-500 I get decent results. And it does answer the question, so I'd probably get 50% on it for sure. But is it wel written? And I don't mean comments. I mean does it follow the OO rules? I put one static method in to fill up the ArrayList of randoms, but can I take it further? Or is there a point where you've over-done it?
Anyway, here's a link to my code. I'd appreciate any comments or critisim. I think it's a good first attempt, but it's not something I'd want to turn in to a professor, yet.
http://sparklesthecat.is-a-geek.com/code/Hello.java
I know it's not a very imaginative name, but it's not going on the market.
--
John T.
My other computer is a swodniw machine
2007
.
- Follow-Ups:
- Re: Is there a better way to do this?
- From: Oliver Wong
- Re: Is there a better way to do this?
- From: Patricia Shanahan
- Re: Is there a better way to do this?
- From: Roedy Green
- Re: Is there a better way to do this?
- Prev by Date: Re: Pixelgrabber and Vectors, changes not happening.
- Next by Date: Re: Pixelgrabber and Vectors, changes not happening.
- Previous by thread: Need Help Making an Alias for a Java Plugin
- Next by thread: Re: Is there a better way to do this?
- Index(es):