Hello, I'm creating a program called Fractions where you create a fraction and get to do operations like subtracting, multiplying, adding them etc. However, I need to make a method that takes the Fraction objects that are already instantiated and put them into an array and then returns the array. Since I'm not very experienced with arrays I'm kind of stuck and need help please. In case anyone is wondering what my code for the Fraction program is so far(please ignore the red font/comment code):

Code:`package fractions;`

import java.lang.Math;

/**

*

* @author Dennis

*/

public class Fraction {

private int numerator;

private int denominator;

public final static int ARRAY_SIZE = 5;

// private int gdc;

public Fraction (int numerator, int denominator) {

this.numerator = numerator;

this.denominator = denominator;

// gdc = 0;

setFraction(numerator , denominator);

// if(numerator % 2 == 0 && denominator % 2 == 0) {

// greatestcommonDiviser(numerator , denominator);

// }

// else if(numerator % 3 == 0 && denominator % 3 == 0) {

// greatestcommonDiviser(numerator, denominator);

// }

}

public Fraction() {

numerator = 0;

denominator = 0;

// gdc = 0;

}

public void setFraction(int numerator, int denominator) {

//boolean switch = false;

this.numerator = numerator;

this.denominator = denominator;

if(denominator == 0) {

System.out.println("The fraction is undefined");

System.exit(0);

}

else if(denominator < 0) {

this.denominator = Math.abs(denominator);

this.numerator = numerator * -1;

}

else if(numerator == denominator) {

this.numerator = numerator / denominator;

this.denominator = denominator / numerator;

}

simplify(numerator, denominator);

}

private int greatestcommonDiviser(int numerator, int denominator) {

this.numerator = numerator;

this.denominator = denominator;

while(numerator != denominator) {

if(numerator > denominator) {

numerator = numerator - denominator;

}

else {

denominator = denominator - numerator;

}

}

return numerator;

}

public Fraction simplify(int numerator, int denominator) {

Fraction other = new Fraction();

this.numerator = numerator;

System.out.println(this.numerator + " Num");

this.denominator = denominator;

System.out.println(this.denominator + " Denum");

// other.numerator = this.numerator;

// other.denominator = this.denominator;

if(denominator < 0) {

this.denominator = Math.abs(denominator);

this.numerator = numerator * -1;

}

while(this.numerator % 2 == 0 && this.denominator % 2 == 0) {

System.out.println("tracer" + this.numerator);

this.numerator = this.numerator / 2;

// System.out.println("other" + other.numerator);

this.denominator = this.denominator / 2;

}

while(this.numerator % 3 == 0 && this.denominator % 3 == 0) {

// System.out.println("tracer");

this.numerator = this.numerator / 3;

this.denominator = this.denominator / 3;

}

while(this.numerator % 5 == 0 && this.denominator % 5 == 0) {

// System.out.println("tracer");

this.numerator = this.numerator / 5;

this.denominator = this.denominator / 5;

}

other.numerator = this.numerator;

other.denominator = this.denominator;

return other;

}

public void reciprocal() {

int rdenominator;

int rnumerator;

rdenominator = this.numerator;

rnumerator = this.denominator;

this.numerator = rnumerator;

this.denominator = rdenominator;

}

public Fraction getFraction(int numerator, int denominator) {

Fraction answer = new Fraction();

this.numerator = numerator;

this.denominator = denominator;

answer.numerator = this.numerator;

answer.denominator = this.denominator;

return answer;

}

public int getNumerator(int numerator) {

return this.numerator;

}

public int getDenominator(int denominator) {

return this.denominator;

}

public Fraction multiply(Fraction other) {

Fraction answer = new Fraction();

answer.numerator = this.numerator * other.numerator;

answer.denominator = this.denominator * other.denominator;

numerator = answer.numerator;

denominator = answer.denominator;

simplify(numerator, denominator);

answer.numerator = numerator;

answer.denominator = denominator;

return answer;

}

public Fraction divide(Fraction other) {

Fraction answer = new Fraction();

answer.numerator = this.numerator * other.denominator;

answer.denominator = this.denominator * other.numerator;

numerator = answer.numerator;

denominator = answer.denominator;

simplify(numerator, denominator);

answer.numerator = numerator;

answer.denominator = denominator;

return answer;

}

public Fraction add(Fraction other) {

Fraction answer = new Fraction();

int anothernum;

if(this.denominator != other.denominator) {

answer.denominator = this.denominator * other.denominator;

anothernum = this.numerator * other.denominator; //9

other.numerator = other.numerator * this.denominator; //5

answer.numerator = anothernum + other.numerator;

}

else {

answer.numerator = this.numerator - other.numerator;

answer.denominator = this.denominator;

}

numerator = answer.numerator;

denominator = answer.denominator;

simplify(numerator, denominator);

answer.numerator = numerator;

answer.denominator = denominator;

return answer;

}

public Fraction subtract(Fraction other) {

Fraction answer = new Fraction();

int anothernum;

if(this.denominator != other.denominator) {

answer.denominator = this.denominator * other.denominator;

anothernum = this.numerator * other.denominator;

other.numerator = other.numerator * this.denominator;

answer.numerator = anothernum - other.numerator;

}

numerator = answer.numerator;

denominator = answer.denominator;

simplify(numerator, denominator);

answer.numerator = numerator;

answer.denominator = denominator;

return answer;

}

public boolean equals(Fraction other) {

return (this.numerator == other.numerator &&

this.denominator == other.denominator);

}

public static Fraction[] readFractionArray(Fraction[] array) {

Fraction[] fractionArray = new Fraction[ARRAY_SIZE];

for(int i=0; i<5; i++) {

fractionArray[i] = new Fraction();

}

}

public static void main(String[] args) {

Fraction[] fractionArray = new Fraction[ARRAY_SIZE];

Fraction f1 = new Fraction(2, -5);

Fraction f2 = new Fraction(2, 4);

Fraction f3 = new Fraction(10, 20);

Fraction f4 = new Fraction(1 , 3);

Fraction f5 = new Fraction();

f5 = f2.add(f4);

System.out.println("Added Fraction numerator is: " + f5.numerator);

System.out.println("Added Fraction denominator is: " + f5.denominator);

System.out.println("The numerator is: " + f3.numerator);

System.out.println("The denumerator is: " + f3.denominator);

// System.out.println(f4.numerator + " :simplified numerator ");

// System.out.println(f4.denominator + " :simplified denominator");

// f3.greatestcommonDiviser(10, 20);

// System.out.println(f3.gdc);

// System.out.println(f2.numerator);

f1 = f1.multiply(f2);

System.out.println(f1.numerator);

System.out.println(f1.denominator);

f2.reciprocal();

System.out.println(f2.numerator);

System.out.println(f2.denominator);

}

}