Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //client class
- //allows user to enter fractions and operations calculating and displaying the result.
- //it will run until the user tells it to quit, by pressing q
- import java.util.*;
- public class FractionCalculator{
- public static void main (String[] args){
- //prints info
- System.out.println("Welcome to Fraction Calculator");
- System.out.println("You can add, subtract, multiply, and divide fractions");
- System.out.println("Enter your fractions in the form a/b where both a and b are integers");
- System.out.println("---------------------------------------------------------------------");
- //prompts for operation
- //getOperation();
- //prompts for fraction
- //getFraction();
- Fraction fractionOneObject = new Fraction(1, 2);
- Fraction oneParameterFractionObject = new Fraction (484);
- Fraction zeroParameterFractionObject = new Fraction();
- System.out.println(fractionOneObject.getNumerator());
- System.out.println(fractionOneObject.getDenominator());
- System.out.println(fractionOneObject.toString());
- System.out.println(fractionOneObject.toDouble());
- }
- public static void getOperation(){
- //prompts for operation (+, -, *, /, = or Q)
- Scanner input = new Scanner(System.in);
- System.out.print("Enter an operator (+, -, *, /, = or Q to quit): ");
- char operation = input.next().charAt(0);
- do {
- System.out.println("Invalid input");
- System.out.print("Enter an operator (+, -, *, /, = or Q to quit): ");
- operation = input.next().charAt(0);
- } while (operation != '+' && operation != '-' && operation != '*' && operation != '/' && operation != '=' && operation != 'Q' && operation != 'q' );
- if (operation == 'q' || operation == 'Q') {
- System.exit(0);
- }
- }
- public static void getFraction(){
- Scanner input = new Scanner(System.in);
- System.out.print("Enter a fraction (a/b) or integer (a): ");
- String fractionOneString = input.next();
- fractionOneString.split("/");
- System.out.println(fractionOneString);
- System.out.println(fractionOneString.charAt(0));
- System.out.println(fractionOneString.charAt(2));
- }
- public static void validFraction(){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement