CS111 Programming Assignment 3
Building Classes

Instructor: Trish Cornez


Problem 1: Written Answers

  1. Briefly explain how abstract classes are different from regular classes.
  2. Briefly explain how abstract classes are similar to regular classes.
  3. When is an abstract class useful? Provide an example of an abstract class and a related regular class.
  4. What is the superclass of all other classes in Java?
  5. What are the Object methods in Java?


Program 1: BigNumber class

      In languages such as C++ and Java, the primitive data type int is limited to a 32 bit or 64 bit representation. Construct a class, BigNumber, to represent very large integers - integers greater than 2,147,483,647. Write the necessary class methods allowing the addition of any two BigNumber objects. Assume only addition will be performed on this class of numbers.

      Write a test application that prompts the user for two BigNumber data elements and add them together.
      Test Execution 1:
      x = 647483147999
      y = 991999999999
      x.add(y); should produce 1639483147998


      Test Execution 2:
      x = 647483147911
      y = 21
      x.add(y); should produce 647483147932


      Test Execution 3:
      x = 19
      y = 765521
      x.add(y); should produce 765540


      Suggestions:
      1. Treat each big number as a String containing a collection of digits.
      2. Add the BigNumbers digit by digit, adding a carry value when necessary.
        For example, the big numbers 778321 and 100000 are stored as strings. But, when summing the two, an ArrayList of Integers can be used to compute independent digits.
          big[0] = 1
          big[1] = 2
          big[2] = 3
          big[3] = 8
          big[4] = 7
          big[5] = 8



Program 2: Rectangle class and Square class

    A square is a rectangle whose length and width are the same.
    Implement a square class from a rectangle base class by using inheritance.