Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create this gui on java that supports rational calculations using this code as the logic, make it look like the picture below using JavaFX and
Create this gui on java that supports rational calculations using this code as the logic, make it look like the picture below using JavaFX and ComboBoxes for the operation options. Will thumbs up
public class Rational extends Object implements Comparable
private final int num;
private final int den;
public final static Rational ZERO new Rational;
public final static Rational ONE new Rational;
public int getNumerator
return num;
public int getDenominator
return den;
public Rational
this;
public Rationalint num
thisnum;
public Rationalint fract
thisfract fract;
public Rationalint numerator, int denominator
if denominator
throw new ArithmeticExceptiondenominator is zero";
int g gcfnumerator denominator;
if denominator
this.num numerator g;
this.den denominator g;
else
this.num numerator g;
this.den denominator g;
public Rational timesRational b
Rational a this;
int num anum bnum;
int den aden bden;
return new Rationalnum den;
public Rational plusRational b
Rational a this;
if aequalsRationalZERO
return b;
if bcompareToRationalZERO
return a;
int num anum bden aden bnum;
int den aden bden;
return new Rationalnum den;
public Rational negate
return new Rationalthis.num, this.den;
public Rational minusRational b
Rational a this;
return aplusbnegate;
public Rational dividesRational b
Rational a this;
return atimesbreciprocal;
public Rational reciprocal
return new Rationalthisden, this.num;
public Rational abs
if thisnum
return this;
else
return this.negate;
public double toDouble
return doublethisnum this.den;
@Override
public boolean equalsObject obj
if this obj
return true;
if obj null
return false;
if thisgetClass obj.getClass
return false;
Rational other Rational obj;
if den other.den
return false;
if num other.num
return false;
return true;
public String toString
if den
return num ;
else
return num den;
public int compareToRational b
Rational a this;
int lhs anum bden;
int rhs aden bnum;
if lhs rhs
return ;
if lhs rhs
return ;
return ;
private static int gcfint m int n
int retval ;
if m
m m;
if n
n n;
if n
retval m;
else
int rem;
while rem m n
m n;
n rem;
retval n;
return retval;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started