Vowels in a FishBowl Program in java

Question:

Steffi plans a game to teach her students about vowels . There are 5 students .Steffi places 25 slip of papers in a fishbowl, where each slip contains a word.Each student has to take 5 slips and count the number of vowels in each slip and write it in a paper consecutively.

The Points are given as below

No of VowelsPoints
10
21
33
44
56
More than 58

A student who gets the highest point is considered the winner. When no point is scored by anyone then display “No one has got any points”.

Sample input 1

mango basket ball auspicious kangaroo

precaution misbehavior battery cup screen

parasite hello good come education

invitation squeeze paper ant multiplication

COOPERATION DEMOCRACY CONGRATULATIONS YOU BYE

Sample output 1

1 1 0 8 4

6 6 1 0 1

4 1 1 1 6

6 4 1 0 8

8 3 8 1 0

1 14

2 14

3 13

4 19

5 20

The winner is student 5 with points 20

CODE:

import java.util.*;
public class Main 
{
    public static void main (String[] args) {
        
        char vowels[]={'A', 'E', 'I', 'O', 'U'};
        //String vowels[]={"A", "E", "I", "O", "U"};
        String input[][]=new String[5][5];
        
        Scanner sc=new Scanner(System.in);
        String ip[]=new String[5];
        for(int i=0; i<5;i++)
        {
            
            ip[i]=sc.nextLine();
            
            input[i]=ip[i].split(" ");
        }
        
        
        
        
        int vowel_count[][]=new int[5][5];
        int count=0;
        for(int i=0;i<5;i++)
        {
            for(int j=0 ; j<5;j++)
            {
                for(int k=0; k<5;k++)
                {   
                    char temp=vowels[k];
                    for(int l=0; l<input[i][j].length(); l++)
                    {
                        if(temp==Character.toLowerCase(input[i][j].charAt(l)) || temp==Character.toUpperCase(input[i][j].charAt(l)))
                        {
                            count++;
                        }
                    }
                }
                vowel_count[i][j]=count;
                count=0;
            }
        }
        
        int score[] =new int[5];
        
        for(int i=0;i<5;i++)
        {
            for(int j=0;j<5;j++)
            {
                if(vowel_count[i][j]==1 || vowel_count[i][j]==0)
                {   System.out.print("0\t");
                    score[i]+=0;
                }
                else if(vowel_count[i][j]==2)
                {   System.out.print("1\t");
                    score[i]+=1;
                }
                else if(vowel_count[i][j]==3)
                {   System.out.print("3\t");
                    score[i]+=3;
                }
                else if(vowel_count[i][j]==4)
                {   System.out.print("4\t");
                    score[i]+=4;
                }
                else if(vowel_count[i][j]==5)
                {   System.out.print("6\t");
                    score[i]+=6;
                }
                else
                {   System.out.print("8\t");
                    score[i]+=8;
                }
            }
            System.out.println();
        }
        
        
        int max=0;
        String max_index=new String();
        for(int i=0;i<5;i++)
        {
            System.out.println((i+1)+"\t"+score[i]);
            if(score[i]>max && score[i]!=0)
            {
                max=score[i];
                max_index=max_index+"student "+String.valueOf(i+1)+" ";
            }
            else if(score[i]==max && score[i]!=0)
            {
                max_index=max_index+"student "+String.valueOf(i+1)+" ";
            }
            
        }
        
        if(max!=0)
        {   
            System.out.println("The winner is "+max_index+"with points "+max);
        }
        else
        {
            System.out.println("No one has got any points");
        }
    }
}
Next:
  1. Least offers
  2. Ascending and descending order
  3. Mail Domain
  4. Count repeating words

Leave a Comment

Scroll to Top