Question

Hello! I have a Java homework question that I could really use some help with. I...

Hello! I have a Java homework question that I could really use some help with. I keep getting an error, but I don't know what is wrong with my code. Thanks so much in advance!

The problem is:

6.9: VowelAnalyst Design and implement an application that reads a string from the user, then determines and prints how many of each lowercase vowel (a, e, i, o, and u) appear in the entire string. Have a separate counter for each vowel. Also count and print the number of nonvowel characters. SPECIFICATION OF PROMPTS, LABELS AND OUTPUT: Your code should use the prompt "enter string: ". After the input is read, there are six lines of output, each starting with a different label: "a: ", "e: ", "i: ", "o: ", "u: ", "other: " in that order. After each label is the required count. For example: if "aardvark heebie jeebies" were read in, the output would be: a: 3 e: 6 i: 2 o: 0 u: 0 other: 12 SPECIFICATION OF NAMES: Your application class should be called VowelAnalyst.

My code is:

import java.util.Scanner;
public class VowelAnalyst
{
   public static void main(String[] args)
   {
       String str;
       char ch;
       int aCount;
       int eCount;
       int iCount;
       int oCount;
       int uCount;
       int otherCount;
       Scanner input=new Scanner(System.in);
       System.out.print("enter string: ");
       str=input.next();
       aCount=0;
       eCount=0;
       iCount=0;
       oCount=0;
       uCount=0;
       otherCount=0;
       for(int pos=0;pos<str.length();pos++)
       {
           ch=str.charAt(pos);
           if(ch=='a')
               aCount++;
           else if(ch=='e')
               eCount++;
               else if(ch=='i')
               iCount++;
               else if(ch=='o')
               oCount++;
               else if(ch=='u')
               uCount++;
               else if(ch!='a'&&ch!='e'&&ch!='i'&&ch!='o'&&ch!='u')
               otherCount++;
               }
       System.out.println("a: "+aCount);
       System.out.println("e: "+eCount);
       System.out.println("i: "+iCount);
       System.out.println("o: "+oCount);
       System.out.println("u: "+uCount);
       System.out.println("other: "+otherCount);
   }
}

The error is:

CODELAB ANALYSIS: LOGICAL ERROR(S)



Problems Detected:
          The value of _stdout is incorrect.

TEST CASE TABLE


Testing with these values... results in
keyboard
display
#1
_stdin: 'between one day and the next'
_stdout: 'enter string: a: 0
The value of _stdout is incorrect.
#2
_stdin: 'hello'
_stdout: 'enter string: a: 0
#3
_stdin: 'abcdefghijklmnopqrstuvwxyz'
_stdout: 'enter string: a: 1
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:-

CODE:-

