DOC PREVIEW
WVU CS 110 - Sample Methods to Write

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Sample methods to write:Sample methods to write:1. Write a value-returning method, isVowel, that returns the value “true” if a given character is a vowel, and otherwise returns “false”. public static boolean isVowel ( char letter) { char x; String str = String.valueOf(letter);// change the letter to uppercase x = Character.toUpperCase(letter); switch (x) { case 'A': case 'E': case 'I': case 'O': case 'U': return true; default: return false; }} // end isVowelAlternately in the method you can use an if statement instead of the case public static boolean isVowel ( char letter) { char x; String str = String.valueOf(letter);// change the letter to uppercase x = Character.toUpperCase(letter);if ((letter == ‘A’) || ( letter == ‘E’) || (letter == ‘I’) || (letter == ‘O’) || (letter == ‘U’))return true;else return false;} // end isVowel2. Write a program that prompts the user to input a sequence of characters (as a string) and outputs the number of vowels. (Hint: Your program should usethe method in the previous problem, use a loop, and methods from class STring) 3. Consider the following program outline:public class Mystery { public static void main(String[] args) {int num;double dec;// some statements go here}// end of mainpublic static int one(int x, int y) {}// end of onepublic static double two( int x, double a) {int first;double z, } // end of two}// end of class mysterya. Write the definition of method one so that it returns the sum of x and y if x is greater than y; other wise it should return x minus 2 times y.b. write the definition of method two as follows:i. read a number and store it in z.ii. update the value of z by adding the value of a to itiii. assign the variable first the value returned by method one withthe parameters 6 & 8iv. update the value of first by adding the value of x to its previousvaluev. if the value of z is more than twice the value of first, return z otherwise return 2 times first minus z.4. Write a method, “reverseDigit” that takes an integer as a parameter, and returns the number with its digits reversed. For example the value of “reverseDigit(123) is 321. Also, write a main program to test your


View Full Document

WVU CS 110 - Sample Methods to Write

Download Sample Methods to Write
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Sample Methods to Write and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Sample Methods to Write 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?