Problem #1: CustomBigInteger

Design a class called CustomBigInteger. The class should contain an array of size 50 elements where each element of the array is a digit of a number. This means you can store an integer up to 50 digits long. NOTE: You do not have to worry about negative numbers.

Provide the following methods in your CustomBigInteger class:

  • a Constructor which creates a new CustomBigInteger object from a String parameter.
  • parseBigInt: This is a private method which takes a string of numbers and extracts and parses each digit into its integer equivalent and stores the digits in the data field array of the CustomBigInteger object. The method should verify that the given string contains only numbers, if not display an error message. The method should also verify that the size of the string is not more than 50 numbers. If so, display an error message. NOTE: You are allowed to have less than 50 digits in the number.
  • add: Takes a CustomBigInteger object as a parameter and finds the sum of this object and the parameter object. Returns a new CustomBigInteger object. Consider how to add together an integer that is this large. Don't forget to carry values over to the next integer position.
  • subtract: Takes a CustomBigInteger object as a parameter and finds the difference of this object and the parameter object. Returns a new CustomBigInteger object. Consider how subtraction works remembering to "borrow" from another integer position when necessary. You do not need to worry about negative results. I will only test with values that will produce a positive difference.
  • toString: prints out a string representation of the CustomBigInteger

Create a driver / tester which asks the user for two large integers. Use the input to create two CustomBigInteger and show the output of add and subtract.

NOTE: You may find that this program is easier to implement if you store the digits starting from the last index to the first.

Problem #2: CustomSet

A Set is a mathematical construct where each value in the set is unique. Design a class called CustomSet which will be an object which can hold a set of integers in the range 0 100. The set is represented by an array of boolean values. An element of the array is true if the integer represented by that index is in the set, false if not in the set.

The no-arg constructor initializes the array to the "empty set" (all values in the array should be false). You should also provide another constructor which takes an integer array as an argument. The values in the array should then be used to initialize the CustomSet object. The parameter array should only hold values between 0 and 100.

Provide a method insertElement which inserts a new integer into the set (by setting that index position to be true). Provide a method deleteElement which deletes an integer from the set (by setting that index position to be false).

Also provide a toString method which prints out a string representation of your CustomSet object. If the set is empty, you may print out an empty pair of {}. Your string representation should look something like: {1, 2, 6, 10, 42}.

Design another class of static methods called CustomSetUtils which has the following static methods:

  • union: Takes two CustomSet objects as parameters and returns the union of both sets as a CustomSet object. An element of the new set is set to true if that element is true in either or both of the existing sets.
  • intersection: Takes two CustomSet objects as parameters and returns the intersection of both sets as a CustomSet object. An element of the new set is set to true if that element is true in both of the existing sets.

Write a tester class which asks the user to enter numbers for two different sets and then print out the results of calling union and intersection on both sets. Also demonstrate that insertElement and deleteElement work.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.