Answered step by step
Verified Expert Solution
Link Copied!

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(0);
public final static Rational ONE = new Rational(1);
public int getNumerator(){
return num;
}
public int getDenominator(){
return den;
}
public Rational(){
this(0,1);
}
public Rational(int num){
this(num,1);
}
public Rational(int[] fract){
this(fract[0], fract[1]);
}
public Rational(int numerator, int denominator){
if (denominator ==0){
throw new ArithmeticException("denominator is zero");
}
int g = gcf(numerator, denominator);
if (denominator >0){
this.num = numerator / g;
this.den = denominator / g;
} else {
this.num =-numerator / g;
this.den =-denominator / g;
}
}
public Rational times(Rational b){
Rational a = this;
int num = a.num * b.num;
int den = a.den * b.den;
return new Rational(num, den);
}
public Rational plus(Rational b){
Rational a = this;
if (a.equals(Rational.ZERO))
return b;
if (b.compareTo(Rational.ZERO)==0)
return a;
int num = a.num * b.den + a.den * b.num;
int den = a.den * b.den;
return new Rational(num, den);
}
public Rational negate(){
return new Rational(-this.num, this.den);
}
public Rational minus(Rational b){
Rational a = this;
return a.plus(b.negate());
}
public Rational divides(Rational b){
Rational a = this;
return a.times(b.reciprocal());
}
public Rational reciprocal(){
return new Rational(this.den, this.num);
}
public Rational abs(){
if (this.num >=0)
return this;
else
return this.negate();
}
public double toDouble(){
return (double)this.num / this.den;
}
@Override
public boolean equals(Object obj){
if (this == obj)
return true;
if (obj == null)
return false;
if (this.getClass()!= 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 ==1)
return num +"";
else
return num +"/"+ den;
}
public int compareTo(Rational b){
Rational a = this;
int lhs = a.num * b.den;
int rhs = a.den * b.num;
if (lhs rhs)
return -1;
if (lhs > rhs)
return 1;
return 0;
}
private static int gcf(int m, int n){
int retval =0;
if (m 0)
m =-m;
if (n 0)
n =-n;
if (n ==0)
retval = m;
else {
int rem;
while ((rem = m % n)!=0){
m = n;
n = rem;
}
retval = n;
}
return retval;
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Eric Redmond ,Jim Wilson

1st Edition

1934356921, 978-1934356920

More Books

Students also viewed these Databases questions

Question

RP-7 What are some ways to reconcile conflicts and promote peace?

Answered: 1 week ago

Question

What is operatiing system?

Answered: 1 week ago

Question

2. List the advantages of listening well

Answered: 1 week ago