मराठी

Design a class Unique, which checks whether a word begins and ends with a vowel. Example: APPLE, ARORA etc. The details of the members of the class are given below: - Computer Science (Theory)

Advertisements
Advertisements

प्रश्न

Design a class Unique, which checks whether a word begins and ends with a vowel.

Example: APPLE, ARORA etc.

The details of the members of the class are given below:

Class name: Unique
Data members/instance variables:  
word: stores a word
len: to store the length of the word
Methods/Member functions:  
Unique( ) default constructor
void aceptword( ) to accept the word in UPPER CASE
boolean checkUnique( ) checks and returns 'true' if the word starts and ends with a vowel otherwise returns 'false'
void display( ) displays the word along with an appropriate message

Specify the class Unique, giving details of the constructor, void acceptword( ), boolean checkUnique( ) and void display( ). Define the main( ) function to create an object and call the Junctions accordingly to enable the task.

कोड लेखन
Advertisements

उत्तर

import java.util.*;
public class Unique
{
    String wrd;
    int len;
    public Unique()
    { 
    wrd=""; 
    len=0;
}
public void acceptword()
{
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter the word");
    wrd=sc.nextLine().toUpperCase();
    len=wrd.length(); 
}
public boolean checkUnique() 
{
    char ch1=wrd.charAt(0);
    char ch2=wrd.charAt(len-1);
    if (( ch1=='A' || ch1=='E' || ch1=='I' ||
    ch2=='O' || ch1=='U') && (ch2=='A' ||
    ch2=='E' || ch2=='I' || ch2=='O' || ch2=='U'))
    return true;
else
    return false;
}
public void display() 
{
    boolean r=checkUnique();
    if (r==true),
      System.out.println(wrd);
    else
      System.out.println("Criter not met"); 
}
public static void main(String [] args)
{
    Unique ob=new Unique();
    ob.acceptword();
    ob.display();
  }
}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2021-2022 (March) Official Board Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×