Monday, 4 April 2016

Program Code


1st Draft of the program code 

(Clickable)
Our program 2nd Draft of the program code


(Clickable)



FINAL DRAFT OF PROGRAM CODE
import java.util.Scanner;
import java.util.*;
class Gap
{
    public static void main(String [] args) throws InputMismatchException
    {
        Scanner in = new Scanner(System.in);
        System.out.println("How many steps:");
int prev = 0;
int steps = 0;
        while(steps == 0)
        {
            try
            {
                steps = in.nextInt();
}
            catch(InputMismatchException e)
            {
                in.nextLine();
                System.out.println("Please re-enter a valid input");
            }
}
     
        while(prev == 0)
        {
            try
            {
                System.out.println("Enter the locations:");
                prev = in.nextInt();
}
            catch(InputMismatchException e)
            {
                in.nextLine();
                System.out.println("Please re-enter a valid input");
            }
}
     
int largestDifference = 0;
int i = 1;
while(i < steps)
        {
            try
{
int next = in.nextInt();
int difference = next - prev;
if(difference > largestDifference)
largestDifference = difference;
prev = next;
i++;
//System.out.println(i);
            }
catch(InputMismatchException e)
{
in.nextLine();
System.out.println("Please re-enter a valid input");
}
        }
        System.out.println("The largest difference is " + largestDifference + ".");
    }
}