Page 473 - Cs_withBlue_J_C11_Flipbook
P. 473
Write a second class Search in package Green to import class Sort of package ComPack and use the method bubble() to check if
any number is present in the array by using method binaryS(). The class description is given below.
Package : Green
Class name : Search
Data Members
int arr[], size : Stores number and its binary equivalent
Member Methods
void accept() : Accepts size and then enters given number of elements in array
arr[]
void binaryS(int v) : Checks if number ‘v’ is present in the array or not by using
method bubble() of class Sort in package ComPack. Use binary
search technique
Define the above classes and also write the main method to execute the same.
4. Write a program to create a package Compack containing class Prime having the following specifications.
Package : ComPack
Class name Prime
boolean isprime(int x) : Returns true if x is prime, false otherwise
Write a second class PrimeDigit in package Green to import class Prime of package ComPack and use the method isprime() to
print the prime digits of the number. Prime numbers are those numbers that are divisible by 1 and themselves, e.g., 2,3,5,7, etc.
Example, If the number is 98254, then 2 and 5 will be printed as prime digits.
The class description is given below.
Package : Green
Class name : PrimeDigit
Data Members
int num : Stores number
Member Methods
void accept() : Accepts a positive number
void print() : Uses method isprime() of class Prime of package ComPrac and
prints the prime digits of number ‘num’.
Define the above classes and also write the main method to execute the same.
5. Write a program to create a package ComPack containing class ToBase having the following specifications.
Package : ComPack
Class name : ToBase
int change(String num, int base) : Converts a number of given base as specified in parameter to
decimal. The given bases can be 2, 8 and 16
Write a second class ChangeNum in package Green to import class ToBase of package ComPack and use the method change() to
print the decimal equivalent of the number.
The class description is given below:
Package : Green
Class name : ChangeNum
Data Members
String num, int base : Stores number and its base (2, 8 or 16)
Member Methods
void accept() : Accepts number and its base
void print() : Uses method change() in class ToBase of package ComPrac and
prints the decimal equivalent of number ‘num’.
Define the above classes and also write the main method to execute the same.
471
Packages 471

