Pratice Sheet Java - If Switch

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Practice Sheet – Java

Conditional (if-else, switch)


1. Write a program to input three sides of a triangle and check whether a triangle is possible or not. If possible,
display the triangle is an Equilateral, an Isosceles or a Scalene Triangle, otherwise display “Triangle is not
possible”.
√3
Equilateral Triangle = 𝑠2 where s = side of an equilateral triangle.
4
1
Isosceles Triangle = ∗ 𝑏 ∗ √4𝑎2 − 𝑏 2 where a & b are the length of the side of a triangle
4
𝑚+𝑛+𝑝
Scalene Triangle = √𝑠 ∗ (𝑠 − 𝑚) ∗ (𝑠 − 𝑛) ∗ (𝑠 − 𝑝) , s = where m, n and p are three sides of a triangle.
2

2. Find the distance between two points (20,20) and (40,50).


3.
Estimate the time needed for a stone to fall from a height of 3000 meter. Assume g=9.8meter/s2
4. A multiplex theatre offers various categories of ticket as shown below. The user selects a category first and then
gives the number of tickets he wants to buy and then generate the payable amount.
Category Premium Gold Business class
Price 150 200 300
Write a program to complete the purchasing of cinema hall ticket to enjoy the movie.

5. Find if a given point lies in a given circle or not?

6. WAP to input three different single digit numbers between 1 and 9 (both inclusive). Display the greatest and
smallest three-digit combinational number.
e.g. Input: 2 7 4 output: Greatest number: 742 Smallest number: 247

7. The Electricity Board charges from their consumers according to the units consumed per month. The amount to
be paid as per the given tariff:
Units consumed Charges
Up to 100 units Rs. 5.50/unit
For the next 200 units Rs. 6.50/unit
For the next 300 units Rs. 7.50/unit
More than 600 units Rs. 8.50/unit
Write a program to input consumer’s Name, consumer Number and the units consumed. The program displays
the following information at the time receiving the money as:
Money Receipts
Consumer’s Name:
Consumer’s Number:
Units consumed:
Amount to be Paid:

8. A cloth showroom has announced the following festival discounts and the assured gifts on the purchase of items,
based on the total cost of the item purchased:
Total Cost Discount Assured Gift
Less than or up to Rs. 2000 5% Wall clock
Rs. 2001 to Rs. 5000 10% School Bag
Rs. 5001 to Rs. 10,000 15% Electric Iron
More than Rs. 10,000 20% Wrist Watch
Write a program to input the total cost of the item purchased, discount, amount to be paid after availing discount
and the assured gift.

PREPARED BY: AJAY KUMAR, ASSISTANT PROFESSOR, CSE DEPT. DIT UNIVERSITY DEHRADUN, INDIA 1
9. The standard form of quadratic equation is given by : ax2 + bx + c = 0, where Discriminant d = b2 – 4ac, that
determines the nature of the roots of the equation as:
Condition Nature
If d >= 0 Roots are real
If d < 0 Roots are imaginary

Write a program to determine the nature and the roots of a quadratic equation, taking a, b, c as input. If d = b 2 –
4ac is greater than or equal to zero, the display ‘Roots are real’, otherwise display ‘Roots are imaginary’. The
roots are determined by the formula as:

−𝑏+ √𝑏2 −4𝑎𝑐 −𝑏 − √𝑏2 −4𝑎𝑐


R1 = R2 =
2𝑎 2𝑎
10. Given below is a hypothetical table showing rate of income tax for male citizens below the age of 65 years:
Taxable income (TI) in Rs. Income Tax in Rs.
Does not exceed Rs. 1,60,000 NIL
Greater than Rs. 1,60,000 and less than or equal to Rs. (TI – Rs. 1,60,000) x 10%
5,00,000
Greater than Rs. 5,00,000 and less than or equal to Rs. [(TI – Rs. 5,00,000) x 20%] + Rs. 34,000
8,00,000
Greater than Rs. 8,00,000 [(TI – Rs. 8,00,000) x 30%] + Rs. 94,000

Write a program to input the age, gender (male or female) and taxable income of a person. If the age is more
than 65 years or the gender is female, display “Wrong category”. If the age is less than or equal to 65 years
and the gender is male, compute and display the income tax payable as per the table given above.

11. Write a choice-based program to input two angles. Calculate and display whether they are ‘Complementary
Angles’ or ‘Supplementary Angles’. [ hint: complementary angles => Sine, supplementary angle=>Cosine]
Angle m = (22.0/(7.0 * 180)) * a ; where m=sin60 , a= 60

12. Mr. Nathu Ram invests certain sum at 5% per annum compound interest for three years. Take sum as input from
the user, Write a program to calculate:
(a) The interest for the first year (b) the interest for the second year (c) the amount after three years

13. A shopkeeper offers 10% discount on the printed price of a Digital Camera. However, a customer has to pay
6% sales tax on the remaining amount. Write a program to calculate the amount to be paid by the consumer,
taking printed price as an input.

14. Mr. Rawat wishes to accumulate 3000 shares of a company. However, he already has some shares of that
company valuing Rs. 10 (nominal value) which yield 10% dividend per annum and received Rs. 2000 as
dividend at the end of the year. Write a program to calculate the number of shares he has and how many more
shares to be purchased to make his target.
𝐴𝑛𝑛𝑢𝑎𝑙 𝑑𝑖𝑣𝑖𝑑𝑒𝑛𝑑∗100
[Hint: No. of share =
𝑁𝑜𝑚𝑖𝑎𝑙 𝑣𝑎𝑙𝑢𝑒∗𝑑𝑖𝑣%
]
15. Write a program to input three numbers (positive or negative). If they are unequal then display the greatest
number otherwise, display they are equal. The program also displays whether the numbers entered by the user
are ‘ALL POSITIVE’, ‘ALL NEGATIVE’ or the combination of +ve and -ve numbers.

16. A special two-digit number is such that when the sum of its digits is added to the product of its digits, the result
is equal to the original two-digit number.
Example: Consider the number : 59 Sum of digits = 5 + 9 = 14 Product of digits = 5*9=45
Total of the sum of digits and product of digits = 14 + 45 = 59

PREPARED BY: AJAY KUMAR, ASSISTANT PROFESSOR, CSE DEPT. DIT UNIVERSITY DEHRADUN, INDIA 2
Write a program to accept a two-digit number. Add the sum of its digits to the product of its digits. If the value
is equal to the number input, output the message “Special 2-digit number” otherwise, output the message “Not
a special two-digit number”.

17. A library charges a fine for books returned late as given below:
No.of days (delayed) Charges for Fine
First 5 days 40 paise per day
6 to 10 days 65 paise per day
Above 10 days 80 paise per day
Design a program to calculate the fine assuming that a book is returned N days late.

18. SBI announces new rates for Term Deposit Schemes for their customers and Senior citizens as given below:
Term ROI (General) ROI (Sr. Citizen)
Up to 12 months 7.5% 8.0%
Up to 24 months 8.5% 9.0%
Up to 36 months 9.5% 10.0%
More than 36 months 10.0% 11.0%
The ‘senior citizen’ tag is applicable to the customers whose age is 60 years or above. Write a program to accept
the sum (p) in term deposit scheme, age of the customer and the term. The program displays the information in
the given format:
Amount Deposited Term Age Interest earned Amount Paid
XXX XXX XX XXX XXX

19. A hotel is giving a seasonal discount on the total amount to be paid by the person staying. The charges for
different rooms are given below along with the discount rate for given criteria:
Category Tariff No. of days stayed Discount
Semi Deluxe Room Rs. 2500/- per day Up to 3 days 10%
Deluxe Room Rs. 3500/- per day More than 3 days and less than 10 days 15%
Super Deluxe Room Rs. 5000/- per day More than 10 days 20%
Write a program to calculate the discount and total amount to be paid along with the name of the guest in a bill
format where name of the guest, category (‘S’ for semi-deluxe, ‘D’ for Deluxe, ‘SD’ for Super-Deluxe) and
number of days stayed in the hotel are entered.

20. A promoter cum Developer announces a special bonanza for early booking of the flats for their customers as
per the tariff given below:
Category Discount on the price Discount on Development Charge
Ground Floor 10% 8%
First Floor 2% 1%
Second Floor 5% 5%
Third Floor 7.5% 10%
Write a menu driven program to input price and the category: ‘0’ (zero) for ground floor, ‘1’ for first floor, ‘2’
for second floor and ‘3’ for third floor. Calculate and display the total discount, price of the flat after getting
discount.

PREPARED BY: AJAY KUMAR, ASSISTANT PROFESSOR, CSE DEPT. DIT UNIVERSITY DEHRADUN, INDIA 3
21. You want to buy an old car from ‘Value Plus’, where you can get a car in its depreciated price. The depreciation
value of a car is calculated on its showroom price and the number of years it has been used. The depreciated
value of a car is calculated as per the tariff given below:
No. of Years used Rate of Depreciation
1 10%
2 20%
3 30%
4 50%
Above than 4 years 60%
Write a menu driven program to input showroom price and the number of years used (‘1’ for one year, ‘2’ for
two years old and so on). Calculate the depreciated value. Display the original price of car, depreciated value
and the amount paid for the car.

22. AN electronic shop has announced the following seasonal discounts on the purchase of certain items.
Category Discount on Laptop Discount on Desktop PC
Up to Rs. 25,000 0.0% 5.0%
Rs. 25,001 – Rs. 57,000 5.0% 7.5%
Rs. 57,001 – Rs. 1,00,000 7.5% 10.0%
More than Rs. 1,00,000 10.0% 15.0%
Write a menu driven program based on above criteria, to input name, address, amount of purchase and the type
of purchase (‘L’ for Laptop, and ‘D’ for Desktop PC). Compute and print the net amount to be paid by a
customer with his name and address.
Hint: Discount = (discount rate / 100) * Amount of purchase
Net Amount = Amount of purchase – discount

23. A courier company charges for an ‘Ordinary’ mail and an ‘Express’ mail based on the weight of the parcel as
per the tariff given below:
Weight of parcel (in gm) Charges on Ordinary mail Charges on Express mail
Up to 100 gms. Rs. 30 Rs. 50
101 to 500 gms. Rs. 20/100 gms Rs. 40/100 gms.
501 and above Rs. 15/100 gms Rs. 30/100 gms
Write a program to accept the weight of a parcel and type of mail (‘O’ for ordinary and ‘E’ for express).
Calculate and print the charges under each category.

24. Input a number of digits. Count the digit in number and display the number of digits.
Example: Input 10, output: 2-digit
Input 200, output: 3-digit

PREPARED BY: AJAY KUMAR, ASSISTANT PROFESSOR, CSE DEPT. DIT UNIVERSITY DEHRADUN, INDIA 4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy