SlideShare a Scribd company logo
Interface
package PJ1;
public interface SimpleFractionInterface
{
/** Task: Sets a fraction to a given value.
* @param num is the integer numerator
* @param den is the integer denominator
* @throw ArithmeticException if denominator is 0 */
public void setSimpleFraction(int num, int den);
/** Task: convert a fraction to double value
* @return the double floating point value of a fraction */
public double toDouble();
/** Task: Adds two fractions.
* @param secondFraction is a fraction that is the second operand of the addition
* @return a fraction which is the sum of the invoking fraction and the secondFraction */
public SimpleFractionInterface add(SimpleFractionInterface secondFraction);
/** Task: Subtracts two fractions.
* @param secondFraction a fraction that is the second operand of the subtraction
* @return a fraction which is the difference of the invoking fraction and the second operand */
public SimpleFractionInterface subtract(SimpleFractionInterface secondFraction);
/** Task: Multiplies two fractions.
* @param secondFraction a fraction that is the second operand of the multiplication
* @return a fraction which is the product of the invoking fraction and the secondFraction*/
public SimpleFractionInterface multiply(SimpleFractionInterface secondFraction);
/** Task: Divides two fractions.
* @param secondFraction a fraction that is the second operand of the division
* @return a fraction which the quotient of the invoking fraction and the secondFraction
* @throw FractionException if secondFraction is 0 */
public SimpleFractionInterface divide(SimpleFractionInterface secondFraction);
/** Task: Get's the fraction's reciprocal
* @return the reciprocal of the invoking fraction
* @throw FractionException if the new number with denominator is 0*/
public SimpleFractionInterface getReciprocal();
}
exception class
package PJ1;
public class SimpleFractionException extends RuntimeException
{
public SimpleFractionException()
{
this("");
}
public SimpleFractionException(String errorMsg)
{
super(errorMsg);
}
}
class with main method
package PJ1;
public class SimpleFraction implements SimpleFractionInterface, Comparable
{
// integer numerator and denominator
private int num;
private int den;
public SimpleFraction()
{
setSimpleFraction(0,1);// default numbers
} // end of the default constructor
public SimpleFraction(int num, int den)
{
setSimpleFraction(num, den);//
} // end constructor
public void setSimpleFraction(int num, int den)
{
if (den == 0)
throw new SimpleFractionException("denominator cannot be 0");
else{
this.num= num;
this.den= den;
}
reduceSimpleFractionToLowestTerms();
} // end setSimpleFraction
public double toDouble()
{
// return double floating point value
return (double) num/den;
} // end toDouble
public SimpleFractionInterface add(SimpleFractionInterface secondFraction)
{
SimpleFraction secondFraction2;
secondFraction2 = (SimpleFraction) secondFraction;
// a/b + c/d is (ad + cb)/(bd)
int newNum = num*secondFraction2.getDen() + secondFraction2.getNum()*den;
int newDen = den*secondFraction2.getDen();
// return result which is a new SimpleFraction object
return new SimpleFraction(newNum,newDen);
} // end add
public SimpleFractionInterface subtract(SimpleFractionInterface secondFraction)
{
SimpleFraction secondFraction2;
secondFraction2 = (SimpleFraction) secondFraction;
// a/b - c/d is (ad - cb)/(bd)
int newNum = num*secondFraction2.getDen()-secondFraction2.getNum()*den;
int newDen = den*secondFraction2.getDen();
// return result which is a new SimpleFraction object
return new SimpleFraction(newNum,newDen);
} // end subtract
public SimpleFractionInterface multiply(SimpleFractionInterface secondFraction)
{
SimpleFraction secondFraction2;
secondFraction2 = (SimpleFraction) secondFraction;
// a/b * c/d is (ac)/(bd)
int newNum = num*secondFraction2.getNum();
int newDen = den*secondFraction2.getDen();
// return result which is a new SimpleFraction object
return new SimpleFraction(newNum,newDen);
} // end multiply
public SimpleFractionInterface divide(SimpleFractionInterface secondFraction)
{
SimpleFraction secondFraction2;
secondFraction2 = (SimpleFraction) secondFraction;
// a/b / c/d is (ad)/(bc)
// return SimpleFractionException if secondFraction is 0
if (secondFraction2.getNum() == 0)
throw new SimpleFractionException("The second fraction cannot be 0");
int newNum= num*secondFraction2.getDen();
int newDen= den*secondFraction2.getNum();
// return result which is a new SimpleFraction object
return new SimpleFraction(newNum,newDen);
} // end divide
public SimpleFractionInterface getReciprocal()
{
SimpleFraction r;
// return SimpleFractionException if secondFraction is 0
if(den == 0)
throw new SimpleFractionException("The second fraction cannot be 0");
else
r = new SimpleFraction(den,num);
// return result which is a new SimpleFraction object
return r;
} // end getReciprocal
public boolean equals(Object other)
{
boolean result = false;
if(other instanceof SimpleFraction){
SimpleFraction otherSimple = (SimpleFraction) other;
if(compareTo(otherSimple) == 0)
result = true;
}
return result;
} // end equals
public int compareTo(SimpleFraction other)
{
if(toDouble() == other.toDouble())
return 0;
else if(toDouble() > other.toDouble())
return 1;
else
return -1;
} // end compareTo
public String toString()
{
return num + "/" + den;
} // end toString
/** Task: Reduces a fraction to lowest terms. */
// private methods start here
private int getNum(){
return num;
}
private int getDen(){
return den;
}
private void reduceSimpleFractionToLowestTerms()
{
// Outline:
// compute GCD of num & den
// GCD works for + numbers.
// So, you should eliminate - sign
// then reduce numbers : num/GCD and den/GCD
int sign = 1; //1= positive numbers; -1 = negative numbers
if(num < 0){ //number negative
sign = -1*sign;
num = num*-1;
}
if (den < 0){
sign= -1*sign;
den = den*-1;
}
int gcd= GCD(num,den);
num= (num/gcd)*sign;
den= den/gcd;
} // end reduceSimpleFractionToLowestTerms
/** Task: Computes the greatest common divisor of two integers.
* @param integerOne an integer
* @param integerTwo another integer
* @return the greatest common divisor of the two integers */
private int GCD(int integerOne, int integerTwo)
{
int result;
if (integerOne % integerTwo == 0)
result = integerTwo;
else
result = GCD(integerTwo, integerOne % integerTwo);
return result;
} // end GCD
//-----------------------------------------------------------------
// Simple test is provided here
public static void main(String[] args)
{
SimpleFractionInterface firstOperand = null;
SimpleFractionInterface secondOperand = null;
SimpleFractionInterface result = null;
double doubleResult = 0.0;
SimpleFraction nineSixteenths = new SimpleFraction(9, 16); // 9/16
SimpleFraction oneFourth = new SimpleFraction(1, 4); // 1/4
System.out.println(" ========================================= ");
// 7/8 + 9/16
firstOperand = new SimpleFraction(7, 8);
result = firstOperand.add(nineSixteenths);
System.out.println("The sum of " + firstOperand + " and " +
nineSixteenths + " is tt" + result);
System.out.println("tExpected result :tt23/16 ");
// 9/16 - 7/8
firstOperand = nineSixteenths;
secondOperand = new SimpleFraction(7, 8);
result = firstOperand.subtract(secondOperand);
System.out.println("The difference of " + firstOperand +
" and " + secondOperand + " is t" + result);
System.out.println("tExpected result :tt-5/16 ");
// 15/-2 * 1/4
firstOperand = new SimpleFraction(15, -2);
result = firstOperand.multiply(oneFourth);
System.out.println("The product of " + firstOperand +
" and " + oneFourth + " is t" + result);
System.out.println("tExpected result :tt-15/8 ");
// (-21/2) / (3/7)
firstOperand = new SimpleFraction(-21, 2);
secondOperand= new SimpleFraction(3, 7);
result = firstOperand.divide(secondOperand);
System.out.println("The quotient of " + firstOperand +
" and " + secondOperand + " is t" + result);
System.out.println("tExpected result :tt-49/2 ");
// -21/2 + 7/8
firstOperand = new SimpleFraction(-21, 2);
secondOperand= new SimpleFraction(7, 8);
result = firstOperand.add(secondOperand);
System.out.println("The sum of " + firstOperand +
" and " + secondOperand + " is tt" + result);
System.out.println("tExpected result :tt-77/8 ");
// 0/10, 5/(-15), (-22)/7
firstOperand = new SimpleFraction(0, 10);
doubleResult = firstOperand.toDouble();
System.out.println("The double floating point value of " + firstOperand + " is t" +
doubleResult);
System.out.println("tExpected result ttt0.0 ");
firstOperand = new SimpleFraction(1, -3);
doubleResult = firstOperand.toDouble();
System.out.println("The double floating point value of " + firstOperand + " is t" +
doubleResult);
System.out.println("tExpected result ttt-0.333333333... ");
firstOperand = new SimpleFraction(-22, 7);
doubleResult = firstOperand.toDouble();
System.out.println("The double floating point value of " + firstOperand + " is t" +
doubleResult);
System.out.println("tExpected result ttt-3.142857142857143");
System.out.println(" ========================================= ");
firstOperand = new SimpleFraction(-21, 2);
System.out.println("First = " + firstOperand);
// equality check
System.out.println("check First equals First: ");
if (firstOperand.equals(firstOperand))
System.out.println("Identity of fractions OK");
else
System.out.println("ERROR in identity of fractions");
secondOperand = new SimpleFraction(-42, 4);
System.out.println(" Second = " + secondOperand);
System.out.println("check First equals Second: ");
if (firstOperand.equals(secondOperand))
System.out.println("Equality of fractions OK");
else
System.out.println("ERROR in equality of fractions");
// comparison check
SimpleFraction first = (SimpleFraction)firstOperand;
SimpleFraction second = (SimpleFraction)secondOperand;
System.out.println(" check First compareTo Second: ");
if (first.compareTo(second) == 0)
System.out.println("SimpleFractions == operator OK");
else
System.out.println("ERROR in fractions == operator");
second = new SimpleFraction(7, 8);
System.out.println(" Second = " + second);
System.out.println("check First compareTo Second: ");
if (first.compareTo(second) < 0)
System.out.println("SimpleFractions < operator OK");
else
System.out.println("ERROR in fractions < operator");
System.out.println(" check Second compareTo First: ");
if (second.compareTo(first) > 0)
System.out.println("SimpleFractions > operator OK");
else
System.out.println("ERROR in fractions > operator");
System.out.println(" =========================================");
System.out.println(" check SimpleFractionException: 1/0");
try {
SimpleFraction a1 = new SimpleFraction(1, 0);
System.out.println("Error! No SimpleFractionException");
}
catch ( SimpleFractionException fe )
{
System.err.printf( "Exception: %s ", fe );
} // end catch
System.out.println("Expected result : SimpleFractionException! ");
System.out.println(" check SimpleFractionException: division");
try {
SimpleFraction a2 = new SimpleFraction();
SimpleFraction a3 = new SimpleFraction(1, 2);
a3.divide(a2);
System.out.println("Error! No SimpleFractionException");
}
catch ( SimpleFractionException fe )
{
System.err.printf( "Exception: %s ", fe );
} // end catch
System.out.println("Expected result : SimpleFractionException! ");
} // end main
} // end SimpleFraction
output:
run:
=========================================
The sum of 7/8 and 9/16 is 23/16
Expected result : 23/16
The difference of 9/16 and 7/8 is -5/16
Expected result : -5/16
The product of -15/2 and 1/4 is -15/8
Expected result : -15/8
The quotient of -21/2 and 3/7 is -49/2
Expected result : -49/2
The sum of -21/2 and 7/8 is -77/8
Expected result : -77/8
The double floating point value of 0/1 is 0.0
Expected result 0.0
The double floating point value of -1/3 is -0.3333333333333333
Expected result -0.333333333...
The double floating point value of -22/7 is -3.142857142857143
Expected result -3.142857142857143
=========================================
First = -21/2
check First equals First:
Identity of fractions OK
Second = -21/2
check First equals Second:
Equality of fractions OK
check First compareTo Second:
SimpleFractions == operator OK
Second = 7/8
check First compareTo Second:
SimpleFractions < operator OK
check Second compareTo First:
SimpleFractions > operator OK
=========================================
check SimpleFractionException: 1/0
Exception: PJ1.SimpleFractionException: denominator cannot be 0
Expected result : SimpleFractionException!
check SimpleFractionException: division
Exception: PJ1.SimpleFractionException: The second fraction cannot be 0
Expected result : SimpleFractionException!
BUILD SUCCESSFUL (total time: 3 seconds)
Solution
Interface
package PJ1;
public interface SimpleFractionInterface
{
/** Task: Sets a fraction to a given value.
* @param num is the integer numerator
* @param den is the integer denominator
* @throw ArithmeticException if denominator is 0 */
public void setSimpleFraction(int num, int den);
/** Task: convert a fraction to double value
* @return the double floating point value of a fraction */
public double toDouble();
/** Task: Adds two fractions.
* @param secondFraction is a fraction that is the second operand of the addition
* @return a fraction which is the sum of the invoking fraction and the secondFraction */
public SimpleFractionInterface add(SimpleFractionInterface secondFraction);
/** Task: Subtracts two fractions.
* @param secondFraction a fraction that is the second operand of the subtraction
* @return a fraction which is the difference of the invoking fraction and the second operand */
public SimpleFractionInterface subtract(SimpleFractionInterface secondFraction);
/** Task: Multiplies two fractions.
* @param secondFraction a fraction that is the second operand of the multiplication
* @return a fraction which is the product of the invoking fraction and the secondFraction*/
public SimpleFractionInterface multiply(SimpleFractionInterface secondFraction);
/** Task: Divides two fractions.
* @param secondFraction a fraction that is the second operand of the division
* @return a fraction which the quotient of the invoking fraction and the secondFraction
* @throw FractionException if secondFraction is 0 */
public SimpleFractionInterface divide(SimpleFractionInterface secondFraction);
/** Task: Get's the fraction's reciprocal
* @return the reciprocal of the invoking fraction
* @throw FractionException if the new number with denominator is 0*/
public SimpleFractionInterface getReciprocal();
}
exception class
package PJ1;
public class SimpleFractionException extends RuntimeException
{
public SimpleFractionException()
{
this("");
}
public SimpleFractionException(String errorMsg)
{
super(errorMsg);
}
}
class with main method
package PJ1;
public class SimpleFraction implements SimpleFractionInterface, Comparable
{
// integer numerator and denominator
private int num;
private int den;
public SimpleFraction()
{
setSimpleFraction(0,1);// default numbers
} // end of the default constructor
public SimpleFraction(int num, int den)
{
setSimpleFraction(num, den);//
} // end constructor
public void setSimpleFraction(int num, int den)
{
if (den == 0)
throw new SimpleFractionException("denominator cannot be 0");
else{
this.num= num;
this.den= den;
}
reduceSimpleFractionToLowestTerms();
} // end setSimpleFraction
public double toDouble()
{
// return double floating point value
return (double) num/den;
} // end toDouble
public SimpleFractionInterface add(SimpleFractionInterface secondFraction)
{
SimpleFraction secondFraction2;
secondFraction2 = (SimpleFraction) secondFraction;
// a/b + c/d is (ad + cb)/(bd)
int newNum = num*secondFraction2.getDen() + secondFraction2.getNum()*den;
int newDen = den*secondFraction2.getDen();
// return result which is a new SimpleFraction object
return new SimpleFraction(newNum,newDen);
} // end add
public SimpleFractionInterface subtract(SimpleFractionInterface secondFraction)
{
SimpleFraction secondFraction2;
secondFraction2 = (SimpleFraction) secondFraction;
// a/b - c/d is (ad - cb)/(bd)
int newNum = num*secondFraction2.getDen()-secondFraction2.getNum()*den;
int newDen = den*secondFraction2.getDen();
// return result which is a new SimpleFraction object
return new SimpleFraction(newNum,newDen);
} // end subtract
public SimpleFractionInterface multiply(SimpleFractionInterface secondFraction)
{
SimpleFraction secondFraction2;
secondFraction2 = (SimpleFraction) secondFraction;
// a/b * c/d is (ac)/(bd)
int newNum = num*secondFraction2.getNum();
int newDen = den*secondFraction2.getDen();
// return result which is a new SimpleFraction object
return new SimpleFraction(newNum,newDen);
} // end multiply
public SimpleFractionInterface divide(SimpleFractionInterface secondFraction)
{
SimpleFraction secondFraction2;
secondFraction2 = (SimpleFraction) secondFraction;
// a/b / c/d is (ad)/(bc)
// return SimpleFractionException if secondFraction is 0
if (secondFraction2.getNum() == 0)
throw new SimpleFractionException("The second fraction cannot be 0");
int newNum= num*secondFraction2.getDen();
int newDen= den*secondFraction2.getNum();
// return result which is a new SimpleFraction object
return new SimpleFraction(newNum,newDen);
} // end divide
public SimpleFractionInterface getReciprocal()
{
SimpleFraction r;
// return SimpleFractionException if secondFraction is 0
if(den == 0)
throw new SimpleFractionException("The second fraction cannot be 0");
else
r = new SimpleFraction(den,num);
// return result which is a new SimpleFraction object
return r;
} // end getReciprocal
public boolean equals(Object other)
{
boolean result = false;
if(other instanceof SimpleFraction){
SimpleFraction otherSimple = (SimpleFraction) other;
if(compareTo(otherSimple) == 0)
result = true;
}
return result;
} // end equals
public int compareTo(SimpleFraction other)
{
if(toDouble() == other.toDouble())
return 0;
else if(toDouble() > other.toDouble())
return 1;
else
return -1;
} // end compareTo
public String toString()
{
return num + "/" + den;
} // end toString
/** Task: Reduces a fraction to lowest terms. */
// private methods start here
private int getNum(){
return num;
}
private int getDen(){
return den;
}
private void reduceSimpleFractionToLowestTerms()
{
// Outline:
// compute GCD of num & den
// GCD works for + numbers.
// So, you should eliminate - sign
// then reduce numbers : num/GCD and den/GCD
int sign = 1; //1= positive numbers; -1 = negative numbers
if(num < 0){ //number negative
sign = -1*sign;
num = num*-1;
}
if (den < 0){
sign= -1*sign;
den = den*-1;
}
int gcd= GCD(num,den);
num= (num/gcd)*sign;
den= den/gcd;
} // end reduceSimpleFractionToLowestTerms
/** Task: Computes the greatest common divisor of two integers.
* @param integerOne an integer
* @param integerTwo another integer
* @return the greatest common divisor of the two integers */
private int GCD(int integerOne, int integerTwo)
{
int result;
if (integerOne % integerTwo == 0)
result = integerTwo;
else
result = GCD(integerTwo, integerOne % integerTwo);
return result;
} // end GCD
//-----------------------------------------------------------------
// Simple test is provided here
public static void main(String[] args)
{
SimpleFractionInterface firstOperand = null;
SimpleFractionInterface secondOperand = null;
SimpleFractionInterface result = null;
double doubleResult = 0.0;
SimpleFraction nineSixteenths = new SimpleFraction(9, 16); // 9/16
SimpleFraction oneFourth = new SimpleFraction(1, 4); // 1/4
System.out.println(" ========================================= ");
// 7/8 + 9/16
firstOperand = new SimpleFraction(7, 8);
result = firstOperand.add(nineSixteenths);
System.out.println("The sum of " + firstOperand + " and " +
nineSixteenths + " is tt" + result);
System.out.println("tExpected result :tt23/16 ");
// 9/16 - 7/8
firstOperand = nineSixteenths;
secondOperand = new SimpleFraction(7, 8);
result = firstOperand.subtract(secondOperand);
System.out.println("The difference of " + firstOperand +
" and " + secondOperand + " is t" + result);
System.out.println("tExpected result :tt-5/16 ");
// 15/-2 * 1/4
firstOperand = new SimpleFraction(15, -2);
result = firstOperand.multiply(oneFourth);
System.out.println("The product of " + firstOperand +
" and " + oneFourth + " is t" + result);
System.out.println("tExpected result :tt-15/8 ");
// (-21/2) / (3/7)
firstOperand = new SimpleFraction(-21, 2);
secondOperand= new SimpleFraction(3, 7);
result = firstOperand.divide(secondOperand);
System.out.println("The quotient of " + firstOperand +
" and " + secondOperand + " is t" + result);
System.out.println("tExpected result :tt-49/2 ");
// -21/2 + 7/8
firstOperand = new SimpleFraction(-21, 2);
secondOperand= new SimpleFraction(7, 8);
result = firstOperand.add(secondOperand);
System.out.println("The sum of " + firstOperand +
" and " + secondOperand + " is tt" + result);
System.out.println("tExpected result :tt-77/8 ");
// 0/10, 5/(-15), (-22)/7
firstOperand = new SimpleFraction(0, 10);
doubleResult = firstOperand.toDouble();
System.out.println("The double floating point value of " + firstOperand + " is t" +
doubleResult);
System.out.println("tExpected result ttt0.0 ");
firstOperand = new SimpleFraction(1, -3);
doubleResult = firstOperand.toDouble();
System.out.println("The double floating point value of " + firstOperand + " is t" +
doubleResult);
System.out.println("tExpected result ttt-0.333333333... ");
firstOperand = new SimpleFraction(-22, 7);
doubleResult = firstOperand.toDouble();
System.out.println("The double floating point value of " + firstOperand + " is t" +
doubleResult);
System.out.println("tExpected result ttt-3.142857142857143");
System.out.println(" ========================================= ");
firstOperand = new SimpleFraction(-21, 2);
System.out.println("First = " + firstOperand);
// equality check
System.out.println("check First equals First: ");
if (firstOperand.equals(firstOperand))
System.out.println("Identity of fractions OK");
else
System.out.println("ERROR in identity of fractions");
secondOperand = new SimpleFraction(-42, 4);
System.out.println(" Second = " + secondOperand);
System.out.println("check First equals Second: ");
if (firstOperand.equals(secondOperand))
System.out.println("Equality of fractions OK");
else
System.out.println("ERROR in equality of fractions");
// comparison check
SimpleFraction first = (SimpleFraction)firstOperand;
SimpleFraction second = (SimpleFraction)secondOperand;
System.out.println(" check First compareTo Second: ");
if (first.compareTo(second) == 0)
System.out.println("SimpleFractions == operator OK");
else
System.out.println("ERROR in fractions == operator");
second = new SimpleFraction(7, 8);
System.out.println(" Second = " + second);
System.out.println("check First compareTo Second: ");
if (first.compareTo(second) < 0)
System.out.println("SimpleFractions < operator OK");
else
System.out.println("ERROR in fractions < operator");
System.out.println(" check Second compareTo First: ");
if (second.compareTo(first) > 0)
System.out.println("SimpleFractions > operator OK");
else
System.out.println("ERROR in fractions > operator");
System.out.println(" =========================================");
System.out.println(" check SimpleFractionException: 1/0");
try {
SimpleFraction a1 = new SimpleFraction(1, 0);
System.out.println("Error! No SimpleFractionException");
}
catch ( SimpleFractionException fe )
{
System.err.printf( "Exception: %s ", fe );
} // end catch
System.out.println("Expected result : SimpleFractionException! ");
System.out.println(" check SimpleFractionException: division");
try {
SimpleFraction a2 = new SimpleFraction();
SimpleFraction a3 = new SimpleFraction(1, 2);
a3.divide(a2);
System.out.println("Error! No SimpleFractionException");
}
catch ( SimpleFractionException fe )
{
System.err.printf( "Exception: %s ", fe );
} // end catch
System.out.println("Expected result : SimpleFractionException! ");
} // end main
} // end SimpleFraction
output:
run:
=========================================
The sum of 7/8 and 9/16 is 23/16
Expected result : 23/16
The difference of 9/16 and 7/8 is -5/16
Expected result : -5/16
The product of -15/2 and 1/4 is -15/8
Expected result : -15/8
The quotient of -21/2 and 3/7 is -49/2
Expected result : -49/2
The sum of -21/2 and 7/8 is -77/8
Expected result : -77/8
The double floating point value of 0/1 is 0.0
Expected result 0.0
The double floating point value of -1/3 is -0.3333333333333333
Expected result -0.333333333...
The double floating point value of -22/7 is -3.142857142857143
Expected result -3.142857142857143
=========================================
First = -21/2
check First equals First:
Identity of fractions OK
Second = -21/2
check First equals Second:
Equality of fractions OK
check First compareTo Second:
SimpleFractions == operator OK
Second = 7/8
check First compareTo Second:
SimpleFractions < operator OK
check Second compareTo First:
SimpleFractions > operator OK
=========================================
check SimpleFractionException: 1/0
Exception: PJ1.SimpleFractionException: denominator cannot be 0
Expected result : SimpleFractionException!
check SimpleFractionException: division
Exception: PJ1.SimpleFractionException: The second fraction cannot be 0
Expected result : SimpleFractionException!
BUILD SUCCESSFUL (total time: 3 seconds)

More Related Content

Similar to Interfacepackage PJ1; public interface SimpleFractionInterface.pdf

public class Point {   Insert your name here    private dou.pdf
public class Point {    Insert your name here    private dou.pdfpublic class Point {    Insert your name here    private dou.pdf
public class Point {   Insert your name here    private dou.pdf
anandshingavi23
 
Fraction.h #include iostream #ifndef FRACTION #define FR.pdf
Fraction.h #include iostream #ifndef FRACTION #define FR.pdfFraction.h #include iostream #ifndef FRACTION #define FR.pdf
Fraction.h #include iostream #ifndef FRACTION #define FR.pdf
ravikapoorindia
 
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
aquazac
 
fraction_math.c for Project 5 Program Design fraction.pdf
fraction_math.c for Project 5  Program Design  fraction.pdffraction_math.c for Project 5  Program Design  fraction.pdf
fraction_math.c for Project 5 Program Design fraction.pdf
anjanadistribution
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
shanki7
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdf
jyothimuppasani1
 
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfPlease do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
aioils
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
fathimafancyjeweller
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Mario Fusco
 
Stack prgs
Stack prgsStack prgs
Stack prgs
Ssankett Negi
 
can someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdfcan someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdf
vinaythemodel
 
C++ AssignmentPlease read all the requirements and the overloading.pdf
C++ AssignmentPlease read all the requirements and the overloading.pdfC++ AssignmentPlease read all the requirements and the overloading.pdf
C++ AssignmentPlease read all the requirements and the overloading.pdf
lakshmijewellery
 
Here is the code with comments to solve the question. Please do rate.pdf
Here is the code with comments to solve the question. Please do rate.pdfHere is the code with comments to solve the question. Please do rate.pdf
Here is the code with comments to solve the question. Please do rate.pdf
angelfragranc
 
C# Program. Create a Windows application that has the functionality .pdf
C# Program. Create a Windows application that has the functionality .pdfC# Program. Create a Windows application that has the functionality .pdf
C# Program. Create a Windows application that has the functionality .pdf
fathimalinks
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
amrit47
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
Lin Yo-An
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
climatecontrolsv
 
CSC-1106 Homework 09 (Class and static methods) Due Tuesday, Novembe.pdf
CSC-1106 Homework 09 (Class and static methods) Due Tuesday, Novembe.pdfCSC-1106 Homework 09 (Class and static methods) Due Tuesday, Novembe.pdf
CSC-1106 Homework 09 (Class and static methods) Due Tuesday, Novembe.pdf
marketing413921
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
Farhan Ab Rahman
 

Similar to Interfacepackage PJ1; public interface SimpleFractionInterface.pdf (20)

public class Point {   Insert your name here    private dou.pdf
public class Point {    Insert your name here    private dou.pdfpublic class Point {    Insert your name here    private dou.pdf
public class Point {   Insert your name here    private dou.pdf
 
Fraction.h #include iostream #ifndef FRACTION #define FR.pdf
Fraction.h #include iostream #ifndef FRACTION #define FR.pdfFraction.h #include iostream #ifndef FRACTION #define FR.pdf
Fraction.h #include iostream #ifndef FRACTION #define FR.pdf
 
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
 
fraction_math.c for Project 5 Program Design fraction.pdf
fraction_math.c for Project 5  Program Design  fraction.pdffraction_math.c for Project 5  Program Design  fraction.pdf
fraction_math.c for Project 5 Program Design fraction.pdf
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
 
write the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdfwrite the To Dos to get the exact outputNOte A valid Fraction .pdf
write the To Dos to get the exact outputNOte A valid Fraction .pdf
 
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfPlease do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
 
mainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdfmainpublic class AssignmentThree {    public static void ma.pdf
mainpublic class AssignmentThree {    public static void ma.pdf
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
Stack prgs
Stack prgsStack prgs
Stack prgs
 
can someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdfcan someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdf
 
C++ aptitude
C++ aptitudeC++ aptitude
C++ aptitude
 
C++ AssignmentPlease read all the requirements and the overloading.pdf
C++ AssignmentPlease read all the requirements and the overloading.pdfC++ AssignmentPlease read all the requirements and the overloading.pdf
C++ AssignmentPlease read all the requirements and the overloading.pdf
 
Here is the code with comments to solve the question. Please do rate.pdf
Here is the code with comments to solve the question. Please do rate.pdfHere is the code with comments to solve the question. Please do rate.pdf
Here is the code with comments to solve the question. Please do rate.pdf
 
C# Program. Create a Windows application that has the functionality .pdf
C# Program. Create a Windows application that has the functionality .pdfC# Program. Create a Windows application that has the functionality .pdf
C# Program. Create a Windows application that has the functionality .pdf
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
 
CSC-1106 Homework 09 (Class and static methods) Due Tuesday, Novembe.pdf
CSC-1106 Homework 09 (Class and static methods) Due Tuesday, Novembe.pdfCSC-1106 Homework 09 (Class and static methods) Due Tuesday, Novembe.pdf
CSC-1106 Homework 09 (Class and static methods) Due Tuesday, Novembe.pdf
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 

More from sutharbharat59

1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf
sutharbharat59
 
1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf
1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf
1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf
sutharbharat59
 
In chemistry, hybridisation (or hybridization) is.pdf
                     In chemistry, hybridisation (or hybridization) is.pdf                     In chemistry, hybridisation (or hybridization) is.pdf
In chemistry, hybridisation (or hybridization) is.pdf
sutharbharat59
 
RPS 19 stands for ribosomal protein S19. This proteins is synthesise.pdf
RPS 19 stands for ribosomal protein S19. This proteins is synthesise.pdfRPS 19 stands for ribosomal protein S19. This proteins is synthesise.pdf
RPS 19 stands for ribosomal protein S19. This proteins is synthesise.pdf
sutharbharat59
 
y^(iv)-4y=0taking 4y to RHS we gety^(iv) = 4yy^(iii) = integra.pdf
y^(iv)-4y=0taking 4y to RHS we gety^(iv) = 4yy^(iii) = integra.pdfy^(iv)-4y=0taking 4y to RHS we gety^(iv) = 4yy^(iii) = integra.pdf
y^(iv)-4y=0taking 4y to RHS we gety^(iv) = 4yy^(iii) = integra.pdf
sutharbharat59
 
 Fe(s) + Mn2+(aq) Fe2+(aq) + Mn(s)Yes this reaction is spon.pdf
 Fe(s) + Mn2+(aq)  Fe2+(aq) + Mn(s)Yes this reaction is spon.pdf Fe(s) + Mn2+(aq)  Fe2+(aq) + Mn(s)Yes this reaction is spon.pdf
 Fe(s) + Mn2+(aq) Fe2+(aq) + Mn(s)Yes this reaction is spon.pdf
sutharbharat59
 
When Na2SO3 is dissolved in water, Na+ and SO32- ions are formedN.pdf
When Na2SO3 is dissolved in water, Na+ and SO32- ions are formedN.pdfWhen Na2SO3 is dissolved in water, Na+ and SO32- ions are formedN.pdf
When Na2SO3 is dissolved in water, Na+ and SO32- ions are formedN.pdf
sutharbharat59
 
To convert html code into Java servlet you have to write all html ta.pdf
To convert html code into Java servlet you have to write all html ta.pdfTo convert html code into Java servlet you have to write all html ta.pdf
To convert html code into Java servlet you have to write all html ta.pdf
sutharbharat59
 
Therapsids is a group of synapsidsAdaptation1.Four limbs extent.pdf
Therapsids is a group of synapsidsAdaptation1.Four limbs extent.pdfTherapsids is a group of synapsidsAdaptation1.Four limbs extent.pdf
Therapsids is a group of synapsidsAdaptation1.Four limbs extent.pdf
sutharbharat59
 
They trade away higher fecundity for future reproduction.Being ite.pdf
They trade away higher fecundity for future reproduction.Being ite.pdfThey trade away higher fecundity for future reproduction.Being ite.pdf
They trade away higher fecundity for future reproduction.Being ite.pdf
sutharbharat59
 
The statements that are consistent with facts known about membrane a.pdf
The statements that are consistent with facts known about membrane a.pdfThe statements that are consistent with facts known about membrane a.pdf
The statements that are consistent with facts known about membrane a.pdf
sutharbharat59
 
The implementation algorithm whose amortized complexity is O (1) to .pdf
The implementation algorithm whose amortized complexity is O (1) to .pdfThe implementation algorithm whose amortized complexity is O (1) to .pdf
The implementation algorithm whose amortized complexity is O (1) to .pdf
sutharbharat59
 
The correct matches are as discussed below(a) A (Glycoprotiens ar.pdf
The correct matches are as discussed below(a) A (Glycoprotiens ar.pdfThe correct matches are as discussed below(a) A (Glycoprotiens ar.pdf
The correct matches are as discussed below(a) A (Glycoprotiens ar.pdf
sutharbharat59
 
Step1 Moles of He = 504.0026Step2 Moles of Xe = 50131.29Step3 .pdf
Step1 Moles of He = 504.0026Step2 Moles of Xe = 50131.29Step3 .pdfStep1 Moles of He = 504.0026Step2 Moles of Xe = 50131.29Step3 .pdf
Step1 Moles of He = 504.0026Step2 Moles of Xe = 50131.29Step3 .pdf
sutharbharat59
 
SKIN SENSORY ORGANThe human skin is the external covering of the .pdf
SKIN SENSORY ORGANThe human skin is the external covering of the .pdfSKIN SENSORY ORGANThe human skin is the external covering of the .pdf
SKIN SENSORY ORGANThe human skin is the external covering of the .pdf
sutharbharat59
 
a) FlaseIn terms of trasing volume it is by far the largest market.pdf
a) FlaseIn terms of trasing volume it is by far the largest market.pdfa) FlaseIn terms of trasing volume it is by far the largest market.pdf
a) FlaseIn terms of trasing volume it is by far the largest market.pdf
sutharbharat59
 
tested on EclipseRainfall.javaimpo.pdf
tested on EclipseRainfall.javaimpo.pdftested on EclipseRainfall.javaimpo.pdf
tested on EclipseRainfall.javaimpo.pdf
sutharbharat59
 
Ques-1Part-a Mitosis it is a somatic cell division in an organi.pdf
Ques-1Part-a Mitosis it is a somatic cell division in an organi.pdfQues-1Part-a Mitosis it is a somatic cell division in an organi.pdf
Ques-1Part-a Mitosis it is a somatic cell division in an organi.pdf
sutharbharat59
 
Proportional tax is a tax where the rate of tax is fixed. It is a pr.pdf
Proportional tax is a tax where the rate of tax is fixed. It is a pr.pdfProportional tax is a tax where the rate of tax is fixed. It is a pr.pdf
Proportional tax is a tax where the rate of tax is fixed. It is a pr.pdf
sutharbharat59
 
POS system is a networked invironment where a main computer linked t.pdf
POS system is a networked invironment where a main computer linked t.pdfPOS system is a networked invironment where a main computer linked t.pdf
POS system is a networked invironment where a main computer linked t.pdf
sutharbharat59
 

More from sutharbharat59 (20)

1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf1. Translation program#includestdio.h#includeconio.h#incl.pdf
1. Translation program#includestdio.h#includeconio.h#incl.pdf
 
1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf
1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf
1A. The acronym DBLC is used to name the Database Life Cycle.The DBL.pdf
 
In chemistry, hybridisation (or hybridization) is.pdf
                     In chemistry, hybridisation (or hybridization) is.pdf                     In chemistry, hybridisation (or hybridization) is.pdf
In chemistry, hybridisation (or hybridization) is.pdf
 
RPS 19 stands for ribosomal protein S19. This proteins is synthesise.pdf
RPS 19 stands for ribosomal protein S19. This proteins is synthesise.pdfRPS 19 stands for ribosomal protein S19. This proteins is synthesise.pdf
RPS 19 stands for ribosomal protein S19. This proteins is synthesise.pdf
 
y^(iv)-4y=0taking 4y to RHS we gety^(iv) = 4yy^(iii) = integra.pdf
y^(iv)-4y=0taking 4y to RHS we gety^(iv) = 4yy^(iii) = integra.pdfy^(iv)-4y=0taking 4y to RHS we gety^(iv) = 4yy^(iii) = integra.pdf
y^(iv)-4y=0taking 4y to RHS we gety^(iv) = 4yy^(iii) = integra.pdf
 
 Fe(s) + Mn2+(aq) Fe2+(aq) + Mn(s)Yes this reaction is spon.pdf
 Fe(s) + Mn2+(aq)  Fe2+(aq) + Mn(s)Yes this reaction is spon.pdf Fe(s) + Mn2+(aq)  Fe2+(aq) + Mn(s)Yes this reaction is spon.pdf
 Fe(s) + Mn2+(aq) Fe2+(aq) + Mn(s)Yes this reaction is spon.pdf
 
When Na2SO3 is dissolved in water, Na+ and SO32- ions are formedN.pdf
When Na2SO3 is dissolved in water, Na+ and SO32- ions are formedN.pdfWhen Na2SO3 is dissolved in water, Na+ and SO32- ions are formedN.pdf
When Na2SO3 is dissolved in water, Na+ and SO32- ions are formedN.pdf
 
To convert html code into Java servlet you have to write all html ta.pdf
To convert html code into Java servlet you have to write all html ta.pdfTo convert html code into Java servlet you have to write all html ta.pdf
To convert html code into Java servlet you have to write all html ta.pdf
 
Therapsids is a group of synapsidsAdaptation1.Four limbs extent.pdf
Therapsids is a group of synapsidsAdaptation1.Four limbs extent.pdfTherapsids is a group of synapsidsAdaptation1.Four limbs extent.pdf
Therapsids is a group of synapsidsAdaptation1.Four limbs extent.pdf
 
They trade away higher fecundity for future reproduction.Being ite.pdf
They trade away higher fecundity for future reproduction.Being ite.pdfThey trade away higher fecundity for future reproduction.Being ite.pdf
They trade away higher fecundity for future reproduction.Being ite.pdf
 
The statements that are consistent with facts known about membrane a.pdf
The statements that are consistent with facts known about membrane a.pdfThe statements that are consistent with facts known about membrane a.pdf
The statements that are consistent with facts known about membrane a.pdf
 
The implementation algorithm whose amortized complexity is O (1) to .pdf
The implementation algorithm whose amortized complexity is O (1) to .pdfThe implementation algorithm whose amortized complexity is O (1) to .pdf
The implementation algorithm whose amortized complexity is O (1) to .pdf
 
The correct matches are as discussed below(a) A (Glycoprotiens ar.pdf
The correct matches are as discussed below(a) A (Glycoprotiens ar.pdfThe correct matches are as discussed below(a) A (Glycoprotiens ar.pdf
The correct matches are as discussed below(a) A (Glycoprotiens ar.pdf
 
Step1 Moles of He = 504.0026Step2 Moles of Xe = 50131.29Step3 .pdf
Step1 Moles of He = 504.0026Step2 Moles of Xe = 50131.29Step3 .pdfStep1 Moles of He = 504.0026Step2 Moles of Xe = 50131.29Step3 .pdf
Step1 Moles of He = 504.0026Step2 Moles of Xe = 50131.29Step3 .pdf
 
SKIN SENSORY ORGANThe human skin is the external covering of the .pdf
SKIN SENSORY ORGANThe human skin is the external covering of the .pdfSKIN SENSORY ORGANThe human skin is the external covering of the .pdf
SKIN SENSORY ORGANThe human skin is the external covering of the .pdf
 
a) FlaseIn terms of trasing volume it is by far the largest market.pdf
a) FlaseIn terms of trasing volume it is by far the largest market.pdfa) FlaseIn terms of trasing volume it is by far the largest market.pdf
a) FlaseIn terms of trasing volume it is by far the largest market.pdf
 
tested on EclipseRainfall.javaimpo.pdf
tested on EclipseRainfall.javaimpo.pdftested on EclipseRainfall.javaimpo.pdf
tested on EclipseRainfall.javaimpo.pdf
 
Ques-1Part-a Mitosis it is a somatic cell division in an organi.pdf
Ques-1Part-a Mitosis it is a somatic cell division in an organi.pdfQues-1Part-a Mitosis it is a somatic cell division in an organi.pdf
Ques-1Part-a Mitosis it is a somatic cell division in an organi.pdf
 
Proportional tax is a tax where the rate of tax is fixed. It is a pr.pdf
Proportional tax is a tax where the rate of tax is fixed. It is a pr.pdfProportional tax is a tax where the rate of tax is fixed. It is a pr.pdf
Proportional tax is a tax where the rate of tax is fixed. It is a pr.pdf
 
POS system is a networked invironment where a main computer linked t.pdf
POS system is a networked invironment where a main computer linked t.pdfPOS system is a networked invironment where a main computer linked t.pdf
POS system is a networked invironment where a main computer linked t.pdf
 

Recently uploaded

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 

Recently uploaded (20)

Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 

Interfacepackage PJ1; public interface SimpleFractionInterface.pdf

  • 1. Interface package PJ1; public interface SimpleFractionInterface { /** Task: Sets a fraction to a given value. * @param num is the integer numerator * @param den is the integer denominator * @throw ArithmeticException if denominator is 0 */ public void setSimpleFraction(int num, int den); /** Task: convert a fraction to double value * @return the double floating point value of a fraction */ public double toDouble(); /** Task: Adds two fractions. * @param secondFraction is a fraction that is the second operand of the addition * @return a fraction which is the sum of the invoking fraction and the secondFraction */ public SimpleFractionInterface add(SimpleFractionInterface secondFraction); /** Task: Subtracts two fractions. * @param secondFraction a fraction that is the second operand of the subtraction * @return a fraction which is the difference of the invoking fraction and the second operand */ public SimpleFractionInterface subtract(SimpleFractionInterface secondFraction); /** Task: Multiplies two fractions. * @param secondFraction a fraction that is the second operand of the multiplication * @return a fraction which is the product of the invoking fraction and the secondFraction*/ public SimpleFractionInterface multiply(SimpleFractionInterface secondFraction); /** Task: Divides two fractions. * @param secondFraction a fraction that is the second operand of the division * @return a fraction which the quotient of the invoking fraction and the secondFraction * @throw FractionException if secondFraction is 0 */ public SimpleFractionInterface divide(SimpleFractionInterface secondFraction); /** Task: Get's the fraction's reciprocal * @return the reciprocal of the invoking fraction * @throw FractionException if the new number with denominator is 0*/ public SimpleFractionInterface getReciprocal(); } exception class
  • 2. package PJ1; public class SimpleFractionException extends RuntimeException { public SimpleFractionException() { this(""); } public SimpleFractionException(String errorMsg) { super(errorMsg); } } class with main method package PJ1; public class SimpleFraction implements SimpleFractionInterface, Comparable { // integer numerator and denominator private int num; private int den; public SimpleFraction() { setSimpleFraction(0,1);// default numbers } // end of the default constructor public SimpleFraction(int num, int den) { setSimpleFraction(num, den);// } // end constructor public void setSimpleFraction(int num, int den) { if (den == 0) throw new SimpleFractionException("denominator cannot be 0"); else{ this.num= num;
  • 3. this.den= den; } reduceSimpleFractionToLowestTerms(); } // end setSimpleFraction public double toDouble() { // return double floating point value return (double) num/den; } // end toDouble public SimpleFractionInterface add(SimpleFractionInterface secondFraction) { SimpleFraction secondFraction2; secondFraction2 = (SimpleFraction) secondFraction; // a/b + c/d is (ad + cb)/(bd) int newNum = num*secondFraction2.getDen() + secondFraction2.getNum()*den; int newDen = den*secondFraction2.getDen(); // return result which is a new SimpleFraction object return new SimpleFraction(newNum,newDen); } // end add public SimpleFractionInterface subtract(SimpleFractionInterface secondFraction) { SimpleFraction secondFraction2; secondFraction2 = (SimpleFraction) secondFraction; // a/b - c/d is (ad - cb)/(bd) int newNum = num*secondFraction2.getDen()-secondFraction2.getNum()*den; int newDen = den*secondFraction2.getDen(); // return result which is a new SimpleFraction object return new SimpleFraction(newNum,newDen); } // end subtract public SimpleFractionInterface multiply(SimpleFractionInterface secondFraction) { SimpleFraction secondFraction2; secondFraction2 = (SimpleFraction) secondFraction; // a/b * c/d is (ac)/(bd)
  • 4. int newNum = num*secondFraction2.getNum(); int newDen = den*secondFraction2.getDen(); // return result which is a new SimpleFraction object return new SimpleFraction(newNum,newDen); } // end multiply public SimpleFractionInterface divide(SimpleFractionInterface secondFraction) { SimpleFraction secondFraction2; secondFraction2 = (SimpleFraction) secondFraction; // a/b / c/d is (ad)/(bc) // return SimpleFractionException if secondFraction is 0 if (secondFraction2.getNum() == 0) throw new SimpleFractionException("The second fraction cannot be 0"); int newNum= num*secondFraction2.getDen(); int newDen= den*secondFraction2.getNum(); // return result which is a new SimpleFraction object return new SimpleFraction(newNum,newDen); } // end divide public SimpleFractionInterface getReciprocal() { SimpleFraction r; // return SimpleFractionException if secondFraction is 0 if(den == 0) throw new SimpleFractionException("The second fraction cannot be 0"); else r = new SimpleFraction(den,num); // return result which is a new SimpleFraction object return r; } // end getReciprocal public boolean equals(Object other) { boolean result = false; if(other instanceof SimpleFraction){ SimpleFraction otherSimple = (SimpleFraction) other; if(compareTo(otherSimple) == 0)
  • 5. result = true; } return result; } // end equals public int compareTo(SimpleFraction other) { if(toDouble() == other.toDouble()) return 0; else if(toDouble() > other.toDouble()) return 1; else return -1; } // end compareTo public String toString() { return num + "/" + den; } // end toString /** Task: Reduces a fraction to lowest terms. */ // private methods start here private int getNum(){ return num; } private int getDen(){ return den; } private void reduceSimpleFractionToLowestTerms() { // Outline: // compute GCD of num & den // GCD works for + numbers. // So, you should eliminate - sign // then reduce numbers : num/GCD and den/GCD int sign = 1; //1= positive numbers; -1 = negative numbers
  • 6. if(num < 0){ //number negative sign = -1*sign; num = num*-1; } if (den < 0){ sign= -1*sign; den = den*-1; } int gcd= GCD(num,den); num= (num/gcd)*sign; den= den/gcd; } // end reduceSimpleFractionToLowestTerms /** Task: Computes the greatest common divisor of two integers. * @param integerOne an integer * @param integerTwo another integer * @return the greatest common divisor of the two integers */ private int GCD(int integerOne, int integerTwo) { int result; if (integerOne % integerTwo == 0) result = integerTwo; else result = GCD(integerTwo, integerOne % integerTwo); return result; } // end GCD //----------------------------------------------------------------- // Simple test is provided here public static void main(String[] args) { SimpleFractionInterface firstOperand = null; SimpleFractionInterface secondOperand = null; SimpleFractionInterface result = null; double doubleResult = 0.0; SimpleFraction nineSixteenths = new SimpleFraction(9, 16); // 9/16 SimpleFraction oneFourth = new SimpleFraction(1, 4); // 1/4
  • 7. System.out.println(" ========================================= "); // 7/8 + 9/16 firstOperand = new SimpleFraction(7, 8); result = firstOperand.add(nineSixteenths); System.out.println("The sum of " + firstOperand + " and " + nineSixteenths + " is tt" + result); System.out.println("tExpected result :tt23/16 "); // 9/16 - 7/8 firstOperand = nineSixteenths; secondOperand = new SimpleFraction(7, 8); result = firstOperand.subtract(secondOperand); System.out.println("The difference of " + firstOperand + " and " + secondOperand + " is t" + result); System.out.println("tExpected result :tt-5/16 "); // 15/-2 * 1/4 firstOperand = new SimpleFraction(15, -2); result = firstOperand.multiply(oneFourth); System.out.println("The product of " + firstOperand + " and " + oneFourth + " is t" + result); System.out.println("tExpected result :tt-15/8 "); // (-21/2) / (3/7) firstOperand = new SimpleFraction(-21, 2); secondOperand= new SimpleFraction(3, 7); result = firstOperand.divide(secondOperand); System.out.println("The quotient of " + firstOperand + " and " + secondOperand + " is t" + result); System.out.println("tExpected result :tt-49/2 "); // -21/2 + 7/8 firstOperand = new SimpleFraction(-21, 2); secondOperand= new SimpleFraction(7, 8); result = firstOperand.add(secondOperand); System.out.println("The sum of " + firstOperand + " and " + secondOperand + " is tt" + result); System.out.println("tExpected result :tt-77/8 "); // 0/10, 5/(-15), (-22)/7 firstOperand = new SimpleFraction(0, 10);
  • 8. doubleResult = firstOperand.toDouble(); System.out.println("The double floating point value of " + firstOperand + " is t" + doubleResult); System.out.println("tExpected result ttt0.0 "); firstOperand = new SimpleFraction(1, -3); doubleResult = firstOperand.toDouble(); System.out.println("The double floating point value of " + firstOperand + " is t" + doubleResult); System.out.println("tExpected result ttt-0.333333333... "); firstOperand = new SimpleFraction(-22, 7); doubleResult = firstOperand.toDouble(); System.out.println("The double floating point value of " + firstOperand + " is t" + doubleResult); System.out.println("tExpected result ttt-3.142857142857143"); System.out.println(" ========================================= "); firstOperand = new SimpleFraction(-21, 2); System.out.println("First = " + firstOperand); // equality check System.out.println("check First equals First: "); if (firstOperand.equals(firstOperand)) System.out.println("Identity of fractions OK"); else System.out.println("ERROR in identity of fractions"); secondOperand = new SimpleFraction(-42, 4); System.out.println(" Second = " + secondOperand); System.out.println("check First equals Second: "); if (firstOperand.equals(secondOperand)) System.out.println("Equality of fractions OK"); else System.out.println("ERROR in equality of fractions"); // comparison check SimpleFraction first = (SimpleFraction)firstOperand; SimpleFraction second = (SimpleFraction)secondOperand; System.out.println(" check First compareTo Second: "); if (first.compareTo(second) == 0)
  • 9. System.out.println("SimpleFractions == operator OK"); else System.out.println("ERROR in fractions == operator"); second = new SimpleFraction(7, 8); System.out.println(" Second = " + second); System.out.println("check First compareTo Second: "); if (first.compareTo(second) < 0) System.out.println("SimpleFractions < operator OK"); else System.out.println("ERROR in fractions < operator"); System.out.println(" check Second compareTo First: "); if (second.compareTo(first) > 0) System.out.println("SimpleFractions > operator OK"); else System.out.println("ERROR in fractions > operator"); System.out.println(" ========================================="); System.out.println(" check SimpleFractionException: 1/0"); try { SimpleFraction a1 = new SimpleFraction(1, 0); System.out.println("Error! No SimpleFractionException"); } catch ( SimpleFractionException fe ) { System.err.printf( "Exception: %s ", fe ); } // end catch System.out.println("Expected result : SimpleFractionException! "); System.out.println(" check SimpleFractionException: division"); try { SimpleFraction a2 = new SimpleFraction(); SimpleFraction a3 = new SimpleFraction(1, 2); a3.divide(a2); System.out.println("Error! No SimpleFractionException"); } catch ( SimpleFractionException fe ) { System.err.printf( "Exception: %s ", fe );
  • 10. } // end catch System.out.println("Expected result : SimpleFractionException! "); } // end main } // end SimpleFraction output: run: ========================================= The sum of 7/8 and 9/16 is 23/16 Expected result : 23/16 The difference of 9/16 and 7/8 is -5/16 Expected result : -5/16 The product of -15/2 and 1/4 is -15/8 Expected result : -15/8 The quotient of -21/2 and 3/7 is -49/2 Expected result : -49/2 The sum of -21/2 and 7/8 is -77/8 Expected result : -77/8 The double floating point value of 0/1 is 0.0 Expected result 0.0 The double floating point value of -1/3 is -0.3333333333333333 Expected result -0.333333333... The double floating point value of -22/7 is -3.142857142857143 Expected result -3.142857142857143 ========================================= First = -21/2 check First equals First: Identity of fractions OK Second = -21/2 check First equals Second: Equality of fractions OK check First compareTo Second: SimpleFractions == operator OK Second = 7/8 check First compareTo Second: SimpleFractions < operator OK
  • 11. check Second compareTo First: SimpleFractions > operator OK ========================================= check SimpleFractionException: 1/0 Exception: PJ1.SimpleFractionException: denominator cannot be 0 Expected result : SimpleFractionException! check SimpleFractionException: division Exception: PJ1.SimpleFractionException: The second fraction cannot be 0 Expected result : SimpleFractionException! BUILD SUCCESSFUL (total time: 3 seconds) Solution Interface package PJ1; public interface SimpleFractionInterface { /** Task: Sets a fraction to a given value. * @param num is the integer numerator * @param den is the integer denominator * @throw ArithmeticException if denominator is 0 */ public void setSimpleFraction(int num, int den); /** Task: convert a fraction to double value * @return the double floating point value of a fraction */ public double toDouble(); /** Task: Adds two fractions. * @param secondFraction is a fraction that is the second operand of the addition * @return a fraction which is the sum of the invoking fraction and the secondFraction */ public SimpleFractionInterface add(SimpleFractionInterface secondFraction); /** Task: Subtracts two fractions. * @param secondFraction a fraction that is the second operand of the subtraction * @return a fraction which is the difference of the invoking fraction and the second operand */ public SimpleFractionInterface subtract(SimpleFractionInterface secondFraction); /** Task: Multiplies two fractions. * @param secondFraction a fraction that is the second operand of the multiplication
  • 12. * @return a fraction which is the product of the invoking fraction and the secondFraction*/ public SimpleFractionInterface multiply(SimpleFractionInterface secondFraction); /** Task: Divides two fractions. * @param secondFraction a fraction that is the second operand of the division * @return a fraction which the quotient of the invoking fraction and the secondFraction * @throw FractionException if secondFraction is 0 */ public SimpleFractionInterface divide(SimpleFractionInterface secondFraction); /** Task: Get's the fraction's reciprocal * @return the reciprocal of the invoking fraction * @throw FractionException if the new number with denominator is 0*/ public SimpleFractionInterface getReciprocal(); } exception class package PJ1; public class SimpleFractionException extends RuntimeException { public SimpleFractionException() { this(""); } public SimpleFractionException(String errorMsg) { super(errorMsg); } } class with main method package PJ1; public class SimpleFraction implements SimpleFractionInterface, Comparable { // integer numerator and denominator private int num; private int den; public SimpleFraction() {
  • 13. setSimpleFraction(0,1);// default numbers } // end of the default constructor public SimpleFraction(int num, int den) { setSimpleFraction(num, den);// } // end constructor public void setSimpleFraction(int num, int den) { if (den == 0) throw new SimpleFractionException("denominator cannot be 0"); else{ this.num= num; this.den= den; } reduceSimpleFractionToLowestTerms(); } // end setSimpleFraction public double toDouble() { // return double floating point value return (double) num/den; } // end toDouble public SimpleFractionInterface add(SimpleFractionInterface secondFraction) { SimpleFraction secondFraction2; secondFraction2 = (SimpleFraction) secondFraction; // a/b + c/d is (ad + cb)/(bd) int newNum = num*secondFraction2.getDen() + secondFraction2.getNum()*den; int newDen = den*secondFraction2.getDen(); // return result which is a new SimpleFraction object return new SimpleFraction(newNum,newDen); } // end add public SimpleFractionInterface subtract(SimpleFractionInterface secondFraction) {
  • 14. SimpleFraction secondFraction2; secondFraction2 = (SimpleFraction) secondFraction; // a/b - c/d is (ad - cb)/(bd) int newNum = num*secondFraction2.getDen()-secondFraction2.getNum()*den; int newDen = den*secondFraction2.getDen(); // return result which is a new SimpleFraction object return new SimpleFraction(newNum,newDen); } // end subtract public SimpleFractionInterface multiply(SimpleFractionInterface secondFraction) { SimpleFraction secondFraction2; secondFraction2 = (SimpleFraction) secondFraction; // a/b * c/d is (ac)/(bd) int newNum = num*secondFraction2.getNum(); int newDen = den*secondFraction2.getDen(); // return result which is a new SimpleFraction object return new SimpleFraction(newNum,newDen); } // end multiply public SimpleFractionInterface divide(SimpleFractionInterface secondFraction) { SimpleFraction secondFraction2; secondFraction2 = (SimpleFraction) secondFraction; // a/b / c/d is (ad)/(bc) // return SimpleFractionException if secondFraction is 0 if (secondFraction2.getNum() == 0) throw new SimpleFractionException("The second fraction cannot be 0"); int newNum= num*secondFraction2.getDen(); int newDen= den*secondFraction2.getNum(); // return result which is a new SimpleFraction object return new SimpleFraction(newNum,newDen); } // end divide public SimpleFractionInterface getReciprocal() { SimpleFraction r; // return SimpleFractionException if secondFraction is 0 if(den == 0)
  • 15. throw new SimpleFractionException("The second fraction cannot be 0"); else r = new SimpleFraction(den,num); // return result which is a new SimpleFraction object return r; } // end getReciprocal public boolean equals(Object other) { boolean result = false; if(other instanceof SimpleFraction){ SimpleFraction otherSimple = (SimpleFraction) other; if(compareTo(otherSimple) == 0) result = true; } return result; } // end equals public int compareTo(SimpleFraction other) { if(toDouble() == other.toDouble()) return 0; else if(toDouble() > other.toDouble()) return 1; else return -1; } // end compareTo public String toString() { return num + "/" + den; } // end toString /** Task: Reduces a fraction to lowest terms. */ // private methods start here private int getNum(){ return num; }
  • 16. private int getDen(){ return den; } private void reduceSimpleFractionToLowestTerms() { // Outline: // compute GCD of num & den // GCD works for + numbers. // So, you should eliminate - sign // then reduce numbers : num/GCD and den/GCD int sign = 1; //1= positive numbers; -1 = negative numbers if(num < 0){ //number negative sign = -1*sign; num = num*-1; } if (den < 0){ sign= -1*sign; den = den*-1; } int gcd= GCD(num,den); num= (num/gcd)*sign; den= den/gcd; } // end reduceSimpleFractionToLowestTerms /** Task: Computes the greatest common divisor of two integers. * @param integerOne an integer * @param integerTwo another integer * @return the greatest common divisor of the two integers */ private int GCD(int integerOne, int integerTwo) { int result; if (integerOne % integerTwo == 0) result = integerTwo; else
  • 17. result = GCD(integerTwo, integerOne % integerTwo); return result; } // end GCD //----------------------------------------------------------------- // Simple test is provided here public static void main(String[] args) { SimpleFractionInterface firstOperand = null; SimpleFractionInterface secondOperand = null; SimpleFractionInterface result = null; double doubleResult = 0.0; SimpleFraction nineSixteenths = new SimpleFraction(9, 16); // 9/16 SimpleFraction oneFourth = new SimpleFraction(1, 4); // 1/4 System.out.println(" ========================================= "); // 7/8 + 9/16 firstOperand = new SimpleFraction(7, 8); result = firstOperand.add(nineSixteenths); System.out.println("The sum of " + firstOperand + " and " + nineSixteenths + " is tt" + result); System.out.println("tExpected result :tt23/16 "); // 9/16 - 7/8 firstOperand = nineSixteenths; secondOperand = new SimpleFraction(7, 8); result = firstOperand.subtract(secondOperand); System.out.println("The difference of " + firstOperand + " and " + secondOperand + " is t" + result); System.out.println("tExpected result :tt-5/16 "); // 15/-2 * 1/4 firstOperand = new SimpleFraction(15, -2); result = firstOperand.multiply(oneFourth); System.out.println("The product of " + firstOperand + " and " + oneFourth + " is t" + result); System.out.println("tExpected result :tt-15/8 "); // (-21/2) / (3/7) firstOperand = new SimpleFraction(-21, 2); secondOperand= new SimpleFraction(3, 7);
  • 18. result = firstOperand.divide(secondOperand); System.out.println("The quotient of " + firstOperand + " and " + secondOperand + " is t" + result); System.out.println("tExpected result :tt-49/2 "); // -21/2 + 7/8 firstOperand = new SimpleFraction(-21, 2); secondOperand= new SimpleFraction(7, 8); result = firstOperand.add(secondOperand); System.out.println("The sum of " + firstOperand + " and " + secondOperand + " is tt" + result); System.out.println("tExpected result :tt-77/8 "); // 0/10, 5/(-15), (-22)/7 firstOperand = new SimpleFraction(0, 10); doubleResult = firstOperand.toDouble(); System.out.println("The double floating point value of " + firstOperand + " is t" + doubleResult); System.out.println("tExpected result ttt0.0 "); firstOperand = new SimpleFraction(1, -3); doubleResult = firstOperand.toDouble(); System.out.println("The double floating point value of " + firstOperand + " is t" + doubleResult); System.out.println("tExpected result ttt-0.333333333... "); firstOperand = new SimpleFraction(-22, 7); doubleResult = firstOperand.toDouble(); System.out.println("The double floating point value of " + firstOperand + " is t" + doubleResult); System.out.println("tExpected result ttt-3.142857142857143"); System.out.println(" ========================================= "); firstOperand = new SimpleFraction(-21, 2); System.out.println("First = " + firstOperand); // equality check System.out.println("check First equals First: "); if (firstOperand.equals(firstOperand)) System.out.println("Identity of fractions OK"); else System.out.println("ERROR in identity of fractions");
  • 19. secondOperand = new SimpleFraction(-42, 4); System.out.println(" Second = " + secondOperand); System.out.println("check First equals Second: "); if (firstOperand.equals(secondOperand)) System.out.println("Equality of fractions OK"); else System.out.println("ERROR in equality of fractions"); // comparison check SimpleFraction first = (SimpleFraction)firstOperand; SimpleFraction second = (SimpleFraction)secondOperand; System.out.println(" check First compareTo Second: "); if (first.compareTo(second) == 0) System.out.println("SimpleFractions == operator OK"); else System.out.println("ERROR in fractions == operator"); second = new SimpleFraction(7, 8); System.out.println(" Second = " + second); System.out.println("check First compareTo Second: "); if (first.compareTo(second) < 0) System.out.println("SimpleFractions < operator OK"); else System.out.println("ERROR in fractions < operator"); System.out.println(" check Second compareTo First: "); if (second.compareTo(first) > 0) System.out.println("SimpleFractions > operator OK"); else System.out.println("ERROR in fractions > operator"); System.out.println(" ========================================="); System.out.println(" check SimpleFractionException: 1/0"); try { SimpleFraction a1 = new SimpleFraction(1, 0); System.out.println("Error! No SimpleFractionException"); } catch ( SimpleFractionException fe ) {
  • 20. System.err.printf( "Exception: %s ", fe ); } // end catch System.out.println("Expected result : SimpleFractionException! "); System.out.println(" check SimpleFractionException: division"); try { SimpleFraction a2 = new SimpleFraction(); SimpleFraction a3 = new SimpleFraction(1, 2); a3.divide(a2); System.out.println("Error! No SimpleFractionException"); } catch ( SimpleFractionException fe ) { System.err.printf( "Exception: %s ", fe ); } // end catch System.out.println("Expected result : SimpleFractionException! "); } // end main } // end SimpleFraction output: run: ========================================= The sum of 7/8 and 9/16 is 23/16 Expected result : 23/16 The difference of 9/16 and 7/8 is -5/16 Expected result : -5/16 The product of -15/2 and 1/4 is -15/8 Expected result : -15/8 The quotient of -21/2 and 3/7 is -49/2 Expected result : -49/2 The sum of -21/2 and 7/8 is -77/8 Expected result : -77/8 The double floating point value of 0/1 is 0.0 Expected result 0.0 The double floating point value of -1/3 is -0.3333333333333333 Expected result -0.333333333... The double floating point value of -22/7 is -3.142857142857143
  • 21. Expected result -3.142857142857143 ========================================= First = -21/2 check First equals First: Identity of fractions OK Second = -21/2 check First equals Second: Equality of fractions OK check First compareTo Second: SimpleFractions == operator OK Second = 7/8 check First compareTo Second: SimpleFractions < operator OK check Second compareTo First: SimpleFractions > operator OK ========================================= check SimpleFractionException: 1/0 Exception: PJ1.SimpleFractionException: denominator cannot be 0 Expected result : SimpleFractionException! check SimpleFractionException: division Exception: PJ1.SimpleFractionException: The second fraction cannot be 0 Expected result : SimpleFractionException! BUILD SUCCESSFUL (total time: 3 seconds)