write a variety of methods and call each method you write in the main method. Wr
ID: 3850846 • Letter: W
Question
write a variety of methods and call each method you write in the main method. Write as many methods as you like. See the point value for each method and “choose” your grade accordingly. Coding the main method properly to test all your chosen methods is required. It must be possible to test all the methods you have coded by running your program only once. 1. Write a method that takes no parameters and returns no value called printMenu. It displays the menu choices for the other methods you have chosen to implement. You will call it in the main method inside a while or do while loop. One of the menu choices will be to exit the program. The method header will look like this: public static void printMenu() The call will look like this: printMenu(); 2. Write a method that takes one parameter: an integer value and returns true if the number is even, false if the number is odd. The method header will look like this: public static Boolean isEven( int nbr ) The call will look like this: if ( isEven(number) ) { //output a message that the number is even else //output a message that the number is odd 3. Write a method that takes one parameter: the radius of a circle and returns the area of the circle. Use Math.PI in your calculation. The method header will look like this: public static double findArea( double radius ) The call will look like this: double area = findArea(num); 4. Write a method that determines if a 5 digit integer is a palindrome (a number that is the same reading it “forwards” and “backwards”. Some English palindromes are “able was I ere I saw Elba” or “Madam, I’m Adam”. You do not have to do any error checking in your main program to guarantee the user gives you a 5 digit number. The method header will look like this: public static boolean isPalindrome( int value ) The call will look like this: if ( isPalindrome(inputValue)) //output a message the number is a palindrome else //output a message the number is not a palindrome 5. Write a method that takes two integer parameters and determines if the second is a multiple of the first parameter. The method header will look like this: public static boolean isMultiple( int a, int b) A call to isMultiple would look like this: if ( isMultiple( little, big ) ) //output a message the second number is a multiple of the first number else //output a message the second number is not a multiple of the first number 6. Write a method that prints all the factors of a number. The method header will look like this: Public static void printFactors( int number ) A call to printFactors would look like this: printFactors(aNumber); 7. Write a recursive method that given a positive integer value i, returns the ith Fibonacci number. Hint: the tests must be in the order listed. The call would look like: answer = fib(4); The method header would look like: public static int fib(int n){ The recursive definition for the Fibonacci sequence is: a. Fibonacci(0) = 0 b. Fibonacci(1) = 1 c. Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2) 8. Write a method to calculate if a given 1 to 3 digit number is an Armstrong number An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371. Method call: if ( isArmstrong(nbr)) System.out.println(“This is an Armstrong number”); else System.out.println(“This is not an Armstrong number”); Method header: public static Boolean isArmstrong(int n){
Explanation / Answer
//output:-->
Select your choice :1. Find Even
2. Calculate area of circle
3. Find number is palindrom or not
4. Find muliplity of a number
5. Print factors of a number
6. Find Fibonacci number
7. Find armstrong number
8. Exit
Enter your choice
1
Enter number to find even or odd
1
Number is odd
Do you want to continue Y/N
y
Select your choice :1. Find Even
2. Calculate area of circle
3. Find number is palindrom or not
4. Find muliplity of a number
5. Print factors of a number
6. Find Fibonacci number
7. Find armstrong number
8. Exit
Enter your choice
3
Enter the five digit number -->
121
Number is palindrom
Do you want to continue Y/N
y
Select your choice :1. Find Even
2. Calculate area of circle
3. Find number is palindrom or not
4. Find muliplity of a number
5. Print factors of a number
6. Find Fibonacci number
7. Find armstrong number
8. Exit
Enter your choice
3
Enter the five digit number -->
123
Number is not palindrom
Do you want to continue Y/N
y
Select your choice :1. Find Even
2. Calculate area of circle
3. Find number is palindrom or not
4. Find muliplity of a number
5. Print factors of a number
6. Find Fibonacci number
7. Find armstrong number
8. Exit
Enter your choice
4
Enter the value of a and b
4
8
The second number is a multiple of the first number
Do you want to continue Y/N
y
Select your choice :1. Find Even
2. Calculate area of circle
3. Find number is palindrom or not
4. Find muliplity of a number
5. Print factors of a number
6. Find Fibonacci number
7. Find armstrong number
8. Exit
Enter your choice
4
Enter the value of a and b
2
3
The second number is not a multiple of the first number
Do you want to continue Y/N
y
Select your choice :1. Find Even
2. Calculate area of circle
3. Find number is palindrom or not
4. Find muliplity of a number
5. Print factors of a number
6. Find Fibonacci number
7. Find armstrong number
8. Exit
Enter your choice
5
Enter the number to find its factor
10
1
10
2
5
Do you want to continue Y/N
y
Select your choice :1. Find Even
2. Calculate area of circle
3. Find number is palindrom or not
4. Find muliplity of a number
5. Print factors of a number
6. Find Fibonacci number
7. Find armstrong number
8. Exit
Enter your choice
7
Enter the number to check armstrong number or not
153
Number is armstrong number
Do you want to continue Y/N
y
Select your choice :1. Find Even
2. Calculate area of circle
3. Find number is palindrom or not
4. Find muliplity of a number
5. Print factors of a number
6. Find Fibonacci number
7. Find armstrong number
8. Exit
Enter your choice
7
Enter the number to check armstrong number or not
234
Number is not armstrong number
Do you want to continue Y/N
n
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.