Advertisement
Guest User

FractionCalculator.class

a guest
Jul 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class FractionCalculator {
  4.  
  5.  
  6.     public static void main(String[] args){
  7.         intro();
  8.         String operand = operand();
  9.  
  10.  
  11.     }
  12.  
  13.     private static void intro() {
  14.         System.out.println("This program is a Fraction Calculator.");
  15.         System.out.println("It will add, subtract, multiply and divide fractions until you type Q to quit.");
  16.         System.out.println("Please enter your fractions in the form a/b, where a and b are integers.");
  17.         for (int i = 0; i < 100; i++) {
  18.             System.out.print("-");
  19.         }
  20.     }
  21.  
  22.     private static String operand(){
  23.         Scanner input = new Scanner(System.in);
  24.         System.out.print("PLease enter an operation (+, -, /, *, = or Q to quit: ");
  25.         String operand = input.nextLine();
  26.  
  27.         while (operand != "+" && operand != "-" && operand != "*" && operand != "/" && operand != "=") {
  28.             System.out.print("Invalid input (+, -, /, *, = or Q to quit): ");
  29.             operand = input.nextLine();
  30.         }
  31.         return operand;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement