Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Tester
  4. {
  5. private static void display(Rational r, String msg)
  6. {
  7. System.out.println("variable: "+msg);
  8. System.out.println("oldNum: "+r.getOldNum());
  9. System.out.println("oldDen: "+r.getOldDen());
  10. System.out.println("newNum: "+r.getNewNum());
  11. System.out.println("newDen: "+r.getNewDen());
  12. System.out.println("getDecimal(): "+r.getDecimal());
  13. System.out.println("displayOldFract(): ");
  14. r.displayOldFract();
  15.  
  16. System.out.print("displayNewFract(): ");
  17. r.displayNewFract();
  18.  
  19. System.out.println();
  20. }
  21. public static void main(String[] args)
  22. {
  23. Scanner input = new Scanner(System.in);
  24.  
  25. Rational o1 = new Rational();
  26. display(o1,"o1");
  27.  
  28. System.out.println("Enter a numerator");
  29. Rational o2 = new Rational(input.nextInt());
  30. display(o2,"o2");
  31. o2.reduce();
  32. display(o2,"o2");
  33.  
  34. System.out.println("Enter a numerator and a denominator");
  35. Rational o3 = new Rational(input.nextInt(), input.nextInt());
  36. display(o3,"o3");
  37. o3.reduce();
  38. display(o3,"o3");
  39.  
  40. Rational o4 = new Rational(o3);
  41. display(o4,"o4 is a copy of o3");
  42.  
  43. o1.multFracts(o2,o3);
  44. o1.reduce();
  45. display(o1,"mult test");
  46. o1.divFracts(o2,o3);
  47. o1.reduce();
  48. display(o1,"div test");
  49. o1.addFracts(o2,o3);
  50. o1.reduce();
  51. display(o1,"add test");
  52. o1.subFracts(o2,o3);
  53. o1.reduce();
  54. display(o1,"sub test");
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement