Advertisement
Guest User

AP CS Vowel thingy

a guest
Feb 5th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. DRIVER:
  2.  
  3. public class VowelDriver {
  4.  
  5. String processLine;
  6.  
  7. public static void main (String[] args){
  8. int lowercase;
  9. int uppercase;
  10. int total;
  11.  
  12. VowelCounter count = new VowelCounter() {
  13.  
  14. };
  15.  
  16. do
  17. {
  18. count.processLine(count.requestInput());
  19. count.printSummary();
  20. }
  21. while (!(enteredSentence = input.nextLine()).equals(""));
  22.  
  23. }
  24. }
  25.  
  26. import java.util.Scanner;
  27.  
  28. //Left index determines row, right index determines column
  29.  
  30. public class VowelCounter {
  31. Integer[][] count = new Integer[2][5];
  32.  
  33. Scanner input = new Scanner(System.in);
  34.  
  35. int aLowerCase = 0;
  36. int eLowerCase = 0;
  37. int iLowerCase = 0;
  38. int oLowerCase = 0;
  39. int uLowerCase = 0;
  40.  
  41. int aUpperCase = 0;
  42. int eUpperCase = 0;
  43. int iUpperCase = 0;
  44. int oUpperCase = 0;
  45. int uUpperCase = 0;
  46.  
  47. int aTotal = 0;
  48. int eTotal = 0;
  49. int iTotal = 0;
  50. int oTotal = 0;
  51. int uTotal = 0;
  52.  
  53. //Issues:
  54.  
  55. //1. I'm getting an error that says "The type of the expression must be an array type
  56. //but it resolved to int". I've added arrows pointing to the lines that have this error.
  57.  
  58. //2. I want to print the final results as an array. Not sure how to set that up.
  59.  
  60. public String requestInput() {
  61. System.out.println("Please type a sentence down below (Press enter by itself to quit)");
  62. return input.nextLine();
  63. }
  64.  
  65. public String printSummary() {
  66. System.out.println(count);
  67. }
  68.  
  69. public String processLine(String enteredSentence) {
  70. for (int count = 0; count < enteredSentence.length(); count++)
  71. {
  72. char check;
  73. check = enteredSentence.charAt(count);
  74. if (check == 'a'){
  75. if (Character.isUpperCase(check)) {
  76. count[2][1]++; //<---
  77. }
  78. if (Character.isLowerCase(check)) {
  79. count[1][1]++; //<---
  80. }
  81. }
  82. if (check == 'e'){
  83. if (Character.isUpperCase(check)) {
  84. count[2][2]++; //<---
  85. }
  86. if (Character.isLowerCase(check)) {
  87. count[1][2]++; //<---
  88. }
  89. }
  90.  
  91. if (check == 'i'){
  92. if (Character.isUpperCase(check)) {
  93. count[2][3]++; //<---
  94. }
  95. if (Character.isLowerCase(check)) {
  96. count[1][3]++; //<---
  97. }
  98. }
  99.  
  100. if (check == 'o'){
  101. if (Character.isUpperCase(check)) {
  102. count[2][4]++; //<---
  103. }
  104. if (Character.isLowerCase(check)) {
  105. count[1][4]++; //<---
  106. }
  107. }
  108.  
  109. if (check == 'u'){
  110. if (Character.isUpperCase(check)) {
  111. count[2][5]++; //<---
  112. }
  113. if (Character.isLowerCase(check)) {
  114. count[1][5]++; //<---
  115. }
  116.  
  117. aTotal = (aUpperCase + aLowerCase);
  118. eTotal = (eUpperCase + eLowerCase);
  119. iTotal = (iUpperCase + iLowerCase);
  120. oTotal = (oUpperCase + oLowerCase);
  121. uTotal = (uUpperCase + uLowerCase);
  122. }
  123. }
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement