Question: Write java code to create 3 methods that accomplish the below concepts according to simple number theory. 1. Create a file PositiveInteger.java that houses a

Write java code to create 3 methods that accomplish the below concepts according to simple number theory.

1. Create a file PositiveInteger.java that houses a class called PositiveInteger

2. This class should have one single instance variable called num

This is what I have for the constructor: public PositiveInteger(int number) { num = number; }

The three methods should start with the italicized sections shown below to accomplish the corresponding tasks:

1. public boolean isPerfect () - A number is said to be perfect if it is equal to the sum of all its factors (for obvious reasons the list of factors being considered does not include the number itself). 6 = 3 + 2 + 1, hence 6 is perfect.

2. public boolean isAbundant() - A number is considered to be abundant if the sum of its factors (aside from the number) is greater than the number itself. For example, 12 is abundant since 1+2+3+4+6 = 16 > 12. However, a number like 15, where the sum of the factors is 1 + 3 + 5 = 9, is not abundant

3. public boolean isNarcissistic() - A positive integer is called a narcissistic number if it is equal to the sum of its own digits each raised to the power of the number of digits. For example, 153 is narcissistic because 13 + 53 + 33 = 1 + 125 + 27 = 153.

Any java code help would be appreciated!

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!