I have the following code and I need to convert my string o1 & o2 (input by the user) into the Fraction class f1 & f2. I'm not sure how to do this and any help would be appreciated!
Update: Setters and getters are already in place, I only pasted the relevant aspects of the code in here. Everything works but I don't know how to assign f1 a value (the value of which should be o1).
private int numerator;
private int denominator;
public Fraction(){
numerator = 0;
denominator = 1;
}
public static void main(String[] args){
String o1 = null;
String o2 = null;
Scanner scan = new Scanner(System.in);
System.out.println("Input Operand 1, separate numerator and denominator by '/'.");
o1 = scan.next();
System.out.println("Input Operand 2, separate numerator and denominator by '/'.");
o2 = scan.next();
Fraction f1 = new Fraction();
int n1 = f1.getNumerator();
int d1 = f1.getDenominator();
Fraction f2 = new Fraction();
int n2 = f2.getNumerator();
int d2 = f2.getDenominator();
Fraction A = new Fraction(n1, d1);
Fraction B = new Fraction(n2,d2);
A.printF(add(A,B));
A.printF(sub(A,B));
A.printF(multiply(A,B));
A.printF(divide(A,B));
}