Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Show a Java class called ArrayDirection? You must get the size of the array from the user and create an integer array of that size.

Show a Java class called ArrayDirection?


You must get the size of the array from the user and create an integer array of that size.

Note: Your solution must not use ArrayList. Submissions with ArraysLists will not be accepted

Limit the array to a size between 5 and 15

The user will then provide values to be stored in an integer array. 

show  a method called checkDirection that checks if the array has an increasing pattern or a decreasing pattern. 

Return 1 if the array is increasing

or

Return -1 if the array is decreasing

If it's neither increasing or decreasing return 0.

If the return value from checkDirection is 1 or -1

  • Display an appropriate message about the pattern
  • display the difference between the first and last element of the array

If the return value is 0

  • display a message that the array has a random pattern

You can write method/methods in addition to the one stated above to better organize your class

Example 1:

array: -2, 12, 19, 24, 37

Return value 1.

This is a increasing pattern array 

Difference: -35

Example 2:

array: 76, 59, 43, 29, -12

Return value -1.

This is a decreasing pattern array 

Difference: 71

Example 3:

array: 17, -17, 37, 2, 19, -97

Return value 0.

Array has a random pattern

 


QUESTION:

How a Java class called CyclicSequence:

The solution to this question must NOT use arrays or ArrayLists

The class should output numbers whose sum of proper divisors form a cyclic sequence that begins and ends with the same number.

Include a method called generateSequence that takes a number as a parameter and outputs the other numbers in the sequence. You can use any number in the list shown below as the starting point to generate the rest of the values in that cyclic sequence.

You can also include a method called sumProperDivisors to calculate the sum of all the number's proper divisors and call it from the generateSequence method.

The output must print the numbers int the sequence (after each value is calculated) separated by 2 spaces.

Use the following to test you logic:

  • The numbers that result in a 2-cycle sequence:  220, 284
  • The numbers result in a 4-cycle sequence: 1547860, 1727636, 1305184, 1264460
  • The numbers result in a 5-cycle sequence: 12496, 14288, 15472, 14536, 14264
  • The only known numbers that result in a 28-cycle sequence are: 14316, 19116, 31704, 47616, 83328,
    177792, 295488, 629072, 589786, 294896, 358336, 418904, 366556, 274924, 275444, 243760, 376736,
    381028, 285778, 152990, 122410, 97946, 48976, 45946, 22976, 22744, 19916, 17716.
  • All other numbers will result in an infinite loop. Your logic will only need to work for the numbers listed above.

Example:

Start with  

1547860: the sum of all its proper divisors is 1727636. 

1727636: the sum of all its proper divisors is 1305184

1305184: the sum of all its proper divisors is 1264460

1264460: the sum of all its proper divisors is 1547860

Step by Step Solution

3.38 Rating (164 Votes )

There are 3 Steps involved in it

Step: 1

Heres a Java class called ArrayDirection that implements the functionality you described import javautilScanner public class ArrayDirection private in... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

More Books

Students also viewed these Programming questions

Question

write a java code that would display a given charater 1 0 times.

Answered: 1 week ago