Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FractionRunner
- {
- public static void main (String[] args)
- {
- Scanner reader = new Scanner (System.in);
- Fraction f1 = new Fraction();
- Fraction f2 = new Fraction();
- String input = "";
- boolean n = true;
- /**
- * input for f1 (fraction one)
- */
- while(n){
- System.out.println("*Basic Fraction Calculator*");
- System.out.println("***************************");
- System.out.println("CHOOSE ONE OF THE FOLLOWING CHOICES");
- System.out.println("a) Choose to add");
- System.out.println("b) Choose to convert a fraction into decimal");
- input = reader.next();
- input.toLowerCase();
- if(input.equals("a"))
- {
- System.out.print("Give me a numerator: ");
- int x = reader.nextInt();
- f1.setNumerator(x);
- System.out.print("Give me a denominator: ");
- int y = reader.nextInt();
- f1.setDenominator(y);
- /**
- * input for f2 (fraction 2)
- */
- System.out.print("Give me a numerator: ");
- int z = reader.nextInt();
- f2.setNumerator(z);
- System.out.print("Give me a denominator: ");
- int q = reader.nextInt();
- f2.setDenominator(q);
- System.out.println(f1.add(f1, f2).toString());
- }
- else if(input.equals("b"));
- {
- System.out.print("Give me a numerator: ");
- int x = reader.nextInt();
- f1.setNumerator(x);
- System.out.print("Give me a denominator: ");
- int y = reader.nextInt();
- f1.setDenominator(y);
- System.out.println(f1.toDecimal());
- }
- System.out.println("Would you like to continue? y/n");
- input = reader.next();
- if (input.equals("n"))
- {
- n=false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement