Wrapper Classes And Other Classes Of java.lang Package

Add Comment

    • 1. Write a class Foo that wraps two Integer objects (representing a fraction) and has method(s) for displaying itself as a fraction.

      2. Write a class Foo2 that wraps two Foo objects (the two fractions to be operated on).

      3. Write a Foo2 method for each of the four arithmetic operations. Each method will compute a resulting Foo object from the operation and will return that object and/or store it internally for later access.

      You should be able to do something like this after completing the above:

      Integer numer_1, numer_2, denom_1, denom_2;
      Foo frac1, frac2;
      Foo2 operands;

      // Add, subtract, multiply and divide 2/3 and 4/5 and display result.

      numer_1 = new Integer(2);
      denom_1 = new Integer(3);
      numer_2 = new Integer(4);
      denom_2 = new Integer(5);
      frac1 = new Foo(numer_1, denom_1);
      frac2 = new Foo(numer_2, denom_2);
      operands = new Foo2(frac1, frac2);
      operands.add().display();
      operands.sub().display();
      operands.mult().display();
      operands.div().display();

Sponsors

Facebook Fans