Advertisement
Guest User

Fraction Runner

a guest
Jan 15th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FractionRunner
  4. {
  5.   public static void main (String[] args)
  6.   {
  7.       Scanner reader = new Scanner (System.in);
  8.       Fraction f1 = new Fraction();
  9.       Fraction f2 = new Fraction();
  10.       String input = "";
  11.       boolean n = true;
  12.       /**
  13.        * input for f1 (fraction one)
  14.        */
  15.       while(n){
  16.       System.out.println("*Basic Fraction Calculator*");
  17.       System.out.println("***************************");
  18.       System.out.println("CHOOSE ONE OF THE FOLLOWING CHOICES");
  19.       System.out.println("a) Choose to add");
  20.       System.out.println("b) Choose to convert a fraction into decimal");
  21.       input = reader.next();
  22.       input.toLowerCase();
  23.      
  24.       if(input.equals("a"))
  25.       {
  26.       System.out.print("Give me a numerator: ");
  27.       int x = reader.nextInt();
  28.       f1.setNumerator(x);
  29.      
  30.       System.out.print("Give me a denominator: ");
  31.       int y = reader.nextInt();
  32.       f1.setDenominator(y);
  33.       /**
  34.        * input for f2 (fraction 2)
  35.        */
  36.       System.out.print("Give me a numerator: ");
  37.       int z = reader.nextInt();
  38.       f2.setNumerator(z);
  39.      
  40.       System.out.print("Give me a denominator: ");
  41.       int q = reader.nextInt();
  42.       f2.setDenominator(q);
  43.       System.out.println(f1.add(f1, f2).toString());
  44.       }
  45.  
  46.       else if(input.equals("b"));
  47.       {
  48.       System.out.print("Give me a numerator: ");
  49.       int x = reader.nextInt();
  50.       f1.setNumerator(x);
  51.      
  52.       System.out.print("Give me a denominator: ");
  53.       int y = reader.nextInt();
  54.       f1.setDenominator(y);
  55.      
  56.       System.out.println(f1.toDecimal());
  57.        }
  58.        
  59.     System.out.println("Would you like to continue? y/n");
  60.     input = reader.next();
  61.     if (input.equals("n"))
  62.     {
  63.         n=false;
  64.     }
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement