Class BigFraction
java.lang.Object
BigFraction
- All Implemented Interfaces:
- Comparable<BigFraction>
This is a a class of immutible extended-precision rational
  numbers.  All BigFractions are fully reduced and any
  negative is in the numerator.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic BigFractionThis is the BigFraction 1/2.static BigFractionThis is the BigFraction 1/1.static BigFractionThis is the BigFraction 0/1.
- 
Constructor SummaryConstructorsConstructorDescriptionThis no-args constructor creates the BigFraction 0/1.BigFraction(BigInteger num) This creates the BigFraction num/1.BigFraction(BigInteger num, BigInteger denom) This is a general-purpose constructor that creates a BigFraction from a specified numerator denominator.
- 
Method SummaryModifier and TypeMethodDescriptionadd(BigFraction that) This computes the sum of two BigFractions.intcompareTo(BigFraction that) This compares this BigFraction to the BigFraction that.divide(BigFraction that) This computes the quotient of two BigFractions.booleanThis returns true when o is a BigFraction numerically equal to this BigFraction.static voidTest code goes in heremultiply(BigFraction that) This computes the product of two BigFractions.pow(int n) This computes thisn.subtract(BigFraction that) This computes the difference of two BigFractions.toString()This gives a string representation of the form num/denom.static BigFractionvalueOf(long num, long denom) This static factory method produces a BigFraction with specified numerator and denominator that are longs.
- 
Field Details- 
ONEThis is the BigFraction 1/1.
- 
ZEROThis is the BigFraction 0/1.
- 
HALFThis is the BigFraction 1/2.
 
- 
- 
Constructor Details- 
BigFractionThis is a general-purpose constructor that creates a BigFraction from a specified numerator denominator.- Parameters:
- num- the numerator of this BigFraction
- denom- the denominator of this BigFraction
- Throws:
- IllegalArgumentException- if a zero denominator is provided.
 
- 
BigFractionThis creates the BigFraction num/1.- Parameters:
- num- the numerator of this BigFraction. The denominator will be 1.
 
- 
BigFractionpublic BigFraction()This no-args constructor creates the BigFraction 0/1.
 
- 
- 
Method Details- 
valueOfThis static factory method produces a BigFraction with specified numerator and denominator that are longs.- Parameters:
- num- the numerator
- denom- the denominator
- Returns:
- the BigFraction num/denom
 
- 
toStringThis gives a string representation of the form num/denom.
- 
equalsThis returns true when o is a BigFraction numerically equal to this BigFraction.
- 
compareToThis compares this BigFraction to the BigFraction that.- Specified by:
- compareToin interface- Comparable<BigFraction>
- Parameters:
- that- the BigFraction we are comparing this BigFraction to.
- Returns:
- a negative integer if this < that and a positive integer if this > that, and zero otherwise.
 
- 
addThis computes the sum of two BigFractions.- Parameters:
- that- the BigFraction we are adding this BigFraction to.
- Returns:
- this + that as a BigFraction.
 
- 
subtractThis computes the difference of two BigFractions.- Parameters:
- that- the BigFraction we are subtraction from this BigFraction.
- Returns:
- this - that as a BigFraction.
 
- 
multiplyThis computes the product of two BigFractions.- Parameters:
- that- the BigFraction we are multiplying by. this BigFraction.
- Returns:
- this*that as a BigFraction.
 
- 
divideThis computes the quotient of two BigFractions.- Parameters:
- that- the BigFraction we are dividing by. this BigFraction.
- Returns:
- this/that as a BigFraction.
 
- 
powThis computes thisn.- Parameters:
- n- the power we are raising this BigFraction to.
- Returns:
- thisn
 
- 
mainTest code goes in here- Parameters:
- args- command-line arguments
 
 
-