/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javatest;

   
import java.util.*; 

public class Javatest {
    
    /**
     The declaring of the scanner and the main program lies here
     */
    
    private static Scanner stdin = new Scanner(System.in);
    
    public static void main(String[] args)
    {
         //declaration of variables    
        int numberStoredByUser ;
        int[] numberArray ; 
        int sum = 0;
        // max value taken from - https://www.quickprogrammingtips.com/java/find-smallest-number-in-an-array-using-java.html
	int smallestCount = Integer.MAX_VALUE;
        int largestCount = 0;
        
                
        
        //The user is asked to enter the amount of numbers they want to use. 
        //The number is stored into a variable to use for working out the array number. 
        System.out.printf("Welcome to the Ellis sum calculator\r\n");
        System.out.printf("Please enter the amount of numbers you would like to input :\r\n");
        numberStoredByUser = stdin.nextInt(); 
        System.out.printf("You have chosen this many numbers:\r\n");
        System.out.println(numberStoredByUser);
		
        //The number entered by user being deciding the length of the array 
        numberArray = new int[numberStoredByUser];
        
		// Allowing the user to enter the values into the array 
		System.out.printf("Please enter the numbers you would like to calculate together:\r\n");
        
		// Loop to store numbers entered by users to array. 
		for ( int i=0;i<numberStoredByUser; i++)
		{
			numberArray[i] = Integer.parseInt(stdin.next());
                        //work out the sum of the array 
                        sum = sum + numberArray[i] ;
                        // The smallest and largest sums of Array - credit to https://www.java-examples.com/find-largest-and-smallest-number-array-example

                        if ( numberArray[i] > largestCount)
                        {
                            largestCount = numberArray[i];
                        }
                        
                        if( smallestCount > numberArray[i])
                        {
                            smallestCount = numberArray[i];
                        }
                        
                        
                //loop to check for duplications and once found asks user to reenter new value( not currently working correctly)
		//for( int j = 0 ; j<i ;j ++)
		//{
		//	if ( numberArray[1]== numberArray[j])
                  //          
                  //      {
                   //         numberArray[j] = numberArray[numberStoredByUser - 1];
                    //        System.out.printf("Duplicate found - please enter value again\r\n");
		//
                     //       i--;
                     //   }    
		}
                
                // Printing out of results from user input and ending program
                
                System.out.println("Sum:" + sum);
                
                System.out.println("Largest:" + largestCount);
               
                System.out.println("Smallest:" + smallestCount);
                
                System.out.println("Order:" + Arrays.toString(numberArray));
                
                System.out.println("Thank you for usinf the Ellis sum calcultor");
                // closing the scanner
                stdin.close();
    }
}
    

