P2Cart Logo
Data members/Instant variables: name, empno, basic, da, hra, pf, gross, net

This Java program defines an Employee class with methods to compute gross and net salary based on basic pay. It uses a parameterized constructor for initialization and displays the results in a formatted way.

Read more
   Define a class Employee described as below:
Data members/Instant variables:
      name, empno, basic, da, hra, pf, gross, net
Member methods:
i)        A parameterized constructor to initialize the data members
ii)      To accept the details of an employee
iii)    To compute the gross and net salary as:
         da = 30% of basic
        hra = 15% of basic
         pf = 12% of basic
      gross = basic + da + hra
        net = gross - pf
iv)    To display the name, empno, gross salary, net salary.
Write a main method to create an object of a class and call above member methods.

Read Answer
Data members/instant variables: max, min, f1, f2;

This Java program defines a Temperature class to convert maximum and minimum temperatures from Celsius to Fahrenheit using a parameterized constructor, a computation method, and a display method. The main method demonstrates the functionality with example input.

Read more
Define a class Temperature described as below:
Data members/instant variables:
max, min, f1, f2;
   Member methods:
    i)      A parameterized constructor to initialize the data members
ii)      To accept the maximum (max) and minimum (min) temperature of a day in Celsius
iii)    To compute the maximum and minimum temperatures to Fahrenheit as:
                  f = (9c/5) + 32
iv)    To display the maximum and minimum temperatures in Fahrenheit.
Write a main method to create an object of a class and call the above member methods.

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

This Java program converts each word in a string to Pig Latin form using a class Latin with methods for input and processing. It handles vowels, consonants, and words without vowels appropriately.

Read more
Write a program a class with the following specifications:
Class name: latin
Data member:
String name – to contain a name
Member functions:
void day 10: default constructor to initialize the string.
void input(String name): to accept a name, convert and print each word input piglatin form.

Read Answer
Write a class program by using a class with the following specifications: Class name: prime

This Java program determines whether a number is prime using a class Prime with a constructor, an input method, and a method to check and display the result.

Read more
Write a class program by using a class with the following specifications:
Class name: prime
Data members/Instant variables:
int n
Member functions:
prime( ): constructor to initialize m
void input(int x): to assign n with z
void display( ): to check and print whether number n is prime or not.

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

This Java program calculates the factorial of a number using a class Factorial with methods to input a number, calculate the factorial, and display the result.

Read more
Write a class program with the following specifications:
Class name: factorial
Data members:    
int a
Member functions:
Factorial( ): default constructor to initialize the data member.
void input(int m): to assign a with m.
void display( ): to print the factorial of the number.

Read Answer
Define a class called ‘Mobike’ with the following specifications:

This Java program calculates rental charges for a Mobike based on the number of days rented, following specific rate rules. It allows input of customer details and displays a formatted summary of charges.

Read more
Define a class called ‘Mobike’ with the following specifications:
Data members/Instant variable:
int bno: To store the bike number
int phno: To store the phone number of the customer
Srting name: To store the name of the customer
int days: To store the number of days the bike is taken out on rent
int charge: To calculate and store the rental charge
Member methods:
void input( ): To input and store the details of the customer
void compute( ): To compute the rental charge
The rent for a mobike is charged on the following basis:
For first five days: Rs. 500 per day
For next five days: Rs. 400 per day
Rent of the days: Rs. 200 per day
void display( ): To display the details in the following format:
                          Bike No.       Phone No.       Name         No. of days        Charge
                           xxxxx            xxxxxx         xxxxxx          xxxxxx            xxxxxx

Read Answer
Hero Honda has increased the cost of its vehicles as per the type of the engine using the following criteria:

This Java program calculates the new cost of a Honda vehicle based on its engine type (2-stroke or 4-stroke) using specified increment rates. It includes methods for input, calculation, and display of the results.

Read more
Hero Honda has increased the cost of its vehicles as per the type of the engine using the following criteria:

Type of Engine

Rate of Increment

2 stroke

10% of the cost

4 stroke

12% of the cost

 Write a program to use a class to find the new cost as per the given specifications:
Class name: Honda
Data members/Instant variables:
int type: To accept type of engine 2 stroke or 4 stroke.
int cost: To accept previous cost.
Member methods:
void gettype( ): To accept the type of engine.
void find( ): To find the new cost as per the criteria given above.
void printcost( ): To print the type and new cost of the vehicle.

Read Answer
Trust Bank charges interest for the vehicle loan as given below:

This Java program calculates the interest and total amount payable for a vehicle loan based on the duration using specified interest rates. It includes methods to input data, calculate values, and display results.

Read more
Trust Bank charges interest for the vehicle loan as given below:

Number of years

Rate of interest

Up to 5 years

15%

More than 5 and up to 10 years

12%

Above 10 years

10%

 Write a program to model a class with the specifications as given on the next page:

Class name: Loan
Data members/Instant variables:
int time: Time for which loan is sanctioned.
double principal: Amount sanctioned.
            double rate: Rate of interest.
            double interest: To store the interest.
            double amt: Amount to pay after given time.
 Interest = (Principal*Rate*Time)/100
Amount = Principal + Interest
Member methods:
void getdata( ): To accept principal and time.
void calculate( ): To find interest and amount.
void display( ): To display interest and amount.

Read Answer
A bookseller maintains record of the books belonging to the various publishers. He uses a class with the specifications given below:

This Java program manages a bookseller's stock. It verifies book availability by matching the title, author, and publisher and processes purchase requests based on stock availability.

Read more
A bookseller maintains record of the books belonging to the various publishers. He uses a class with the specifications given below:
Class name: Stock
Data members/Instant variables:
String title: Contains title of the book.
String author: Contains author name.
String pub: Contains publisher’s name.
int noc: Number of copies.
Member Methods:
void getdata( ): To accept title, author, pub, number of copies.
void purchase (int t, String p, int n): To check the existence of the book in the stock by
                                                           comparing total, author and publisher. Also checkn>noc.
                                                           If yes, maintain the balance as noc-n, otherwise display book not available or stock in under flowing.

 Write a program to perform the task given above.
Read Answer
Data members: String name: to store the name of the book

This Java program calculates the fine for a book based on how many days it is overdue, using a defined rate schedule. The fine is calculated based on the first 7, 8-15, 16-30, and more than 30 days of overdue periods.

Read more
Define a class Library having the following description:
Data members:         
String name: to store the name of the book
            int price: to store the printed price of the book
            int day: to enter the number of days for which the fine is to be paid
            double fine: to store the fine to be paid
Member functions:
void input( ): Store the name of the book, printed price of the book
void cal( ): Calculate the fine to be paid
void display( ): Displays the name of the book, fine to be paid
Write a program to compute the fine according to the given conditions and display the fine to be paid

Days

Fine

First seven days

25 paise per day

Eight to fifteen days

40 paise per day

Sixteen to thirty days

60 paise per day

More than thirty days

80 paise per day

Read Answer
Data members: int p: to enter the principal (sum)

This Java program calculates the simple interest and total amount to be paid based on the principal, rate of interest, and time provided by the user. It displays the results with interest rates adjusted based on the time period.

Read more
Define a class Interest having the following description:
Data members:
int p: to enter the principal (sum)
            int r: to enter the rate
            int t: to enter the time
            double interest: to store the interest to be paid
            double amt: to store the amount to be paid
Member functions:
void input( ): Store the principal, rate, time
void cal( ): Calculate the interest and amount to be paid
void display( ): Display the principal, interest and amount to be paid
Write a program to compute the interest according to the given conditions and display the output.

Time

Rate of Interest

For 1 year

6.5%

For 2 years

7.5%

For 3 years

8.5%

For 4 years or more

9.5%

(Note: Time to be taken only in whole year)
Read Answer
Data members: int prv, pre: to store the previous and present meter reading

This Java program calculates the telephone bill for a customer based on the number of calls made, applying specific rates, and adds a fixed monthly rent of Rs. 180 for the service.

Read more
Define a class Telephone having the following description:
Data members:         
int prv, pre: to store the previous and present meter reading
int call: to store the calls made (i.e. pre - prv)
String name: to store the name of the consumer
double amt: to store the amount
double total: to store the total amount to be paid
Member functions:
void input( ): Store the previous reading, present reading, name of the consumer
void cal( ): Calculate the amount and total amount to be paid
void display( ): Displays the name of the consumer, calls made, amount, total amount to be paid
Write a program to compute the monthly bill to be paid according to the given conditions and display the output as per the given format.

Calls made

Rate

Up to 100 calls

No charge

For the next 100 calls

90 paise per calls

For the next 200 calls

80 paise per calls

More than 400 calls

70 paise per calls

However, every consumer has to pay Rs. 180 per month as monthly rent for availing the service.
Output:           Name of customer            Calls made           Amount to be paid
                            ……………                …………….            ……………. 
                           ……………                …………….            ……………. 
                           ……………                …………….            ……………. 

