package cin_2010_05_12.solucao1;


/**
 * Crie uma classe chamada MeuArray que: 
 *  1 - Possui um atributo que e um array do tipo inteiro
 *  2 - Possui um construtor que inicializa o atributo com 
 *      um array para 5 inteiros e define os valores inteiros
 *  3 - Possui os seguintes metodos:
 *     3.1 - getSum         - retorna a soma de todos os elementos do vetor;
 *     3.2 - getGreater     - retorna o maior valor inteiro armazenado no vetor;
 *     3.3 - countNumber    - recebe um numero inteiro como par‰metro 
 *                            e retorna o numero de ocorrencias desse numero no vetor
 *     3.4 - changePosition - troca a posicao dos elementos do vetor 
 *                            (inverte a posicao dos elementos do array)
 */
public class MeuArray {
	private int[] arrayInt;
	
	// DIFERENTE DA SOLUCAO 2
	public MeuArray() {
		this.arrayInt = new int[5];
		this.arrayInt[0] = 5;
		this.arrayInt[1] = 4;
		this.arrayInt[2] = 3;
		this.arrayInt[3] = 2;
		this.arrayInt[4] = 1;
	}

	public int getSum() {
		int soma = 0;
		for(int i=0; i< this.arrayInt.length; i++) {
			soma = soma + this.arrayInt[i];
		}
		return soma;
	}

	public int getGreater() {
		int maior = this.arrayInt[0];
		for(int i=1; i< this.arrayInt.length; i++) { 
			if(this.arrayInt[i] > maior) {
				maior = this.arrayInt[i]; 
			}
		}
		return maior;
	}
	
	public int countNumber(int numero) {
		int contador = 0;
		for(int i=0; i< this.arrayInt.length; i++) { 
			if(this.arrayInt[i] == numero) {
				contador++; 
			}
		}
		return contador;
	}
	
	// DIFERENTE DA SOLUCAO 2
	public void changePosition() {
		int[] aux = new int[this.arrayInt.length];
		for(int i=0; i< this.arrayInt.length; i++) { 
			aux[i] = this.arrayInt[this.arrayInt.length-1-i];
		}
		this.arrayInt = aux;
	}
	
	// metodo adicional para dar acesso ao atributo da classe
	public int[] getArrayInt() {
		return this.arrayInt;
	}
}
