Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Needs help implementing two methods for Fraction object. Methods are asking to a

ID: 3528983 • Letter: N

Question

Needs help implementing two methods for Fraction object. Methods are asking to add and subtract fractions. An interface, FractionInterface, is used, which I am a little confused on how I tie in to implement two methods. Project can be found on my webpage: https://sites.google.com/site/cschomeworkhelp2013/home public FractionInterface add(FractionInterface secondFraction) public FractionInterface subtract(FractionInterface secondFraction) are the two methods that are bolded on webpage....this will give me a heads start to figure it out.

Explanation / Answer

*/ import java.util.*; import PJ1.*; class PJ1_Test { static private Scanner scanner; private static Fraction readFraction() { System.out.print( " Try to read a fraction x/y, please enter x y : " ); int numerator = scanner.nextInt(); int denominator = scanner.nextInt(); Fraction f = new Fraction(numerator, denominator); System.out.println( " Read OK:"+f); return f; } private static void printOperations() { System.out.println("=============================================="); System.out.println(" Operations:"); System.out.println(" 0) exit 1) add 2) subtract 3) multiply 4) divide"); System.out.println(" 5) compareTo 6) equals 7) recipocal 8) switchSign 9) getSign "); System.out.println(" 10) getNumerator 11) getDenominator 12) setFraction (x/y) "); System.out.print( " Enter an operation number: "); } public static void main( String args[] ) { scanner = new Scanner( System.in ); // scanner for input boolean continueLoop = true; // determines if more input is needed Fraction n1=null; Fraction n2=null; int op,x,y; do { try // read two numbers and calculate quotient { printOperations(); op= scanner.nextInt(); if (op == 0) { break; } else if ((op >0) && (op 6) && (op < 12)) { n1 = readFraction(); } else if (op == 12) { n1 = new Fraction(); } else if (op == 13) { n1 = new Fraction(); } else { System.out.print( " Invalid input... try again " ); continue; } System.out.println(" Tests: "); switch (op) { case 1: System.out.println(" " + n1 + " + " + n1 + " = " + n1.add(n1)); System.out.println(" " + n2 + " + " + n2 + " = " + n2.add(n2)); System.out.println(" " + n1 + " + " + n2 + " = " + n1.add(n2)); System.out.println(" " + n2 + " + " + n1 + " = " + n2.add(n1)); break; case 2: System.out.println(" " + n1 + " - " + n1 + " = " + n1.subtract(n1)); System.out.println(" " + n2 + " - " + n2 + " = " + n2.subtract(n2)); System.out.println(" " + n1 + " - " + n2 + " = " + n1.subtract(n2)); System.out.println(" " + n2 + " - " + n1 + " = " + n2.subtract(n1)); break; case 3: System.out.println(" " + n1 + " * " + n1 + " = " + n1.multiply(n1)); System.out.println(" " + n2 + " * " + n2 + " = " + n2.multiply(n2)); System.out.println(" " + n1 + " * " + n2 + " = " + n1.multiply(n2)); System.out.println(" " + n2 + " * " + n1 + " = " + n2.multiply(n1)); break; case 4: System.out.println(" " + n1 + " / " + n1 + " = " + n1.divide(n1)); System.out.println(" " + n2 + " / " + n2 + " = " + n2.divide(n2)); System.out.println(" " + n1 + " / " + n2 + " = " + n1.divide(n2)); System.out.println(" " + n2 + " / " + n1 + " = " + n2.divide(n1)); break; case 5: System.out.println(" " + n1 + " ct " + n1 + " = " + n1.compareTo(n1)); System.out.println(" " + n2 + " ct " + n2 + " = " + n2.compareTo(n2)); System.out.println(" " + n1 + " ct " + n2 + " = " + n1.compareTo(n2)); System.out.println(" " + n2 + " ct " + n1 + " = " + n2.compareTo(n1)); break; case 6: System.out.println(" " + n1 + " eq "+ n1 + " = " + n1.equals(n1)); System.out.println(" " + n2 + " eq "+ n2 + " = " + n2.equals(n2)); System.out.println(" " + n1 + " eq "+ n2 + " = " + n1.equals(n2)); System.out.println(" " + n2 + " eq "+ n1 + " = " + n2.equals(n1)); break; case 7: System.out.println(" " + n1 + " getReciprocal= " + n1.getReciprocal()); break; case 8: System.out.print(" " + n1 ); n1.switchSign(); System.out.println(" switchSign - = " + n1); System.out.print(" " + n1 ); n1.switchSign(); System.out.println(" switchSign + = " + n1); break; case 9: System.out.println(" " + n1 + " getSign = " + n1.getSign()); break; case 10: System.out.println(" " + n1 + " getNumerator = " + n1.getNumerator()); break; case 11: System.out.println(" " + n1 + " getDenominator = " + n1.getDenominator()); break; case 12: System.out.print( "read a fraction x/y, please enter x y : " ); x = scanner.nextInt(); y = scanner.nextInt(); System.out.print(" " + n1 + " setFraction = "); n1.setFraction(x,y); System.out.println(n1); break; } } // end try catch ( ArithmeticException arithmeticException ) { System.err.printf( " Exception: %s ", arithmeticException ); } // end catch } while ( continueLoop ); // end do...while } // end main }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote