Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
15.7k views
in Computer by (79.3k points)

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 member/instance variables :
sent to store a sentence 
freq stores 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) checks and returns true if word begins with a capital letter, otherwise returns false
void display( ) displays 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.

1 Answer

+1 vote
by (76.4k points)
selected by
 
Best answer

import java. io. * ;

class Capital

{

String sent;

int freq;

Capital ( )

{

sent = " "; freq = 0;

}

void input ( )

{

BufferedReader br = new BufferedReader (new InputStreamReader (System. in)); 

system. out. println ("Enter one sentence"); 

sent = br. readLine ( );

String [ ] word = sent. split (" \\ s");

for (int i = 0; i < word. length; i ++)

{

if (isCap (word [i]) = = true)

freq ++;

}

}

boolean isCap (String w)

{

if (Character. isUpperCase (w. charAt (0)) = = true)

return true;

else return false;

}

void display ( )

}

System. out. println (sent);

System. out. println (" the frequency of the words beginning with a capital letter is "+ freq);

}

public static void main ( )

{

Capital Ob = new Capital ( );

Ob. input ( );

Ob. display ( );

}

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...