Page 370 - Computer science 868 Class 12
P. 370

Sentence: I Am going to School
              Frequency of words beginning with capital letter: 3



                Program 6      Input a sentence from the user and count the number of times, the words “an” and “and” are
                               used in the sentence. Design a class Frequency using the description given below.

                               Class name              :   Frequency
                               Data Members/Variables
                               text                    :   to store the sentence
                               countand                :   to store the frequency of the word “and”

                               countan                 :   to store the frequency of the word “an”
                               len                     :   to store the length of the string
                               Member Functions/Methods

                               Frequency()             :   constructor to initialise the instance variables
                               void accept(String n)   :    to assign n to text, where the value of the parameter n should be
                                                          in lowercase
                               void checkandfreq()     :   to count the frequency of “and”

                               void checkanfreq()      :   to count the frequency of “an”
                               void display()          :    to display the number of “and”  and  “an”  with  appropriate
                                                          messages
                               Specify the class Frequency giving  details  of the constructor(),  void  accept(String),  void
                               checkandfreq(),  void  checkanfreq()  and  void  display().  Also, define the main()  function  to
                               create an object and call methods accordingly to enable the task.           [ISC 2011]


                 1       import java.util.*;

                 2       class frequency
                 3       {
                 4           String text;

                 5           int countand,countan,len;
                 6           frequency()

                 7           {
                 8               text = "";

                 9               countand = 0;
                10               countan = 0;

                11               len = 0;
                12           }

                13






                368368  Touchpad Computer Science-XII
   365   366   367   368   369   370   371   372   373   374   375