Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DRIVER:
- public class VowelDriver {
- String processLine;
- public static void main (String[] args){
- int lowercase;
- int uppercase;
- int total;
- VowelCounter count = new VowelCounter() {
- };
- do
- {
- count.processLine(count.requestInput());
- count.printSummary();
- }
- while (!(enteredSentence = input.nextLine()).equals(""));
- }
- }
- import java.util.Scanner;
- //Left index determines row, right index determines column
- public class VowelCounter {
- Integer[][] count = new Integer[2][5];
- Scanner input = new Scanner(System.in);
- int aLowerCase = 0;
- int eLowerCase = 0;
- int iLowerCase = 0;
- int oLowerCase = 0;
- int uLowerCase = 0;
- int aUpperCase = 0;
- int eUpperCase = 0;
- int iUpperCase = 0;
- int oUpperCase = 0;
- int uUpperCase = 0;
- int aTotal = 0;
- int eTotal = 0;
- int iTotal = 0;
- int oTotal = 0;
- int uTotal = 0;
- //Issues:
- //1. I'm getting an error that says "The type of the expression must be an array type
- //but it resolved to int". I've added arrows pointing to the lines that have this error.
- //2. I want to print the final results as an array. Not sure how to set that up.
- public String requestInput() {
- System.out.println("Please type a sentence down below (Press enter by itself to quit)");
- return input.nextLine();
- }
- public String printSummary() {
- System.out.println(count);
- }
- public String processLine(String enteredSentence) {
- for (int count = 0; count < enteredSentence.length(); count++)
- {
- char check;
- check = enteredSentence.charAt(count);
- if (check == 'a'){
- if (Character.isUpperCase(check)) {
- count[2][1]++; //<---
- }
- if (Character.isLowerCase(check)) {
- count[1][1]++; //<---
- }
- }
- if (check == 'e'){
- if (Character.isUpperCase(check)) {
- count[2][2]++; //<---
- }
- if (Character.isLowerCase(check)) {
- count[1][2]++; //<---
- }
- }
- if (check == 'i'){
- if (Character.isUpperCase(check)) {
- count[2][3]++; //<---
- }
- if (Character.isLowerCase(check)) {
- count[1][3]++; //<---
- }
- }
- if (check == 'o'){
- if (Character.isUpperCase(check)) {
- count[2][4]++; //<---
- }
- if (Character.isLowerCase(check)) {
- count[1][4]++; //<---
- }
- }
- if (check == 'u'){
- if (Character.isUpperCase(check)) {
- count[2][5]++; //<---
- }
- if (Character.isLowerCase(check)) {
- count[1][5]++; //<---
- }
- aTotal = (aUpperCase + aLowerCase);
- eTotal = (eUpperCase + eLowerCase);
- iTotal = (iUpperCase + iLowerCase);
- oTotal = (oUpperCase + oLowerCase);
- uTotal = (uUpperCase + uLowerCase);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement