Check whether the given series is Arithmetic - Java Quiz Question



Write a program to check whether the given series is Arithmetic. A series is considered to be Arithmetic when difference between two consecutive terms is same.

Input (List) Output (boolean)
[{1 / 1}, {3 / 2}, {2 / 1}, {5 / 2}, {3 / 1}, {7 / 2}, {4 / 1}, {9 / 2}, {5 / 1}, {11 / 2}, {6 / 1}] true
[{1 / 2}, {2 / 3}, {5 / 6}, {1 / 1}, {7 / 6}, {4 / 3}, {3 / 2}, {5 / 3}, {11 / 6}] true
[{-1 / 2}, {-1 / 1}, {-3 / 2}, {-2 / 1}, {-5 / 2}, {-3 / 1}, {-7 / 2}, {-4 / 1}, {-9 / 2}, {-3 / 1}, {-7 / 2}] false
[{5 / 2}, {2 / 3}, {-7 / 6}, {-3 / 1}, {-29 / 6}, {-20 / 3}, {-17 / 2}, {-31 / 3}] true
[{1 / 3}, {7 / 4}, {-7 / 13}, {-7 / 30}, {-7 / 47}, {-7 / 64}, {-7 / 81}, {-1 / 14}, {-7 / 115}] false
[] false

class IsSeriesArithmetic

{    public static void main(String s[])
    {
        List input = new ArrayList();
        input.add(new Fraction(5, 2));
        input.add(new Fraction(2, 3));
        input.add(new Fraction(-7, 6));
        input.add(new Fraction(-3, 1));
        input.add(new Fraction(-29, 6));
        input.add(new Fraction(-20, 3));
        input.add(new Fraction(-17, 2));
        input.add(new Fraction(-31, 3));
        System.out.println("The given series is Arithmetic : " + isArithmeticSeries(input));

    }


public static boolean isArithmeticSeries(List<Fraction> input) {
//Write code here to find the given series is an arithmetic.
}

//If required, write the additional methods here.
}
class Fraction {

int numerator;
int denominator;

public Fraction(int numerator, int denominator) {
this.numerator = numerator;
this.denominator = denominator;
}
}