For this assignment your job is to create two class


For this assignment your job is to create two class application that examines the concept of a numerical palindrome.

A numerical palindrome is a non-negative whole number that is the same forwards and backwards, e.g. 2332, 12321, etc. Here's the catch: suppose you do the following. Start with any positive whole number. If it's a palindrome, you're done; if it isn't, reverse the number, add the reversal to the original value, and test this new result. It it's a palindrome, you're done; otherwise repeat: reverse, add, and test again, and so forth. This process almost always leads, very quickly, to a palindrome

A note on how to structure your solution. A NumPal object MUST have four attributes: the current number, its reverse, the String version of the current number, and String version of the reverse of the current number. The numbers should be of type long, not int.

Here's a detailed account of what you need to do for this assignment. You must develop a complete class, NumPal, which works properly with the driver class above, and in that way allows you to turn integer inputs into numerical palindromes. Your submitted code must implement the following methods:

  • Implement the NumPal constructor. Notice that it takes a String argument, NOT an integer argument.
  • Implement the pal() method, which determines if a NumPal object represents a palindrome.
  • Implement the toString() method, which returns a String of the proper form (an example of toString output is given in the first sample run above for 552).
  • Implement the next() method, which - given a NumPal object - returns the next NumPal object according to the "reverse and add" method described above.
  • Implement a reverseString method, which takes a String, say s, as an argument, and returns the reverse of s. Thus reverseString("aabcd") should return the String dcbaa. The code you submit should use this method in an essential way. This method appears as an exercise at the end of Chapter 5 in the textbook.

One final comment. There are clearly many ways to structure a solution to this problem. We've chosen one, and you need to adhere to the pattern we've spelled out above. You may not alter the driver class in any way.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: For this assignment your job is to create two class
Reference No:- TGS02344244

Now Priced at $25 (50% Discount)

Recommended (92%)

Rated (4.4/5)