Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class FractionCalculator {
- public static void main(String[] args){
- intro();
- String operand = operand();
- }
- private static void intro() {
- System.out.println("This program is a Fraction Calculator.");
- System.out.println("It will add, subtract, multiply and divide fractions until you type Q to quit.");
- System.out.println("Please enter your fractions in the form a/b, where a and b are integers.");
- for (int i = 0; i < 100; i++) {
- System.out.print("-");
- }
- }
- private static String operand(){
- Scanner input = new Scanner(System.in);
- System.out.print("PLease enter an operation (+, -, /, *, = or Q to quit: ");
- String operand = input.nextLine();
- while (operand != "+" && operand != "-" && operand != "*" && operand != "/" && operand != "=") {
- System.out.print("Invalid input (+, -, /, *, = or Q to quit): ");
- operand = input.nextLine();
- }
- return operand;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement