Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. //client class
  2. //allows user to enter fractions and operations calculating and displaying the result.
  3. //it will run until the user tells it to quit, by pressing q
  4.  
  5. import java.util.*;
  6.  
  7. public class FractionCalculator{
  8.  
  9. public static void main (String[] args){
  10.  
  11. //prints info
  12. System.out.println("Welcome to Fraction Calculator");
  13. System.out.println("You can add, subtract, multiply, and divide fractions");
  14. System.out.println("Enter your fractions in the form a/b where both a and b are integers");
  15. System.out.println("---------------------------------------------------------------------");
  16.  
  17.  
  18. //prompts for operation
  19. //getOperation();
  20.  
  21. //prompts for fraction
  22. //getFraction();
  23.  
  24. Fraction fractionOneObject = new Fraction(1, 2);
  25.  
  26. Fraction oneParameterFractionObject = new Fraction (484);
  27.  
  28. Fraction zeroParameterFractionObject = new Fraction();
  29.  
  30.  
  31. System.out.println(fractionOneObject.getNumerator());
  32. System.out.println(fractionOneObject.getDenominator());
  33. System.out.println(fractionOneObject.toString());
  34. System.out.println(fractionOneObject.toDouble());
  35.  
  36.  
  37. }
  38.  
  39. public static void getOperation(){
  40.  
  41. //prompts for operation (+, -, *, /, = or Q)
  42. Scanner input = new Scanner(System.in);
  43. System.out.print("Enter an operator (+, -, *, /, = or Q to quit): ");
  44.  
  45. char operation = input.next().charAt(0);
  46.  
  47. do {
  48. System.out.println("Invalid input");
  49. System.out.print("Enter an operator (+, -, *, /, = or Q to quit): ");
  50.  
  51. operation = input.next().charAt(0);
  52.  
  53. } while (operation != '+' && operation != '-' && operation != '*' && operation != '/' && operation != '=' && operation != 'Q' && operation != 'q' );
  54.  
  55. if (operation == 'q' || operation == 'Q') {
  56. System.exit(0);
  57. }
  58.  
  59. }
  60.  
  61. public static void getFraction(){
  62. Scanner input = new Scanner(System.in);
  63. System.out.print("Enter a fraction (a/b) or integer (a): ");
  64. String fractionOneString = input.next();
  65.  
  66. fractionOneString.split("/");
  67.  
  68. System.out.println(fractionOneString);
  69. System.out.println(fractionOneString.charAt(0));
  70. System.out.println(fractionOneString.charAt(2));
  71.  
  72.  
  73.  
  74. }
  75.  
  76. public static void validFraction(){
  77.  
  78. }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement