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

Lab7. java. Your Name t Determines and prints how many of each vowel appear in e

ID: 3861710 • Letter: L

Question

Lab7. java. Your Name t Determines and prints how many of each vowel appear in each string. Then it draws starts in the specific format import java .util scanner: public class Lab7 public static void main(String[] args) //PART 1 //Determine and print how many of each vowels appear in a string Scanner scan new scanner(system. in); System.out.println Enter a string or type V"quitl" to exit 1"): tLine String line scan.nex //convert all characters to lower cases line line .toLowerCase 1 while (line. equals("quit") false) //counter is used to count the number of vowels 01 int counter //stepl-ai complete the following for loop so that to the end //the index i from the beginning of the string //Hint use length method for (int i the following if statement to check if //character is one of vowels are,i,o, or u //Hint I use charAt method if (line.charAts (i) counter system out.println("The string line contains counter vowel (s) system. out.println ("Enter a string or type quit to exit

Explanation / Answer

/*
* Lab 7
*
*/

import java.util.Scanner;

public class JavaApplication1 {

    public static void main(String[] args) {

//part-1
        Scanner s = new Scanner(System.in);
        System.out.println("Enter string or type "quit" to exit:");
        String line = s.nextLine();
//convert all characters to lower case
        line = line.toLowerCase();
        while (line.equals("quit") == false) {
            //counter is used to count the number of vowels
            int counter = 0;
//step1-a here index i goes from the beginning of the string to end
            for (int i = 0; i < line.length(); i++) {
                //step 1-b character is one of the vowels a,e,i,o or u
                if (line.charAt(i) == 'a' || line.charAt(i) == 'e' || line.charAt(i) == 'i' || line.charAt(i) == 'o' || line.charAt(i) == 'u') {
                    counter++;
                }
            }
            System.out.println("The string " + line + " contains " + counter + " vowel(s)");
            System.out.println(" Enter string or type "quit" to exit:");
            line = s.nextLine();

            line = line.toLowerCase();
        }

//part2
        System.out.println(" The following is PART 2 ");

        for (int i = 1; i <= 5; i++) {
            //step2-a the following loop to draw spaces
            for (int k = 1; k <= (5 - i); k++) {
                System.out.print(" ");
            }
            // step2-b to draw stars
            for (int j = 1; j <= i; j++) {
                System.out.print("*");
            }

            System.out.println();
        }

    }
}