Question: Q.1. (50 pts.) Consider the number given below. Let us name such numbers as magic numbers. 2646798 = 2 +62 +48 +64 + 7 +9+87

 Q.1. (50 pts.) Consider the number given below. Let us name

Q.1. (50 pts.) Consider the number given below. Let us name such numbers as magic numbers. 2646798 = 2 +62 +48 +64 + 7 +9+87 We want to implement a MagicNumber class that is derived from the Number class. For this purpose, first implement a Number class having an instance variable narned as length" that is an int and, "digits" that is an array of ints. The class should have 2 constructors. The default constructor should call another constructor with 5 as the actual parameter. In that constructor, the function parameter should be used to initialize the length value and digits as an array of that length. The array elements must be initialized as 1, 2, 3, ... , length. The third constructor must have an array parameter which is used to initialize digits array and length. The method "returnValueFromDigits()" should compute and return the int value corresponding to the digits in "digits" array. The method returnSumFromDigits() should return the sum of powers of the digits. For example, given 2, 1 and 3, the first method should return 213 and the second should return 30 (2 + 1*1+ 3*3*3 = 30). Derive a MagicNumber class as an extension of Number class. This class should have a boolean method named as is Magic that uses the methods described above in Number class to return true if the number is magic. Also you should include an appropriate constructor. An exemplar use of this class is as follows: MagicNumber num=new MagicNumber(new int (213): System.out.println(num.isMagic()); Implement the classes Number and MagicNumber

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!