Example #1
0
 public static Fraction multiply(Fraction a, Fraction b, Fraction... fractions) {
   Fraction result = Fraction.multiply(a, b);
   for (Fraction c : fractions) {
     result = Fraction.multiply(result, c);
   }
   return result;
 }
Example #2
0
 @Test
 public void testMultiply() {
   assertEquals(myFraction1.multiply(myFraction2).toString(), "12 / 25");
   assertEquals(myFraction3.multiply(myFraction4).toString(), "10 / 49");
   myFraction1 = myFraction1.add(myFraction1);
 }
Example #3
0
  public void actionPerformed(ActionEvent com) {
    String e = com.getActionCommand();
    if (e.equals("1")) {
      msg.append("1");
    }
    if (e.equals("2")) {
      msg.append("2");
    }
    if (e.equals("3")) {
      msg.append("3");
    }
    if (e.equals("4")) {
      msg.append("4");
    }
    if (e.equals("5")) {
      msg.append("5");
    }
    if (e.equals("6")) {
      msg.append("6");
    }
    if (e.equals("7")) {
      msg.append("7");
    }
    if (e.equals("8")) {
      msg.append("8");
    }
    if (e.equals("9")) {
      msg.append("9");
    }
    if (e.equals("0")) {
      msg.append("0");
    }
    // *********************OPERANDS**********************

    if (e.equals("*")) {
      pushsign = 2;
      String peeked = new String(OperandStack.peek());
      if (peeked == "*") {
        frac2 = Fraction(FracStack.pop());
        frac1 = FracStack.pop();
        frac3 = frac1.multiply(frac2);
        FracStack.push(frac3);
        FracStack.push(new Fraction(msg.getText()));
        OperandStack.push(peeked);
      }
      if (peeked == "/") {
        frac2 = new Fraction(FracStack.pop());
        frac1 = new Fraction(FracStack.pop());
        frac3 = frac1.multiply(frac2);
        FracStack.push(frac3);
        FracStack.push(new Fraction(msg.getText()));
        OperandStack.push(peeked);
      }
    }
    if (e.equals("/")) {}

    if (e.equals("+")) {}

    if (e.equals("-")) {}

    if (e.equals("=")) {}

    if (e.equals("Frac")) {
      msg.append("/");
    }
  }