0% found this document useful (0 votes)
25 views9 pages

Programs

The document outlines a series of Java programming tasks, including calculating electricity bills, checking leap years, detecting character types, evaluating numbers, and generating patterns. It also includes class definitions for various applications such as movies, employees, currency conversion, and parking lot management. Each task is designed to reinforce programming concepts and practices in Java.

Uploaded by

cyancubest
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

Programs

The document outlines a series of Java programming tasks, including calculating electricity bills, checking leap years, detecting character types, evaluating numbers, and generating patterns. It also includes class definitions for various applications such as movies, employees, currency conversion, and parking lot management. Each task is designed to reinforce programming concepts and practices in Java.

Uploaded by

cyancubest
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1) An electricity board charges the bill depending on the number of units

consumed as follows:

Sales units Commission charge

First 100 units 40p per unit

Next 200 units 60p per unit

Above 300 units Re 1 per unit

Write a java program to print the net bill to paid by a consumer. The net bill
includes a rent of Rs 250/- . Charged from a consumer.

2) Write class leap to accept an year and check if it is a leap year or not.

3)WAP in java to input a character from the keyboard and detect whether it is an
alphabet or a digit. If it is an alphabet check whether it is lower case alphabet or
an uppercase. Print appropriate message.

4) Write a menu driven program that outputs the results of the following
evaluation based on the number entered by the user:

a) Absolute value of the number

b) Square root of the number

c) Random numbers between 0 and 1.


5)Write a program to input a number and print whether the number is a special
number or not.(A number is said to be a special number, if the sum of the
factorial of the digits of the number is same as the original number).Example: 145
is a special number, because 1! + 4! + 5! = 1 + 24 + 120 = 145.

6) Write a program to calculate and print the sum of odd numbers and sum of
even numbers for the first n natural numbers

The integer n is to be entered by the user

7) A tech number has even number of digits. If the number is split in two equal
halves, then the square of sum of these halves is equal to the number itself. Write
a program to generate and print all four digits tech numbers.

Example:Consider the number 3025Square of sum of the halves of 3025 = (30 +


25)2 = (55)2 = 3025 is a tech number.

8) Write a complete java program to print the ASCII codes of following characters:
?, Z, m, #.

Define a method named ASC() to perform the above started job.

9) Write a program using a method called area() to compute area of the following:

(a) Area of circle = (22/7) * r * r

(b) Area of square= side * side


(c) Area of rectangle = length * breadth

Display the menu to display the area as per the user's choice.

10) Define a class named movieMagic with the following description:

Data MembersPurpose

int year. - To store the year of release of a movieString title. - To store the title
of the moviefloat rating. - To store the popularity rating of the movie (minimum
rating=0.0 and maximum rating=5.0)

MemberMethods

PurposemovieMagic() - Default constructor to initialize numeric data members


to 0 and String data member to "".

void accept(). - To input and store year, title and ratingvoid

display(). - To display the title of the movie and a message based on the rating
as per the table given below

Ratings Table

RatingMessage to be displayed.

0.0 to 2.0. - Flop

2.1 to 3.4. - Semi-Hit

3.5 to 4.4. - Hit

4.5 to 5.0. - Super-Hit


Write a main method to create an object of the class and call the above member
methods.

11) Define a class employee with its data member basic. Find the gross pay of an
employee for the following allowances and deductions. Use meaningful variables.
Print name, basic pay, net pay and gross pay.

Dearness Allowance = 25% of Basic Pay. House Rent Allowance = 15% of Basic
Pay. Provident Fund = 8.33% of Basic Pay.

Net Pay = Basic Pay+ Dearness Allowance + House Rent Allowance.

Gross Pay = Net Pay - Provident Fund.

12)Write a java program to Define a Java class Employee with the following
members:

Data Members: code, name, basic, hra, da, PF

Default Constructor: initialises code, basic, hra, da and PF to zero

Parameterized Constructor: Initialises basic, computes hra, da and PF as per the


following criteria

hra = 10% of basic

da = 55% of basic

PF = Rs. 1000.

Main Method: computes and displays the net salary

NetSalary = basic + da + hra – PF

13)Write a menu driven program to accept a number from the user and check
whether it is a Prime number or an Automorphic number.
(a) Prime number: (A number is said to be prime, if it is only divisible by 1 and
itself)

Example: 3,5,7,11

(b) Automorphic number: (Automorphic number is the number which is contained


in the last digit(s) of its square.)

Example: 25 is an Automorphic number as its square is 625 and 25 is present as


the last two digits.

14)Write two separate programs to generate the following patterns using


iteration (loop) statements:

(a)

* #

* # *

* # * #

* # * # *
(b)

54321

5432

543

54

15) Write a program to input a number. Check and display whether it is a Niven
number or not. (A number is said to be Niven which is divisible by the sum of its
digits).

Example: Sample Input 126

Sum of its digits = 1 + 2 + 6 = 9 and 126 is divisible by 9.

16) write a program in Java to print the following pattern.

7 7 7 7 7.

76666

76555

76544

76543
17) Write a menu driven class to accept a number from the user and check
whether it is a Palindrome or a Perfect number.

(a) Palindrome number: (A number is a Palindrome which when read in reverse


order is same as in the right order)

Example: 11, 101, 151 etc.

(b) Perfect number: (A number is called Perfect if it is equal to the sum of its
factors other than the number itself.)

Example: 6 = 1 + 2 + 3

18)Define a class ConvertCurrency that contains the following members


methods:, DollarToRupee() - Accept dollors as parameter and returns the amount
in rupees.

EuroToRupee() - Accept Euro currency as parameter and returns the amount in


rupees.

main() - call the above methods and displays the result.

19)Define a class called ParkingLot with the following description:

Class name : ParkingLot

Data Members

int vno - To store the vehicle number


int hours - To store the number of hours the vehicle is parked in the parking lot

double bill - To store the bill amount

Member Methods

void input( ) - To input the vno and hours

void calculate( ) - To compute the parking charge at the rate ₹3 for the first hour
or the part thereof and ₹1.50 for each additional hour or part thereof.

void display() - To display the detail

Write a main method to create an object of the class and call the above methods.

20) Define a class named FruitJuice with the following description:

Data Members and Purpose

int product_code - stores the product code number

String flavour - stores the flavour of the juice (e.g., orange, apple, etc.)

String pack_type - stores the type of packaging (e.g., tera-pack, PET bottle, etc.)

int pack_size - stores package size (e.g., 200 mL, 400 mL, etc.)

int product_price - stores the price of the product

Member Methods

FruitJuice() - Default constructor to initialize integer data members to 0 and


string data members to " "

void input(). - To input and store the product code, flavour, pack type, pack size
and product price

void discount() - To reduce the product price by 10


void display() - To display the product code, flavour, pack type, pack size and
product price.

21) Write a program that accepts a string from the user and displays the count of
vowels and consonants from the string.

You might also like