P2Cart Logo
Write a program in Java using a class with the following specifications- Class name: Sort

This Java program defines a class Sort that sorts an array of 10 integers in ascending order using the Bubble Sort technique. It includes methods to input data, sort the array, and display the sorted array.

Read more
Write a program in Java using a class with the following specifications-
Class name: Sort
Data members/instant variables:
 integer array for 10 numbers.
int i, j, temp, k
Member functions:
void inputdata( ): to accept 10 integers in the array
void array( ): to arrange the numbers in ascending order
void outputdata( ): to display the array elements in ascending order. 

Read Answer
Write a class program in Java to use an integer array of 10 numbers as instant variables.

This Java program defines a class Array_max to handle an array of 10 integers. It provides methods to input numbers, find the maximum value, and display the result.

Read more
Write a class program in Java to use an integer array of 10 numbers as instant variables.
Class name: Array_max
Data members:
 int I, max, m[]
Member functions:
void inputdata( ): to accept a lis of 10 integers.
void findmax( ): to find the maximum among the list of array elements.
void outputdata( ): to display maximum among the list of the elements.

Read Answer
A dice game is played between two players.

This Java program simulates a dice game between two players. Each player rolls a dice until their score reaches 20. The winner is the player with the minimum number of throws.

Read more
A dice game is played between two players. Each player throws a dice unless his scores add up to 20. A player is declared ‘Winner’ with the minimum number of throws. Define a class Game with the given specifications:
Data Members:
 Name, Player number.
Member methods:
To accept the details of players
To display details of the result.
To compute the result depending on the number of throws.

Write a main method to create an object of a class and call the above member method.
Read Answer
Encryptology is the process of encoding a string to another form in such a way that it should not be known to unauthorized person.

This Java program defines an Encode class to encrypt a string using character shifting based on a move value. It supports positive, negative, and zero moves, with proper wrapping of characters within the alphabet.

Read more
Encryptology is the process of encoding a string to another form in such a way that it should not be known to an unauthorized person. You are to encode a program in Java by using a class to encrypt a string in such a way that each character of the given string is replaced with a character at the mentioned gap (say, move). If the move is positive then the characters are replaced by other characters ahead of the given move. For a negative move, the characters are replaced by other characters backwards. In case the move is 0 then the same string is produced.
You must keep in mind that the characters are wrapped around while encryption i.e., Z is followed by A and A is followed by Z considering the moves to be negative and positive respectively.
e.g., ABZ can be encrypted as CDB if move = 2
ABZ can be encrypted as YZX if move = -2
ABZ can be encrypted as ABZ if move = 0
Class: encode
Data members/Instant variables:
String s, str
Member methods:
void input( ): To assign string st to s. Initialize String str = “”
void perform(int move): To perform encryption at a defined move
void display( ): To display the encrypted string.

Read Answer
Data members/instant variables: s: String type t1, t1: Integer counters

This Java program defines a Count class to count words starting with uppercase and lowercase characters in a string. It uses string splitting, character classification, and counter updates for processing.

Read more
Write a class program in Java with the following specifications:
Class name: count
Data members/instant variables:
s: String type
t1, t1: Integer counters
Member methods:
void input(String st): To assign string st s. Initialize t1, t2 with 0.
void countwords( ): To count the number of words starting with upper case and lower case characters.
void display( ): To print the counter values.

Read Answer
Write a program in Java by using a class with the following specifications: Class name: operate

This Java program defines an Operate class to analyze a string for letters, digits, white spaces, upper and lower case letters, and combined counts. It demonstrates string traversal and character classification.

Read more
Write a program in Java by using a class with the following specifications:
 Class name: operate
Data members/instant variables:
s: string type
Member methods:
void input(String st): To assign st to s.
void checkpoint( ): To check and print the following:
a)      Number of Letters
b)      Number of Digits
c)      Number of Letter or Digits
d)     Number of White spaces
e)      Number of Upper Case Letter
f)       Number of Lower case Latter

Read Answer
Sponge Iron Company announces an increment of their employee based on seniority basic as per the given conditions:

This Java program defines an Increment class to calculate an employee's updated basic pay based on age and company rules. It demonstrates input handling, conditional calculations, and formatted output.

Read more
Sponge Iron Company announces an increment of their employee based on seniority basic as per the given conditions:

Age

Increment

56 years and above

20% of basic

Above 45 and below 56 years

15% of basic

Up to 45

10% of basic

 Write a program to find new basic by using the following class specifications:
Class: Increment
Data members/Instant variables:
String name: Name of the employee
double basic: Basic pay of the employee
int age: Age of the employee
Member method:
void getdata(String n, double b, int a): To accept name, basic and age.
void calculate( ): To find increment and update basic.
void display( ): To display age and updated basic in the format given
below:
Name               Age                 Updated Basic
xxxxxxx          xxxxxxx               xxxxxxx
Read Answer
Define a class Security having the following description:

This Java program defines a Security class to calculate an employee's wages based on the number of hours worked and predefined conditions. It demonstrates input validation, wage computation, and formatted output.

Read more
Define a class Security having the following description:
Data members/ Instant variables:
String n: to store name
int h: to store number of hours for which wages to paid
double r: to store the rate of the wages
double w: to calculate the wages
Member functions:
get( ): Store the name, rate and number of hours
calwage( ): Calculate the wages of an employee
display( ): Output details of an employee
However, The security is not allowed to word for more than 70 hours a week.
Write a program to compute the wages according to the given conditions and display the output as per given format.

Number of hours

Rate

Up to 40 hrs.

Rs. r per hour

For next 20 hrs.

Rs. 1.5r per hour

For next 20 hrs.

Rs. 2r per hour

Output:           Name               Hours              Wages
                      ………..           …………         …………                                                                                                                                                                                                                              ………..           …………         …………

Read Answer
Define a class Salary described as below:

This Java program defines a Salary class to manage teacher details, including calculating the annual income tax based on a monthly salary exceeding Rs. 1,75,000. It demonstrates object-oriented programming concepts with input, computation, and display functionalities.

Read more
Define a class Salary described as below:
Data Members:
 Name, Address, Phone, Subject, Specialization, Monthly, Salary, Income Tax.
     Member methods:
a)      To accept the details of a teacher including the monthly salary
b)      To display the details of the teacher.
c)      To computer the annual Income Tax as 5% of the annual salary above Rs.   1,75,000/-.
Write a main method to create object of a class and cell the above member method. 

Read Answer
Write a class program with the following specifications: Class name: Rectangle

This Java program defines a Rectangle class with methods to input dimensions, calculate area, perimeter, and diagonal, and display the results. It demonstrates object-oriented programming concepts.

Read more
Write a class program with the following specifications:
Class name: Rectangle
Data members/Instant variables:
 int length, int breadth
Member functions:
void inputdata( ): to accept length and breadth of the rectangle
void calculate( ): to find area, perimeter and diagonal of the rectangle
void outputdata( ): to print the results
Read Answer
Design a class to overload a function manip ( ) as follows: a) Void compare (int, int) : to compare two integers values and print the greater of the two integers.....

This Java program demonstrates function overloading with the compare() method. The method is overloaded to compare two integers, two characters (based on ASCII values), and two strings (based on length). Depending on the input type, it prints the greater value or the longer string.

Read more
     Design a class to overload a function manip ( ) as follows:
a)      Void compare (int, int) : to compare two integers values and print the greater of the two integers.
b)      Void compare (char, char) : to compare the numeric value of two characters and print with the higher numeric value.  
c)      Void compare (String, String): to compare the length of the two strings and print the longer of the two.

Read Answer
Design a class to overload a function manip ( ) as follows: a) Void manip (String str, int p) with one String argument and one integer argument.

This Java program demonstrates function overloading with the manip() method to perform two tasks: (1) display characters at even or odd positions in a string based on user input, and (2) compute the square or cube root of an integer based on a given character argument.

Read more
     Design a class to overload a function manip ( ) as follows:
a)      Void manip (String str, int p) with one String argument and one integer argument. It displays the characters of even positions of String, if p is an even number otherwise, displays the characters of odd positions.
b)      Void manip (int a, char ch) with one integer argument and one character argument. It computes the square root of integer arguments if ch is 's' else cube root of the integers.

Read Answer
Write a menu-driven program using a method Number () to perform the following tasks:

This Java program allows the user to convert a decimal number to binary and a binary number to decimal using a menu-driven interface. The program provides options to convert a number based on user input, with error handling for invalid binary numbers.

Read more
Write a menu-driven program using a method Number () to perform the following tasks:
a)      Accept a number from the user and display in its Binary Equivalents
                   e.g.: Sample Input: (21)10, Sample Output: (10101)2
b)      Accept a binary number from the user and display in its Decimal Equivalents
            e.g.: Input: (11101)2,  Sample Output: (29)10

Read Answer
If the number is present, then display the message 'Number is present' otherwise, 'number is not present'.

This Java program takes 10 numbers as input, stores them in an array, and then searches for a specified number in the array. If the number is found, it displays "Number is present", otherwise "Number is not present".

Read more
Write a program to accept 10 numbers in a Single Dimensional Array. Pass the array to a function Search (int m[], int ns) to search the given number ns in the list of array elements. If the number is present, then display the message 'Number is present' otherwise, 'number is not present'.
Read Answer
Write a program using method name Glcm (int, int) to find the Lowest Common Multiples (LCM) of two numbers by GCD (Greatest Common Divisor) of the numbers.

This Java program calculates the Lowest Common Multiple (LCM) of two integers using the Greatest Common Divisor (GCD). The GCD is found using the continued division method, and the LCM is then calculated using the formula: LCM = (a * b) / GCD(a, b).

Read more
Write a program using method name Glcm (int, int) to find the Lowest Common Multiples (LCM) of two numbers by GCD (Greatest Common Divisor) of the numbers.
GCD of two integers is calculated by continued division method. Divide the larger number by the smaller, the remainder then divides the previous divisor. The process is repeated till the remainder is zero. The divisor then results in the GCD.

LCM = Product of two numbers/GCD

Write the main method to display the LCM of two numbers.
Read Answer
Design a class overloading a function calculate ( ) as follows: a) Void calculate (int m, char ch) with one integer argument and one character argument.

This Java program demonstrates function overloading by defining two calculate methods. The first method checks if an integer is divisible by 7 or if its last digit is 7, while the second method compares two integers and displays the greater or smaller based on a character argument.

Read more
     Design a class overloading a function calculate ( ) as follows:
a)      Void calculate (int m, char ch) with one integer argument and one character argument. It checks whether the integer argument is divisible by 7 or not, if ch is 's' otherwise, it checks the last digit of the integer argument contains 7 or not.
b)      Void calculate (int a, int b, char ch) with two integer arguments and one character argument. It displays the greater of integer arguments if ch is 'g' otherwise, displays the smaller of integer arguments.

Read Answer
Design a class over loading a function display ( ) as follows:

This Java program demonstrates function overloading by defining two display methods. One method displays uppercase or lowercase characters based on an integer parameter, and the other displays vowels or all alphabets based on a character parameter.

Read more
     Design a class overloading a function display ( ) as follows:
a)      Void display (String str, int p) with one String argument and one integer argument. It displays all the uppercase characters if 'p' is 1 (one) otherwise, displays all the lowercase characters.
b)      Void display (String str, char chr) with one String argument and one character argument. It displays all the vowels if chr is v otherwise, displays all the alphabets.

Read Answer
Write a program in Java to accept a String from the user. Pass the String to a function First (String str) which displays the first character of each word.

This Java program takes a string input from the user and displays the first character of each word in the string, printing each character on a new line.

Read more
Write a program in Java to accept a String from the user. Pass the String to a function First (String str) which displays the first character of each word.
Sample Input: Understanding Computer Applications
Sample Output: U
                             C
                             A

Read Answer
Write a program in Java to accept the name of an employee and the annual income.

This Java program calculates the income tax for an employee based on their annual income using specific tax slabs. It displays the employee's name and the computed income tax according to the given tariff.

Read more
Write a program in Java to accept the name of an employee and the annual income. Pass the name and the annual income to a function Tax (String name, int income) which displays the name of the employee and the income tax as per the given tariff:

Annual Income

Income Tax

Up to Rs. 50000

No tax

Rs. 50001 to Rs. 100000

10% of the income exceeding Rs. 50000

Rs. 100001 to Rs. 150000

Rs. 5000+ 20% of the amount exceeding Rs. 100000

Rs. 150001 and above

Rs. 15000 + 30% of the amount exceeding Rs. 150000

Read Answer
Pass the String to a function Change (String str) which displays the first character of each word after changing the case (lower to upper and vice-versa).

This Java program accepts a string from the user and displays the first character of each word after changing its case (lowercase to uppercase and vice versa). Each character is printed on a new line.

Read more
Write a program in Java to accept a String from the user. Pass the String to a function Change (String str) which displays the first character of each word after changing the case (lower to upper and vice-versa).
Sample Input : Delhi public school
Sample Output: d
                            P
                            S

Read Answer