1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
yarga [219]
3 years ago
10

Write the Number class that can be used to test if the number is odd, even, and perfect. A perfect number is any number that is

equal to the sum of its divisors. Write the NumberAnalyzer class that has an ArrayList of Number to determine how many numbers in the list are odd, even, and perfect.
Computers and Technology
1 answer:
egoroff_w [7]3 years ago
6 0

Answer:

Explanation:

The following code is written in Python. It creates a class that takes in one ArrayList parameter and loops through it and calls two functions that check if the numbers are Perfect, Odd, or Even. Then it goes counting each and printing the final results to the screen.

class NumberAnalyzer:

   def __init__(self, myArray):

       perfect = 0

       odd = 0

       even = 0

       for element in myArray:

           if self.isPerfect(element) == True:

               perfect += 1

           else:

               if self.isEven(element) == True:

                   even += 1

               else:

                   odd += 1

       print("# of Perfect elements: " + str(perfect))

       print("# of Even elements: " + str(even))

       print("# of Odd elements: " + str(odd))

   def isPerfect(self, number):

       sum = 1

       i = 2

       while i * i <= number:

           if number % i == 0:

               sum = sum + i + number / i

           i += 1

       if number == sum:

           return True

       else:

           return False

   def isEven(self, number):

       if (number % 2) == 0:

           return True

       else:

           return False

You might be interested in
How can you create an illusion of spatial depth in a two-dimensional design?
astraxan [27]

Answer:

Using three or more vanishing points within a work to create the illusion of space on a two-dimensional surface.

Explanation:

6 0
3 years ago
You want to deploy a software package that's available to all users in the domain if they want to use it, but you don't want the
gulaghasi [49]

Answer:

Access installation through shared drive

Explanation:

4 0
3 years ago
Electricity fact topic
gregori [183]
''for kids'' i think thats what that mean
5 0
4 years ago
Read 2 more answers
Write a brief description of what the local authorities are recommending in the news people should do to protect themselves from
lana [24]
The brief description of the local author asbestos is Hope and that's what it would too with a heart and another heart which equals 100 which equals yes
3 0
3 years ago
Lawanda starts a new job today at a company that delivers thousands of packages each day. Identify three ways in which Lawanda's
jek_recluse [69]

Answer:

use your own opinion

Explanation:

7 0
3 years ago
Other questions:
  • Where is the insert function button found in microsoft excel?
    11·1 answer
  • What would happen if a pc that contains a power supply that does not automatically adjust for input voltage is set to 230 volts
    13·1 answer
  • In cell R9, enter a formula using the AVERAGEIF function to determine the average number of years of experience for lifeguards.
    12·1 answer
  • The benefits of flextime include:
    11·2 answers
  • ¿Que es la energía? (una sola respuesta es la correcta)
    11·1 answer
  • Consider the following method, which is intended to return the index of the first negative integer in a given array of integers.
    14·1 answer
  • Write a static method reOrder56(int[] nums) that return an array that contains exactly the same numbers as the given array, but
    10·1 answer
  • What is text formatting?​
    5·2 answers
  • 20.
    8·1 answer
  • Area Triangolo Rettangolo in c++
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!