CSC1110 Exercise 3

Complete the following program

The program below is intended to count the number of vowels in a given String, but is incomplete. Your job is to:

  1. Complete the "helper" methods that print out the results and check if a character is a vowel
  2. In the main method, write a for loop to iterate through the String and count how many vowels it contains
  3. Repeat Step 2, but this time using a while loop
  4. Repeat Step 2, but this time using a do-while loop
/*
 * Course: CS1110
 * Loop Exercise
 * Fall 2023
 */

import java.util.Scanner;

/**
 * This class will count the number of vowels (a, e, i, o, u)
 * in a given word and display the result. It will do this
 * three times, using a different type of loop each time
 */
public class Exercise3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        boolean done = false;
        do {
            System.out.print("Enter a word of at least 3 letters or 'q' to quit: ");
            String word = in.nextLine();
            if(word.equalsIgnoreCase("q")) {
                done = true;
            }
            if(word.length() >= 3) {
                int vowels = 0;
                // TODO: for loop
  
                // TODO: while loop

                // TODO: do-while loop

            }
        } while(!done);
        System.out.println("Exiting...");
    }

    private static void report(String word, int vowels) {
        // TODO: print out the results like this -> for the word Penguin, "Penguin contains 3 vowels."
    }

    private static boolean isVowel(char c) {
        // TODO: return true if the character is an a, e, i, o, or u
    }
}

Submission Instructions:

Submit Exercise3.java to Canvas.