Read Answer
Data members: int cost: to store the price of the article

This Java program calculates the discount on an article based on its cost and displays the name of the customer, the discount, and the final amount to be paid after applying the discount.

Read more
Define a class Discount having the following description:
Data members:
int cost: to store the price of the article
String name: to store name
double dc: to store the discount
double amt: to store the amount to be paid
Member functions:
void input( ): Store the cost of the article, name of the customer
void cal( ): Calculate the discount and amount to be paid
void display( ): Displays the name of the customer, cost, discount, amount to be paid
Write a program to compute the discount according to the given conditions and display the output as per given format.

List Price

Rate of Discount

Up to Rs. 5,000

No discount

From Rs. 5,001 to Rs. 10,000

10% on the list price

From Rs. 10,000 to Rs. 15,000

15% on the list price

Above Rs. 15,000

20% on the list price

Output:           Name of the customer             Discount            Amount to be paid
                             ……………                       ………….               ………….
                             ……………                       ………….               ………….
                             ……………                       ………….               ………….

Read Answer
Data members/(Instant variables): int pan : to store personal account number

This Java program defines an Employee class that accepts the employee's PAN number, name, and annual taxable income. It then calculates the income tax based on predefined income tax slabs and displays the employee’s details along with the calculated tax.

Read more
Define a class employee having the following description:
Data members/(Instant variables):
int pan : to store personal account number
String name: to store name
double taxincome: to store annual taxable income
double tax: to store tax that is calculated

Total Annual Taxable Income

Tax Rate

Up to Rs. 1,00,000

No tax

From Rs. 1,00,001 to Rs. 1,50,000

10% of the income exceeding Rs. 1,00,000

From Rs. 1,50,001 to Rs. 2,50,000

Rs. 5000+20% of the income exceeding Rs. 1,50,000

Above Rs. 2,50,000

Rs. 25000+30% of the income exceeding Rs. 2,50,000

 
Output:           Pan Number           Name          Tax-Income         Tax
                          …………            ………..        ………..            ………..     
                          …………            ………..        ………..            ………..     
                         …………            ………..        ………..            ………..     

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

This Java program defines a class Triplet that accepts three numbers, checks if they satisfy the Pythagorean theorem (i.e., whether they form a Pythagorean triplet), and displays the appropriate message.

Read more
Write a program using a class with the following specifications:
Class name: triplet
Data members:
 int a, b, c
Member functions:
void getdata( ): to accept three numbers.
void findprint( ): to check and print whether the numbers are Pythagorean Triplets or not.

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

This Java program defines a class Vowel to accept a string from the user, count the number of vowels in it, and display the total number of vowels found.

Read more
Write a program using a class with the following specifications:
Class name: vowel
Data members:
string s; int c(to count vowels)
Member functions:
void getstr( ): to accept string.
void getvowel( ): to count the number of vowels.
void display( ): to print the number of vowels.

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

This Java program defines a class CaseConvert to accept a string from the user and convert all uppercase letters to lowercase and vice versa, then display the converted string.

Read more
Write a program using a class with the following specifications:
Class name: caseconvert
Data members:
String str
Member functions:
void getstr( ): to accept a string.
void convert( ): to obtain a string after converting upper case to lower and vice-versa.
void display( ): to print the converted string.

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

This Java program defines a class StringMainp that accepts a string and reverses each word in the string. The reversed string is then printed out.

Read more
Write a program in Java by using a class with the following specifications:
Class name: stringmainp
Data members:
String s, rev
Member functions:
void getstr( ): to accept a string.
void search( ): to reverse and print each word.

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

This Java program defines a Son class that accepts 10 integers, sorts them using selection sort, and allows the user to search for a number in the sorted array using binary search.

Read more
Write a program in Java using a class with the following specifications:
Class name: son
Data members/instant variables:
integer array for 10 numbers.
Member functions:
void arrange( ): to display the list of sorted numbers using selection sort.
void search( ): to search a given number in the sorted array by using Binary Search technique.

Read Answer
Write a class program to accept two numbers as instant variables. Use the following functions for the given purposes:

This Java program defines a Calculate class that calculates the sum and difference of two user-inputted numbers. The program includes methods for inputting data, performing calculations, and displaying the results.

Read more
Write a class program to accept two numbers as instant variables. Use the following functions for the given purposes:
Class name: Calculate
void inputdata( ): to input both the values
void calculate( ): to find sum and difference
void outputdata( ): to print sum and difference of both the numbers.

Use a main class to call the functions.
Read Answer