Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.90 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. public class Driver{
  4. public static void main(String args[]){
  5. Scanner kboard = new Scanner(System.in);
  6. Fraction frac, frac2;
  7. int numer, denom, choice;
  8. String loop;
  9. while(!loop.equals("quit")){
  10. System.out.print("Please enter the numerator for the fraction: ");
  11. numer = kboard.nextInt();
  12.  
  13. System.out.print("Please enter the denominator for the fraction: ");
  14. denom = kboard.nextInt();
  15.  
  16. frac = new Fraction(numer, denom);
  17.  
  18. System.out.println("Please pick select an option: \n1. Simplify \n2. Add \n3. Subtract \n4. Multiply" +
  19. "\n5. Divide \n6. Compare \n7. Equals \n8. Decimal form \n9. Random Fraction" +
  20. "\n10. Show all strings");
  21.  
  22. choice = kboard.nextInt();
  23. switch(choice){
  24. case 1:
  25. System.out.println("The simplified version of the fraction is: " + frac.Simplify());
  26. break;
  27.  
  28. case 2:
  29. System.out.print("Give a fraction to add to the original fraction\nThe numerator is");
  30. numer = kboard.nextInt();
  31. System.out.print("The denominator is: ");
  32. denom = kboard.nextInt();
  33. frac2 = new Fraction(numer, denom);
  34.  
  35. System.out.println("The sum of these fractions is: " + frac.add(frac2));
  36. break;
  37.  
  38. case 3:
  39. System.out.print("Give a fraction to subtract from the original fraction\nThe numerator is");
  40. numer = kboard.nextInt();
  41. System.out.print("The denominator is: ");
  42. denom = kboard.nextInt();
  43. frac2 = new Fraction(numer, denom);
  44. System.out.println("The difference of these fractions is: " + frac.subtract(frac2));
  45.  
  46. break;
  47.  
  48. case 4:
  49. System.out.print("Give a fraction to multiply with the original fraction\nThe numerator is");
  50. numer = kboard.nextInt();
  51. System.out.print("The denominator is: ");
  52. denom = kboard.nextInt();
  53. frac2 = new Fraction(numer, denom);
  54. System.out.println("The product of these fractions is: " + frac.multiply(frac2));
  55. break;
  56.  
  57. case 5:
  58. System.out.print("Give a fraction to divide with the original fraction\nThe numerator is");
  59. numer = kboard.nextInt();
  60. System.out.print("The denominator is: ");
  61. denom = kboard.nextInt();
  62. frac2 = new Fraction(numer, denom);
  63. System.out.println("The result of these fractions is: " + frac.divide(frac2));
  64. break;
  65.  
  66. case 6:
  67. System.out.print("Give a fraction to compare with the original fraction\nThe numerator is");
  68. numer = kboard.nextInt();
  69. System.out.print("The denominator is: ");
  70. denom = kboard.nextInt();
  71. frac2 = new Fraction(numer, denom);
  72. System.out.println( frac.compareTo(frac2));
  73. break;
  74.  
  75. case 7:
  76. System.out.print("Give a fraction to see if it is equal to the original fraction \nThe numerator is");
  77. numer = kboard.nextInt();
  78. System.out.print("The denominator is: ");
  79. denom = kboard.nextInt();
  80. frac2 = new Fraction(numer, denom);
  81. if(frac.equals(frac2)){
  82. System.out.println("Your fraction is equal to the original fraction");
  83. }else{
  84. System.out.println("The fractions are not equal.");
  85. }
  86. break;
  87.  
  88. case 8:
  89. System.out.println("The decimal form of this fraction is: " + frac.decimal());
  90. break;
  91.  
  92. case 9:
  93. System.out.println("The random fraction is: " + frac.randFrac());
  94. break;
  95.  
  96. case 10:
  97. System.out.println(frac.toString());
  98. break;
  99.  
  100. default:
  101. System.out.println("Please try again and enter a valid choice.");
  102.  
  103. }
  104. System.out.print("Type 'quit' to quit the program, otherwise type anything else and hit enter.");
  105. loop = kboard.next();
  106.  
  107. }
  108.  
  109. System.out.println("Goodbye!");
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement