[go: up one dir, main page]

0% found this document useful (0 votes)
17 views6 pages

9 Pract

The document contains a series of programming tasks that require writing code for various mathematical and logical problems, including time conversion, employee salary calculations, triangle properties, discount calculations, number evaluations, and pattern generation. Each task specifies input requirements and expected outputs, covering a wide range of programming concepts such as loops, conditionals, and method overloading. The tasks are designed to enhance programming skills in Java.

Uploaded by

A A
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)
17 views6 pages

9 Pract

The document contains a series of programming tasks that require writing code for various mathematical and logical problems, including time conversion, employee salary calculations, triangle properties, discount calculations, number evaluations, and pattern generation. Each task specifies input requirements and expected outputs, covering a wide range of programming concepts such as loops, conditionals, and method overloading. The tasks are designed to enhance programming skills in Java.

Uploaded by

A A
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
You are on page 1/ 6

1.

Write a program to input the time in hours, minutes and seconds and
print it in seconds.
For Example:
INPUT: Enter time in hours:
1
Enter time in minutes:
12
Enter time in seconds:
6
OUTPUT:
Time in seconds:4326
2. Write a program to input the Basic Pay of an employee and find the gross
pay of the employee for the following allowances and deductions.
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
3. Write a program that outputs the results of the following evaluations
based on the number entered by the user.
i. Cube root of the number
ii. Absolute value of the number
iii. Square root of the number
iv. Random numbers between 0 and 1.
4. Write a program to input the three sides of a triangle and find the
perimeter and area of the triangle.
If a, b and c are the 3 sides then,
Perimeter=a+b+c
Area= s(s − a)(s − b)(s − c) where
s =( a + b + c)/2 .
5. Write a program to accept three sides of a triangle as parameter and
check whether it can form a triangle or not. If it forms a triangle, check
whether it is an acute angled, obtuse angled or right-angled triangle.
(Hint: To form a triangle, each side should be less the sum of the other
two sides..
a. To form an acute angled triangle the square of every side should
be less than the sum of the squares of the other two sides.
b. To form an obtuse angled triangle the square of any side should be
greater than the sum of the squares of the other two sides.
c. To form an right angled triangle the square of any side should be
equal to the sum of the squares of the other two sides.)

6. A cloth showroom has announced the following festival discounts on the


purchase of items based on the total cost of the items purchased:
Total Cost Discount (in Percentage)
Less than ₹ 2000 5%
₹ 2001 to ₹ 5000 25%
₹ 5001 to ₹ 10000 35%
Above ₹ 10000 50%
Write a program to input the total cost and compute and display the amount to
be paid by the
customer after availing the discount.

7. 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
read 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

8. Write a program to find the sum of series, taking the value of ‘a’ and ‘n’ from
the user.
9. Write a program to input a number and check whether it is a Smith number
or not. Smith number is such a number, the sum of whose digits equals the
sum of the digits of its prime factors.
Smith number is a composite number in which the sum of its digits is
equal to the
sum of the digits of all its prime factors.
For Example 378 is a Smith Number as the sum of the digits of 378 are :
3+7+8 = 18. The prime
factors of 378 are: 2, 3, 3, 3, 7 ( sum = 2+3+3+3+7 = 18).
Similarly 22 is a Smith Number as the sum of the digits are : 2+2=4. The
prime factors of 22 are:
2 and 11 (Sum = 2+(1+1) = 4
Other Examples include 27, 58, 85, 94, 121, 166, 202, 265, etc.

10. Design a class to overload a function compute() as follows:


(i) void compute(int,char): to compute the square of the integer
argument if the given character argument is ‘s’ otherwise find its
cube.

(ii) void compute(double char): to compute volume of a cube if the


given character argument is ‘v’ otherwise find its diagonal.

(iii) void compute(int,int,char): to compute area of a rectangle if


the given character argument is ‘a’ otherwise finds its perimeter.
Volume of cube=side3 Area of rectangle=length*breadth
Diagonal of cube=a√3 Perimeter of rectangle=2*(length+breadth)
11. Write a program to accept a number and check and display whether
it is a Niven number or not.
(Niven number is that number which is divisible by its sum of
digits).
Example:
Consider the number 126.
Sum of its digits is 1 + 2 + 6 = 9 and 126 is divisible by 9.
12. A library charges a fine for books returned late. Following are the
fines:
Number of days Amount
First five days : 40 paise per day.
Six to Ten days : 65 paise per day.
Above ten days : 80 paise per day.

Design a program to calculate the fine assuming that a book is returned


N days late.

13. To foster a sense of water conservation, the water department has an


annual water conservation tax policy. The tax are based on the water
consumption of the consumer. The tax rates are as follows:

Water Consumed (in Gallons) Tax Rate in ₹ /100 gallons

Upto 45 No Tax
More than 45 but 75 or less 475.00
More than 75 but 125 or less 750.00
More than 125 but 200 or less 1225.00
More than 200 but 350 or less 1650.00
More than 350 2000.00

Write a program to input the water consumed annually in gallons and output
the tax payable.

14. Write a program to find the sum of 1st 10 numbers of Fibonacci series i.e.
1,1,2,3,5,8,13….
Fibonacci series is such a series which starts from 1 and 1, and subsequent
numbers are the sum of the previous two numbers.

15.Write a program to input an integer and remove all the even digits from it.
For Example,
INPUT: Enter an integer: 1234
OUPUT: 13
16. In an entrance examination, students have answered English, Maths and
Science papers. Write a program to calculate and display average marks
obtained by all the students. Take the number of students appeared and marks
obtained in all three subjects by every student along with the name as inputs.

17. Write programs to find the sum of the given series:


(a) 1 + (1/2!) + (1/3!) + (1/4!) + .......... + (1/n!)

(b) 1 + (1+2) + (1+2+3) + .......... + (1+2+3+ ...... + n)

18. Write the programs in Java to display the following patterns:


(a)

1
21
321
4321
54321

(b)

12345
1234
123
12
1

19. Write a class with the name Area using method overloading that computes
the area of a parallelogram, a rhombus and a trapezium.
Formula:

Area of a parallelogram (pg) = base * ht

Area of a rhombus (rh) = (1/2) * d1 * d2


(where, d1 and d2 are the diagonals)
Area of a trapezium (tr) = (1/2) * ( a + b) * h
(where a and b are the parallel sides, h is the perpendicular distance between
the parallel sides)

20. Design a class overloading a method calculate() as follows:


1. 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 whether the last digit of the
integer argument is 7 or not.
2. 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, it displays the smaller of integer arguments.

You might also like