Hello, I've very recently the forums and am in need of some help. I've been given a simple program to write, to get some hands on experience with "getters" and "setters". This program will take the values entered by the user and output the the number in the list, the sum, the average, and the smallest and largest numbers in the list. The last part is where I'm having problems. No matter what I do I can't see to find a way to correctly get the largest and smallest value from the user input.
private int getLargest() { return largest; } private void setLargest( int largest ) { largest = largest; } private int getSmallest() { return smallest; } private void setSmallest( int smallest ) { smallest = smallest; } private void clear() { for( int cycle = 0; cycle > count; cycle++ ) { list[ cycle ] = 0; } sum = 0; average = 0; largest = 0; smallest = 0; count = 0; } private void processElement( int element ) { list[ getCount() ] = element; count = getCount() + 1; setCount( count ); sum = getSum() + element; setSum( sum ); average = ((double)getSum() / (double)( getCount() + 1)); setAverage( average ); if ( element >= getLargest() ) { setLargest( element ); } else if ( element <= getSmallest() ) { setSmallest( element ); } }
Sorry if I break any forum rules in posting this question. Any help would be much appreciated, also hows my use of getters and setters?