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

Write a java class with the following two user-defined methods: Write a value-re

ID: 3768871 • Letter: W

Question

Write a java class with the following two user-defined methods:

Write a value-returning method named isVowel, that returns the boolean value true if a given character is a vowel, and otherwise returns the boolean value false.

Write a value-returning method named reverseDigit, that takes an int (integer) as a parameter and returns the number with its digits reversed as an int. For example, calling reverseDigit(12345) returns the int value of 54321.

Write the main method for this class to test the above two user-defined methods.

Some things to think about:

What is the data type of the parameter passed to the isVowel method?

The isVowel method needs some conditional logic to make this decision, first pass at implementing this might be to write to test for an explicit vowel.

For the reverseDigit method, there's a couple of different ways you might want to think about doing this. One might be to convert the passed int value to a String first and then build the reverse of that String which can then be converted to an int. Look at Integer and String class API. Another means to do this could be using a purely mathematical approach.

Explanation / Answer

import java.util.Scanner; public class In_Class_Module_8 { public static void main(String[] args){ } public static boolean isVowel(String word){ Scanner keyboard = new Scanner(System.in); char vowels; System.out.print("Enter a letter: "); vowels = keyboard.findWithinHorizon(".", 0).charAt(0); if (word.length()!=1) return false; char vowels=word.toLowerCase().charAt(0); if(vowels== 'a'|| vowels =='e' || vowels=='i'|| vowels == 'o' || vowels == 'u'){ return true; } return false; } } public static void reverseInteger() { Scanner keyboard = new Scanner( System.in ); System.out.print( "Enter an integer (-1 to exit): " ); int number = keyboard.nextInt(); while ( number != -1 ) { System.out.printf( "%d reversed is %d ", number, reverseDigits( number ) ); System.out.print( "Enter an integer (-1 to exit): " ); number = keyboard.nextInt(); } } public int reverseDigits( int number ) { int reverseNumber = 0; int placeValue; while ( number > 0 ) { placeValue = number % 10; number = number / 10; reverseNumber = reverseNumber * 10 + placeValue; } return reverseNumber; } } public class Module8Test { public static void main( String args[] ) { Reverse application = new Reverse(); application.reverseInteger(); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote