Page 368 - Computer science 868 Class 12
P. 368
Program 5 A class Capital has been defined to check whether a sentence has words beginning with a
capital letter or not.
Some of the members of the class are given below.
Class name : Capital
Data Members/Instance variables
sent : to store a sentence
freq : to store the frequency of words beginning with a
capital letter
Member Functions/Methods
Capital() : default constructor
void input() : to accept the sentence
boolean isCap(String w) : to check and return true if the word begins with a
capital letter, otherwise return false
void display() : to display the sentence along with the frequency of
the words beginning with a capital letter
Specify the class Capital giving the details of the constructor(), void input(), boolean
isCap(String) and void display(). Define the main() function to create an object and call the
functions accordingly to enable the task. [ISC 2018]
1 import java.util.*;
2 class Capital
3 {
4 String sent;
5 int freq;
6 Capital()
7 {
8 sent = new String();
9 freq = 0;
10 }
11
12 public void input()
13 {
14 Scanner sc = new Scanner(System.in);
15 System.out.print("Enter the sentence: ");
16 sent = sc.nextLine();
17 }
366366 Touchpad Computer Science-XII