/******************************************************************************

Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
String str;
char ch;
int aCount;
int eCount;
int iCount;
int oCount;
int uCount;
int otherCount;
Scanner input=new Scanner(System.in);
System.out.print("enter string: ");
str=input.nextLine();
aCount=0;
eCount=0;
iCount=0;
oCount=0;
uCount=0;
otherCount=0;
for(int pos=0;pos<str.length();pos++)
{
ch=str.charAt(pos);
if(ch=='a')
aCount++;
else if(ch=='e')
eCount++;
else if(ch=='i')
iCount++;
else if(ch=='o')
oCount++;
else if(ch=='u')
uCount++;
else if(ch!='a'&&ch!='e'&&ch!='i'&&ch!='o'&&ch!='u')
otherCount++;
}
System.out.println("a: "+aCount);
System.out.println("e: "+eCount);
System.out.println("i: "+iCount);
System.out.println("o: "+oCount);
System.out.println("u: "+uCount);
System.out.println("other: "+otherCount);
}
}

NOTE:- Change str=input.nextLine(); because next() will only input the first word not the whole string, and nextLine() will input whole line.

OUTPUT SCREENSHOT:-

public static void main(String[] args) { 12 13- 14 15 16 17 18 19 20 21 22 String str; char ch; int a Count; int eCount; int

Add a comment
Know the answer?
Add Answer to:
Hello! I have a Java homework question that I could really use some help with. I...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello, I have a assignment where the user inputs a word and the out will then...

    Hello, I have a assignment where the user inputs a word and the out will then tell the user how many of the five vowels are in the word so for example if I typed the word hello, it would output {0 1 0 0 0 } since there is only one vowel and that is e which is in the second row, I have most of it done, but I can't seem to figure out how to get the...

  • Here is my code to put a quote down, flip it, and reverse it. I do...

    Here is my code to put a quote down, flip it, and reverse it. I do not have much knowledge on coding. Does my code only use Variables, Console I/O, Java Program Design, Intro to IDEs, If Statements, Selection and Conditional Logic, Strings, Loops, Nesting, and Iteration? If not, could it be fixed to only use them? These are the offical steps of the assignment: - Ask a user to enter a quote - whether it's several sentences or a...

  • Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In...

    Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and cannot figure it out. Thank you. Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and...

  • (a)How many times does the code snippet given below display "Hello"? int x = 1; while...

    (a)How many times does the code snippet given below display "Hello"? int x = 1; while (x != 15) {    System.out.println ("Hello");    x++; } (b)What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 5) {    sum = sum + i;    i++; } System.out.println("The value of sum is " + sum); Quie 2 What is the output of the following snipped code? public class Test {...

  • I am currently doing homework for my java class and i am getting an error in...

    I am currently doing homework for my java class and i am getting an error in my code. import java.util.Scanner; import java.util.Random; public class contact {       public static void main(String[] args) {        Random Rand = new Random();        Scanner sc = new Scanner(System.in);        System.out.println("welcome to the contact application");        System.out.println();               int die1;        int die2;        int Total;               String choice = "y";...

  • in JAVA -- need to use an arraystack for this and can only manipulate smartstring.java aka...

    in JAVA -- need to use an arraystack for this and can only manipulate smartstring.java aka the one that says :               public class SmartString implements SmartStringADT at the beginning //for SmartStringTest.java: import static org.junit.Assert.*; import org.junit.Test; public class SmartStringTest {    //Test insert method    @Test    public void testinsert1() {        SmartString evaluator = new SmartString();        evaluator.insert(0, "Hello");        evaluator.insert(4, ", how are you?");        assertEquals("Hello, how are you?", evaluator.toString());    }   ...

  • I'm having trouble getting my program to output this statement Enter a sentence: Test! There are...

    I'm having trouble getting my program to output this statement Enter a sentence: Test! There are 5 total characters. There are 1 vowel. There are 1 UPPERCASE letters. There are 3 lowercase letters. There are 1 other characters. Here's my code: #include<string.h> #include<stdio.h> #include<stdbool.h> int main() { char str[100]; int i; int vowels=0; int UC; int LC; int Others; int c; printf("Enter a sentence: \n"); gets(s); LC=countLC(&s); UC=countUC(&s); Others=countOthers(&s); printf("There are %d total characters.\n", ; for(i=0; i<strlen(str); i++){ if(isVowel(str[i])) vowels++;...

  • I have the following java-program, that creates a random walk starting at (0,0) and continuing until...

    I have the following java-program, that creates a random walk starting at (0,0) and continuing until x or y is greater than abs(n). First: I get an error, when I try closing the Scanner by inserting "reader.close(); " in line 28. It says "Unreachable code". How can I fix that? Second: Is it possible to create a different colour for the StdDraw.point when it reaches a point on one of the edges "n+1" or "n-1" ? 1 import java.util.*; 3...

  • java a. What is printed by the following code? Explain your answer by showing how you...

    java a. What is printed by the following code? Explain your answer by showing how you computed the values of pos, s1, s2 and 53. String str = "2900 Bedford Ave Brooklyn NY 12230-6843"; int pos = str.indexOf(" ", str.indexOf(" ", 'B') + 1); String si = str.substring(o, pos); System.out.println("pos: + post sl: + sl); pos - str.indexOf("B", pos+1); pos = str.indexOf("B", pos+1); String s2 = str.substring(pos, str. indexOf(" ", pos)): System.out.println("pos: + pos + + s2); String s3 =...

  • Help check why the exception exist do some change but be sure to use the printwriter...

    Help check why the exception exist do some change but be sure to use the printwriter and scanner and make the code more readability Input.txt format like this: Joe sam, thd, 9, 4, 20 import java.io.File; import java.io.PrintWriter; import java.io.IOException; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.Scanner; public class Main1 { private static final Scanner scan = new Scanner(System.in); private static String[] player = new String[622]; private static String DATA = " "; private static int COUNTS = 0; public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT