Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 - Create a class called NumberAnalyzer and implement the following methods in

ID: 3604410 • Letter: 1

Question

1 - Create a class called NumberAnalyzer and implement the following methods in the class. a) oddOrEven : This method will take an integer as an argument and will return “Odd” or “Even” as a String depending on the number being odd or even. b) isItPrime : This method will take an integer as an argument and will return true or false as boolean depending on the number being a prime number or not. c) isItPerfect : This method will take an integer as an argument and will return true or false as boolean depending on the number being a perfect number or not. ( Look at the previous assignment for the definition of perfect numbers.) d ) fibonacci : This method will take an integer and return the Nth number in the fibonacci sequence as an integer. - The Fibonacci sequence : 1, 1, 2, 3, 5, 8, 13, 21, 34 … starting with 1, 1 each number in the sequence is found by adding up the two numbers before it. So, the 1st fibonacci number is 1, the 2nd fibonacci number is 1 the 3rd fibonacci number is 2 . . . the 6th fibonacci number is 8 e)isNthFibonacciM: This method takes two integer arguments N and M then checks if the Nh Fibonacci number is M and returns true or false as boolean accordingly. (Hint: You can use the previous method.) N: 1 , M: 1 true N: 2 , M: 1 true N: 6 , M: 8 true N: 5 , M: 7 false N: 6 , M: 25 false 2- create the run method and do the following in it using the previous methods • ask for the number N • in an infinite loop Take the question number from the user and depending on the question number do the following. 1. Print “Odd” if the number is odd and “Even” if the number is even. 2. Print “Yes” if the number is prime and “No” if it is not 3. Print “Yes” if the number is perfect and “No” if it is not 4. Print the Nh Fibonacci number. 5. Ask the user for the number M and print “Yes” if the Nth fibonacci number is M, “No” otherwise. 6. 6 - quit

I want it in java language

Explanation / Answer

Below is the Java Program.

import java.io.Console;

public class NumberAnalyzer { // Class NumberAnalyzer

public static String oddOrEven(int x) // Method to check if the number is even or odd

{

int number = x;

String result;

if(number%2 == 0)

result = "Even";

else

result = "Odd";

return result;

}

public static boolean isItPrime(int number) // Method to check if the number is prime or not

{

for(int i=2; i<=number/2; i++){

if(number % i == 0){

return false;

}

}

return true;

}

public static boolean isItPerfect(int number) // Method to check if the number is perfect or not

{

int Sum = 0;

for(int i = 1 ; i < number ; i++) {

if(number % i == 0) {

Sum = Sum + i;

}

}

if (Sum != number)

{

return false;

}

else

return true;

}

  

private static int fibonacci(int n) { // Method to print nth fibonacci number

if (n == 1)

return 0;

if (n == 2)

return 1;

return fibonacci(n - 1) + fibonacci(n - 2);

}

  

public static void main(String args[]) {

int num;

Console console = System.console();

System.out.println("Enter any integer: ");

num = Integer.parseInt(console.readLine());

System.out.println("Select Option:");

System.out.println("1. Ques- Display Even/Odd");

System.out.println("2. Ques- Prime");

System.out.println("3. Ques- Perfect");

System.out.println("4. Ques- fibonacci");

System.out.println("6. Quit");

int Selection = Integer.parseInt(console.readLine());

switch( Selection ) { // Case statement to execute the appropriate method selected by the user.

case 1:

String a = oddOrEven(num);

System.out.println(a);

break;

case 2:

boolean b = isItPrime(num);

System.out.println(b);

break;

case 3:

boolean d = isItPerfect(num);

System.out.println(d);

break;

case 4:

int c = fibonacci(num);

System.out.println(c);

break;

  

case 6:

return;

default:

System.out.println("Unknown choice");

break;

}

}

}