Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class Driver{
- public static void main(String args[]){
- Scanner kboard = new Scanner(System.in);
- Fraction frac, frac2;
- int numer, denom, choice;
- String loop;
- while(!loop.equals("quit")){
- System.out.print("Please enter the numerator for the fraction: ");
- numer = kboard.nextInt();
- System.out.print("Please enter the denominator for the fraction: ");
- denom = kboard.nextInt();
- frac = new Fraction(numer, denom);
- System.out.println("Please pick select an option: \n1. Simplify \n2. Add \n3. Subtract \n4. Multiply" +
- "\n5. Divide \n6. Compare \n7. Equals \n8. Decimal form \n9. Random Fraction" +
- "\n10. Show all strings");
- choice = kboard.nextInt();
- switch(choice){
- case 1:
- System.out.println("The simplified version of the fraction is: " + frac.Simplify());
- break;
- case 2:
- System.out.print("Give a fraction to add to the original fraction\nThe numerator is");
- numer = kboard.nextInt();
- System.out.print("The denominator is: ");
- denom = kboard.nextInt();
- frac2 = new Fraction(numer, denom);
- System.out.println("The sum of these fractions is: " + frac.add(frac2));
- break;
- case 3:
- System.out.print("Give a fraction to subtract from the original fraction\nThe numerator is");
- numer = kboard.nextInt();
- System.out.print("The denominator is: ");
- denom = kboard.nextInt();
- frac2 = new Fraction(numer, denom);
- System.out.println("The difference of these fractions is: " + frac.subtract(frac2));
- break;
- case 4:
- System.out.print("Give a fraction to multiply with the original fraction\nThe numerator is");
- numer = kboard.nextInt();
- System.out.print("The denominator is: ");
- denom = kboard.nextInt();
- frac2 = new Fraction(numer, denom);
- System.out.println("The product of these fractions is: " + frac.multiply(frac2));
- break;
- case 5:
- System.out.print("Give a fraction to divide with the original fraction\nThe numerator is");
- numer = kboard.nextInt();
- System.out.print("The denominator is: ");
- denom = kboard.nextInt();
- frac2 = new Fraction(numer, denom);
- System.out.println("The result of these fractions is: " + frac.divide(frac2));
- break;
- case 6:
- System.out.print("Give a fraction to compare with the original fraction\nThe numerator is");
- numer = kboard.nextInt();
- System.out.print("The denominator is: ");
- denom = kboard.nextInt();
- frac2 = new Fraction(numer, denom);
- System.out.println( frac.compareTo(frac2));
- break;
- case 7:
- System.out.print("Give a fraction to see if it is equal to the original fraction \nThe numerator is");
- numer = kboard.nextInt();
- System.out.print("The denominator is: ");
- denom = kboard.nextInt();
- frac2 = new Fraction(numer, denom);
- if(frac.equals(frac2)){
- System.out.println("Your fraction is equal to the original fraction");
- }else{
- System.out.println("The fractions are not equal.");
- }
- break;
- case 8:
- System.out.println("The decimal form of this fraction is: " + frac.decimal());
- break;
- case 9:
- System.out.println("The random fraction is: " + frac.randFrac());
- break;
- case 10:
- System.out.println(frac.toString());
- break;
- default:
- System.out.println("Please try again and enter a valid choice.");
- }
- System.out.print("Type 'quit' to quit the program, otherwise type anything else and hit enter.");
- loop = kboard.next();
- }
- System.out.println("Goodbye!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement