P2Cart Logo
A bank maintains two types of operations Simple and Interest. Use Class Simple with the following specifications:

This Java program models a bank system where it calculates simple interest and the total amount after applying interest. The program supports operations like deposit and withdrawal, and uses inheritance to extend the functionality of the Simple class into the Interest class.

Read more
A bank maintains two types of operations Simple and Interest. Use Class Simple with the following specifications:
Class name: Simple
Data members:
int acno, float balance
Member functions:
Simple(int a, int b): to initialize acno = a, balance = b
void withdraw( ): to maintain the balance with withdrawl (balance - w)
void deposit(int d): to maintain the balance with the deposit (balance + d)
Use Class Interest which inherits with Simple with the following specifications:
Data members:
int r, t; float si, amt;
Member methods:
interest(int x, int y): to initialize r=x, t=y, amt=0
void calculate( ): Find simple interest and amount
                             si = (balance*r*t)/100
                              a = a + si;
void display( ): to print account number, balance, interest and amount.

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

This Java program accepts a 3x3 matrix, calculates the sum of each row and each column, and displays the results. The program uses methods in a Matrix class to handle the calculations and display the output.

Read more
Write a class program with the following specifications:
Class name: matrix
Data members:
int array m[][] with 3 rows and 3 columns
Member functions;
void getdata( ): to accept the numbers in the array
void rowsum( ): to find and print the sum of the numbers of each row.
void colsum( ): to find and print the sum of numbers of each column.

Use another class to call the functions.
Read Answer
Write a program by using a class with the following specifications: Class name: salary Data members:

This Java program calculates and displays the dearness allowance (DA), house rent allowance (HRA), and gross salary based on the inputted basic pay. The allowances are calculated as percentages of the basic pay.

Read more
Write a program by using a class with the following specifications:
Class name: salary
Data members:
private int basic
Member functions:
void input( ): to input basic pay
void display( ): to find and print the following-
                        da = 30% of basic, hra = 10% of basic, gross = basic + da + hra

Use main class to operate the functions.
Read Answer
Write a program by using a class with the following specifications: Class name: factorial

This Java program uses a class Factorial to input a number and compute its factorial. The program handles both positive and negative inputs, displaying the factorial or a message if the input is invalid.

Read more
Write a program by using a class with the following specifications:
Class name: factorial
Data members:
private int n
Member functions:
void input( ): to input a number
void fact( ): to find and print factorial of the number.

Use main class to operate the functions.
Read Answer
Use main class to operate the functions.

This Java program uses a class Prime to input a number and check if it is a prime number. The program checks divisibility to determine if the number is prime and displays the result.

Read more
Write a program by using a class with the following specifications:
Class name: prime
Data members:
private int n
Member functions:
void input( ): to input a number
void prime( ): to check and display the number is prime or not

Use main class to operate the functions. 
Read Answer
Write a class with the following specifications: Class name: employee

This Java program calculates an employee's salary based on basic pay, DA (50%), HRA (10%), Provident Fund (8.33%), and the final net salary. It uses inheritance to extend the Employee class and calculate the necessary salary components in the Salary class. The payslip is then displayed showing all details.

Read more
Write a class with the following specifications:
Class name: employee
Data members:
String name; float basic;
Member functions:
void getdata( ): to accept name and basic pay
Class salary extends employee
Data members:
float da, hra, gr oss, net
Member functions:
void calculate( ): to find the followings:
                       da = 50% of basic
                      hra = 10% of basic
                   gross = basic + da + hra
                        pf = 8.33% of (basic + da)
                       net = gross - pf
void display( ): to display the payslip

Read Answer
A company pays commission to its salesman on the sale value according to the following rates:

This Java program calculates the commission for a salesman based on the sale value. The commission rates are 5%, 10%, and 15% for different sale ranges. The program takes a sale value, calculates the corresponding commission, and displays the result.

Read more
A company pays commission to its salesman on the sale value according to the following rates:

Sale

Commission

Up to Rs. 1000

5% on sale

Rs. 1001 to Rs. 2000

10% on sale

Rs. 2001 and above

15% on sale

 Model a class program with the following specifications:
Class name: salecom
Data members:
salecom(double s, double c): constructor to initialize sale and com with s and c respectively.
void commission( ): to find the commission
void display( ): to display the commission

Read Answer
Vidyapatib river bridge has a tollbooth. Some cars passing through the bridge stop to play a toll of Rs. 5 are termed as good cars but some run through and do not pay any toll are termed as bad cars.

This Java program simulates a tollbooth system for a bridge, where good cars pay a toll of Rs. 5, and bad cars pass without paying. The program keeps track of the number of cars and the total amount collected from good cars.

Read more
Vidyapatib river bridge has a tollbooth. Some cars passing through the bridge stop to play a toll of Rs. 5 are termed as good cars but some run through and do not pay any toll are termed as bad cars. Write a class program with the following specifications:
Class name: tollbooth
Data members:
 private static int ncars, amount
Member functions:
tollbooth( ): constructor to initialize ncars and amount with 0.
void goodcars( ): to increase ncars by 1 and amount by 0.
void badcars( ): to increase only the ncars by 1
void display( ): to print the number of cars passed through the bridge within a defined period and amount collected.

Read Answer
Write a program in Java with the following specifications: Class name: array

This Java program defines a class Array to handle two integer arrays and performs operations like summing corresponding elements and finding the maximum of corresponding elements in the arrays.

Read more
Write a program in Java with the following specifications:
Class name: array
Data members:
Private int a[ ] and b[ ] to contain 10 integers.
Member functions:
void getlist( ): to accept the numbers in both the arrays
int sum(int x, int y): to find and return the sum of corresponding elements.
int max(int x, int y): to find and return maximum of the corresponding elements.
void display( ): to display the sum as well as maximum of the corresponding elements of both the arrays.

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

This Java program defines a Stringopr class that calculates the length of a given string and counts the number of words in it using string manipulation techniques.

Read more
Write a program in Java using a class with the following specifications:
Class name: stringopr
Data members:
private String s;
Member functions:
 Stringopr(String x): constructor to initialize string s with x.
int len(string p): to find the length of the string p
int numberofwords( ): to find and display the number of words in the string.

Read Answer
“A number is said to be palindrome if it appears to be the same after reversing the digits”. Write a program by using a class with the following specifications:

This Java program checks whether a number is a palindrome by reversing its digits and comparing it to the original number. It uses a class to handle the logic and user interaction.

Read more
“A number is said to be palindrome if it appears to be the same after reversing the digits”. Write a program by using a class with the following specifications:
Class: number
Data members:
private int num;
Member functions:
number(int x): constructor to initialize num with x;
int reverse(int n): used to return the reverse number
void palindrome( ): to check and print the number is palindrome or not.

Read Answer
Data members/Instant variables: private int result

This Java program implements a simple calculator with options for addition, subtraction, multiplication, division, displaying the result, and clearing the result. It uses a class to manage the calculations and interact with the user.

Read more
Write a class program to design a calculator with the following specifications:
Class name: calculator
Data members/Instant variables:
private int result
Member functions:
calculator( ): constructor to initialize result with zero.
void add(int a): to add a with the result
void sum(int a): to subtract a from the result
void mul( ): to multiply a into the result
void div(int a): to divide result by a
void display( ): to display result
void clear( ): to clear the result

Read Answer
Write a program in Java to find the roots of a quadratic equation ax2+bx+c=0 with the following specifications:

This Java program defines the Quad class to calculate and display the roots of a quadratic equation ax^2 + bx + c = 0 based on the coefficients entered by the user. The program computes the discriminant and determines whether the roots are real or not.

Read more
Write a program in Java to find the roots of a quadratic equation ax2+bx+c=0 with the following specifications:
Class name: Quad
Data members:
float a, b, c, d (a, b, c are the co-efficients & d is the discriminant), r1 and r2 are the roots of the equation.
Member methods:
quad(int x, int y, int z): to initialize a=x, b=y, c=z, d=0
void calculate( ): find d=b2-4ac
if d<0 then print “Roots not possible” otherwise find and print:
r1 = (-b + √d)/2a                     and                  r2 = (-b - √d)/2a

Read Answer
The population of a country in a particular year can be calculated by:

This Java program defines the Population class that calculates and displays the population of a country from 2001 to 2007 based on the initial population and annual growth rate.

Read more
The population of a country in a particular year can be calculated by:
p*(1 + r/100) at the end of year 2000, where p is the initial population and r is the growth rate.
Write a Class program in Java to find the population of the country at the end of each year from 2001 to 2007. The Class has the following specifications:
Class name: Population
Data members:
float p, r
Member methods:
Population(int a, int b): Constructor to initialize p and r with a and b respectively.
void print( ): to calculate and print the populations of each year from 2001 to 2007.  

Read Answer
Write a class program in Java with the following specifications: Class name: Stringop

This Java program defines the class Stringop, which encodes a string by shifting each character by two positions in the ASCII table and prints each word of the string on a separate line.

Read more
Write a class program in Java with the following specifications:
Class name: Stringop
Data members:
String str
Member functions:
Stringop( ): to initialize str with NULL.
void encode( ): to replace and print each character of the string with second next character in ASCII table.
Example: A with C, B with D and so on………….
void print( ): to print each word of the String in a separate line.

Read Answer
Write a class program in Java with the following specifications: Data name: Stat

This Java program defines a class Stat that computes the mean of 10 integers and calculates the deviation of each number from the mean. The class accepts input, computes the mean, and displays the deviations for each number.

Read more
Write a class program in Java with the following specifications:
Data name: Stat
Data members:
int a [ ]: to contain 10 integers
double m: to store the mean of 10 integers
double sd: to store deviation from the mean
Member functions:
stat( ): to initialize array a [int b[ ] ], m, sd
int mean( ): to find the mean of 10 numbers
void dev( ): to print deviation of each number from the mean

d = m – a[ ] 
Read Answer
Data members/Instant variables: String str(a word), i, p(to store the length of the word), char ch;

This Java program defines a class Arrange that arranges the characters of a given word in ascending order based on their ASCII values without using any built-in sorting techniques.

Read more
     Define a class Arrange described as below:
Data members/Instant variables:
              String str(a word), i, p(to store the length of the word), char ch;
Member methods:
i)        A parameterized constructor to initialize the data member
ii)      To accept the word
iii)    To arrange all the alphabets of word in ascending order of its ASCII value without using sorting technique
iv)    To display the arranged alphabets.
Write a main method to create an object of a class and call the above member methods.

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

This Java program defines a class Calculate to determine if a number is a Prime Palindrome. It includes methods to check for primality, calculate the reverse of a number, and display the results.

Read more
Write a class program with the following specifications:
Class name: Calculate
Instant variables:
int num, f, rev
Member methods:
Calculate(int n): to initialize num with n, f and rev with 0 (zero)
int prime( ): to return 1, if number is prime
int reverse( ): to return reverse of the number
void display( ): to check and print, whether the number is prime palindrome or not

Read Answer
Write a class program in Java with the following specifications: Class name: hcflcm

This Java program defines a class hcflcm that calculates the HCF and LCM of two numbers using a constructor for initialization and a method to perform calculations. The Euclidean algorithm is used for HCF computation.

Read more
Write a class program in Java with the following specifications:
Class name: hcflcm
Data members/Instant variables:
int, a, b
Member functions:
hcflcm(int x, int y): constructor to initialize a=x and b=y.
void calculate( ): to find and print hcf and lcm of both the numbers. 

Read Answer
Data members/Instant variables: name, age, m1, m2, (marks in three subjects), maximum, average

This Java program defines a Student class to calculate and display the maximum and average marks of a student based on input details, using a parameterized constructor and member methods.

Read more
   Define a class Student described as below:
Data members/Instant variables:
       name, age, m1, m2, (marks in three subjects), maximum, average
Member methods:
i)        A parameterized constructor to initialize the data members
ii)      To accept the details of a student
iii)    To compute the average and the maximum out of three marks
iv)    To display the name, age, and marks in three subjects, maximum and average.
Write a main method to create an object of a class and call the above member methods.

Read Answer